当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.keys方法代码示例

本文整理汇总了Python中synnefo.lib.ordereddict.OrderedDict.keys方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.keys方法的具体用法?Python OrderedDict.keys怎么用?Python OrderedDict.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synnefo.lib.ordereddict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.keys方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a component name or ID.")

        identifier = args[0]
        if identifier.isdigit():
            try:
                component = Component.objects.get(id=int(identifier))
            except Component.DoesNotExist:
                raise CommandError('No component found with ID %s.' %
                                   identifier)
        else:
            try:
                component = Component.objects.get(name=identifier)
            except Component.DoesNotExist:
                raise CommandError('No component found named %s.' % identifier)

        kv = OrderedDict(
            [
                ('id', component.id),
                ('name', component.name),
                ('base url', component.base_url),
                ('ui url', component.url),
                ('token', component.auth_token),
                ('token created', component.auth_token_created),
                ('token expires', component.auth_token_expires),
            ])

        utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                           options["output_format"], vertical=True)

        services = component.service_set.all()

        service_data = []
        for service in services:
            service_data.append((service.id, service.name, service.type))

        if service_data:
            self.stdout.write('\n')
            labels = ('id', 'name', 'type')
            utils.pprint_table(self.stdout, service_data, labels,
                               options["output_format"],
                               title='Registered services')
开发者ID:antonis-m,项目名称:synnefo,代码行数:45,代码来源:component-show.py

示例2: handle

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please profile name")

        try:
            profile = Profile.objects.get(name=args[0])
        except Profile.DoesNotExist:
            raise CommandError("Profile does not exist")

        kv = OrderedDict(
            [
                ('id', profile.id),
                ('is active', str(profile.active)),
                ('name', profile.name),
                ('is exclusive', profile.is_exclusive),
                ('policies', profile.policies),
                ('groups', profile.groups.all()),
                ('users', profile.users.all())
            ])

        utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                           options["output_format"], vertical=True)
开发者ID:antonis-m,项目名称:synnefo,代码行数:24,代码来源:authpolicy-show.py

示例3: handle

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a service name or ID.")

        identifier = args[0]
        if identifier.isdigit():
            try:
                service = Service.objects.get(id=int(identifier))
            except Service.DoesNotExist:
                raise CommandError('No service found with ID %s.' % identifier)
        else:
            try:
                service = Service.objects.get(name=identifier)
            except Service.DoesNotExist:
                raise CommandError('No service found named %s.' % identifier)

        kv = OrderedDict(
            [
                ('id', service.id),
                ('name', service.name),
                ('component', service.component),
                ('type', service.type),
            ])

        utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                           options["output_format"], vertical=True)

        self.stdout.write('\n')
        endpoint_data = EndpointData.objects.filter(endpoint__service=service)
        data = []
        for ed in endpoint_data:
            data.append((ed.endpoint_id, ed.key, ed.value))

        labels = ('endpoint', 'key', 'value')
        utils.pprint_table(self.stdout, data, labels,
                           options["output_format"],
                           title='Endpoints')
开发者ID:antonis-m,项目名称:synnefo,代码行数:39,代码来源:service-show.py

示例4: AMQPPukaClient

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]

#.........这里部分代码省略.........
            callback = None

        promise = self.client.basic_publish(exchange=exchange,
                                            routing_key=routing_key,
                                            body=body, headers=headers,
                                            callback=callback)

        if self.confirms:
            self.unacked[promise] = (exchange, routing_key, body)

        return promise

    def handle_publisher_confirm(self, promise, result):
        """Handle publisher confirmation message.

        Callback function which handles publisher confirmation by removing
        the promise (and message) from 'unacked' messages.

        """
        msg = self.unacked.pop(promise, None)
        if msg is None:
            self.log.warning("Received publisher confirmation for"
                             " unknown promise '%s'", promise)

    @reconnect_decorator
    def flush_buffer(self):
        while self.client.needs_write():
            self.client.on_write()

    @reconnect_decorator
    def get_confirms(self):
        """Wait for all publisher confirmations."""
        while self.unacked:
            self.client.wait(self.unacked.keys())

    @reconnect_decorator
    def _resend_unacked_messages(self):
        """Resend unacked messages in case of a connection failure."""
        msgs = self.unacked.values()
        self.unacked.clear()
        for exchange, routing_key, body in msgs:
            self.log.debug('Resending message %s' % body)
            self.basic_publish(exchange, routing_key, body)

    @reconnect_decorator
    def _resend_unsend_messages(self):
        """Resend unsend messages in case of a connection failure."""
        for body in self.unsend.keys():
            (exchange, routing_key) = self.unsend[body]
            self.basic_publish(exchange, routing_key, body)
            self.unsend.pop(body)

    @reconnect_decorator
    def basic_consume(self, queue, callback, no_ack=False, prefetch_count=0):
        """Consume from a queue.

        @type queue: string or list of strings
        @param queue: the name or list of names from the queues to consume
        @type callback: function
        @param callback: the callback function to run when a message arrives

        """
        self.log.debug("Consume from queue '%s'", queue)
        # Store the queues and the callback
        self.consumers[queue] = callback
开发者ID:AthinaB,项目名称:synnefo,代码行数:69,代码来源:amqp_puka.py

示例5: handle

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a user ID or email")

        identifier = args[0]
        if identifier.isdigit():
            users = AstakosUser.objects.filter(id=int(identifier))
        else:
            try:
                uuid.UUID(identifier)
            except:
                users = AstakosUser.objects.filter(email__iexact=identifier)
            else:
                users = AstakosUser.objects.filter(uuid=identifier)
        if users.count() == 0:
            field = "id" if identifier.isdigit() else "email"
            msg = "Unknown user with %s '%s'" % (field, identifier)
            raise CommandError(msg)

        for user in users:
            kv = OrderedDict(
                [
                    ("id", user.id),
                    ("uuid", user.uuid),
                    ("status", user.status_display),
                    ("email", user.email),
                    ("first name", user.first_name),
                    ("last name", user.last_name),
                    ("admin", user.is_superuser),
                    ("last login", user.last_login),
                    ("date joined", user.date_joined),
                    ("last update", user.updated),
                    # ('token', user.auth_token),
                    ("token expiration", user.auth_token_expires),
                    ("providers", user.auth_providers_display),
                    ("groups", [elem.name for elem in user.groups.all()]),
                    ("permissions", [elem.codename for elem in user.user_permissions.all()]),
                    ("group permissions", user.get_group_permissions()),
                    ("email_verified", user.email_verified),
                    ("moderated", user.moderated),
                    ("rejected", user.is_rejected),
                    ("active", user.is_active),
                    ("username", user.username),
                    ("activation_sent_date", user.activation_sent),
                    ("last_login_details", user.last_login_info_display),
                ]
            )

            if get_latest_terms():
                has_signed_terms = user.signed_terms
                kv["has_signed_terms"] = has_signed_terms
                if has_signed_terms:
                    kv["date_signed_terms"] = user.date_signed_terms

            utils.pprint_table(self.stdout, [kv.values()], kv.keys(), options["output_format"], vertical=True)

            if options["list_quotas"] and user.is_accepted():
                unit_style = options["unit_style"]
                check_style(unit_style)

                quotas = get_user_quotas(user)
                if quotas:
                    self.stdout.write("\n")
                    print_data, labels = show_user_quotas(quotas, style=unit_style)
                    utils.pprint_table(self.stdout, print_data, labels, options["output_format"], title="User Quota")

            if options["list_projects"]:
                print_data, labels = ownerships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(
                        self.stdout, print_data, labels, options["output_format"], title="Owned Projects"
                    )

                print_data, labels = memberships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(
                        self.stdout, print_data, labels, options["output_format"], title="Project Memberships"
                    )
开发者ID:konsP,项目名称:synnefo,代码行数:82,代码来源:user-show.py

示例6: OrderedDict

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import keys [as 别名]
        'DISPLAY': ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
        'BASE': 1024,
    }
}

STYLE_TO_EXP = OrderedDict(
    [('b',  0),
     ('kb', 1),
     ('mb', 2),
     ('gb', 3),
     ('tb', 4),
     ('pb', 5),
     ]
)

STYLES = STYLE_TO_EXP.keys() + ['auto', 'none']


class StyleError(Exception):
    pass


def show_float(n):
    if n < 1:
        return "%.3f" % n
    if n < 10:
        return "%.2f" % n
    return "%.1f" % n


def get_exponent(style):
开发者ID:AthinaB,项目名称:synnefo,代码行数:33,代码来源:units.py


注:本文中的synnefo.lib.ordereddict.OrderedDict.keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。