• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.iteritems_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.compat.iteritems_函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems_函数的具体用法?Python iteritems_怎么用?Python iteritems_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __update

 def __update(self, opts, mp_opts):
     if not opts is None:
         for option_name, option_value in iteritems_(opts):
             if not option_value is None:
                 self.set_option(option_name, option_value)
     if not mp_opts is None:
         for attr_name, attr_mp_options in iteritems_(mp_opts):
             for mp_opt_name, mp_opt_value in iteritems_(attr_mp_options):
                 if not mp_opt_value is None:
                     self.set_attribute_option(attr_name,
                                             mp_opt_name, mp_opt_value)
开发者ID:helixyte,项目名称:everest,代码行数:11,代码来源:config.py


示例2: _set_request_extensions

def _set_request_extensions(event):
    request = event.request
    exts = request.registry.queryUtility(IRequestExtensions)
    for name, fn in iteritems_(exts.methods):
        method = fn.__get__(request, request.__class__)
        setattr(request, name, method)
    request._set_properties(exts.descriptors)
开发者ID:Javex,项目名称:pyramid,代码行数:7,代码来源:factories.py


示例3: add_representer

 def add_representer(self, content_type=None, representer_class=None,
                     options=None, _info=u''):
     if content_type is None and representer_class is None:
         raise ValueError('Either content type or representer class must '
                          'be provided.')
     if not content_type is None and not representer_class is None:
         raise ValueError('Either content type or representer class may '
                          'be provided, but not both.')
     if options is None:
         options = {}
     rpr_reg = self.get_registered_utility(IRepresenterRegistry)
     if not representer_class is None:
         rpr_reg.register_representer_class(representer_class)
         if issubclass(representer_class, MappingResourceRepresenter):
             mp_reg = rpr_reg.get_mapping_registry(
                                         representer_class.content_type)
         else: # pragma: no cover
             # FIXME: This is for representers that bypass the mapping
             #        machinery by using custom parsers/generators. Needs
             #        a test case.
             mp_reg = None
     else:
         mp_reg = rpr_reg.get_mapping_registry(content_type)
     if not mp_reg is None:
         for name, value in iteritems_(options):
             mp_reg.set_default_config_option(name, value)
开发者ID:helixyte,项目名称:everest,代码行数:26,代码来源:configuration.py


示例4: after

 def after(self):
     # Register resources eagerly so the various adapters and utilities are
     # available for other directives.
     discriminator = ('resource', self.interface)
     reg = get_current_registry()
     config = Configurator(reg, package=self.context.package)
     config.add_resource(self.interface, self.member, self.entity,
                         collection=self.collection,
                         collection_root_name=self.collection_root_name,
                         collection_title=self.collection_title,
                         repository=self.repository,
                         expose=self.expose,
                         _info=self.context.info)
     for key, value in iteritems_(self.representers):
         cnt_type, rc_kind = key
         opts, mp_opts = value
         if rc_kind == RESOURCE_KINDS.MEMBER:
             rc = get_member_class(self.interface)
         elif rc_kind == RESOURCE_KINDS.COLLECTION:
             rc = get_collection_class(self.interface)
         else: # None
             rc = self.interface
         discriminator = ('resource_representer', rc, cnt_type, rc_kind)
         self.action(discriminator=discriminator, # pylint: disable=E1101
                     callable=config.add_resource_representer,
                     args=(rc, cnt_type),
                     kw=dict(options=opts,
                             attribute_options=mp_opts,
                             _info=self.context.info),
                     )
开发者ID:b8va,项目名称:everest,代码行数:30,代码来源:directives.py


示例5: with_updated_configuration

    def with_updated_configuration(self, options=None,
                                   attribute_options=None):
        """
        Returns a context in which this mapping is updated with the given
        options and attribute options.
        """
        new_cfg = self.__configurations[-1].copy()
        if not options is None:
            for o_name, o_value in iteritems_(options):
                new_cfg.set_option(o_name, o_value)
        if not attribute_options is None:
            for attr_name, ao_opts in iteritems_(attribute_options):
                for ao_name, ao_value in iteritems_(ao_opts):
                    new_cfg.set_attribute_option(attr_name, ao_name, ao_value)
#        upd_cfg = type(new_cfg)(options=options,
#                                attribute_options=attribute_options)
#        new_cfg.update(upd_cfg)
        return MappingConfigurationContext(self, new_cfg)
开发者ID:helixyte,项目名称:everest,代码行数:18,代码来源:mapping.py


示例6: _decode_dict

    def _decode_dict(self, value):
        # Attribute dictionaries should be case-insensitive. python-ldap
        # defines this, although for some reason, it doesn't appear to use it
        # for search results.
        decoded = self.ldap.cidict.cidict()

        for k, v in iteritems_(value):
            decoded[self.decode(k)] = self.decode(v)

        return decoded
开发者ID:Pylons,项目名称:pyramid_ldap,代码行数:10,代码来源:__init__.py


示例7: to_zipfile

 def to_zipfile(self, resource, zipfile):
     """
     Dumps the given resource and all resources linked to it into the given
     ZIP file.
     """
     rpr_map = self.to_strings(resource)
     with ZipFile(zipfile, 'w') as zipf:
         for (mb_cls, rpr_string) in iteritems_(rpr_map):
             fn = get_collection_filename(mb_cls, self.__content_type)
             zipf.writestr(fn, rpr_string, compress_type=ZIP_DEFLATED)
开发者ID:b8va,项目名称:everest,代码行数:10,代码来源:storing.py


示例8: __init__

 def __init__(self, init_map=None, map_type=dict):
     """
     :param init_map: map-like object to initialize this instance with
     :param map_type: type to use for the left and right item maps
       (dictionary like)
     """
     self.__left = map_type()
     self.__right = map_type()
     if not init_map is None:
         for left, right in iteritems_(init_map):
             self.__setitem__(left, right)
开发者ID:b8va,项目名称:everest,代码行数:11,代码来源:utils.py


示例9: to_files

 def to_files(self, resource, directory):
     """
     Dumps the given resource and all resources linked to it into a set of
     representation files in the given directory.
     """
     collections = self.__collect(resource)
     for (mb_cls, coll) in iteritems_(collections):
         fn = get_write_collection_path(mb_cls,
                                        self.__content_type,
                                        directory=directory)
         with open_text(os.path.join(directory, fn)) as strm:
             dump_resource(coll, strm, content_type=self.__content_type)
开发者ID:b8va,项目名称:everest,代码行数:12,代码来源:storing.py


示例10: check_attributes

def check_attributes(test_object, attribute_map):
    """
    Utility function to test whether the test object attributes match the
    expected ones (given the dictionary).

    :param test_object: a test object
    :param attribute_map: a dictionary with key = attribute name
            and value = expected value for this attribute
    """
    for attr_name, exp_val in iteritems_(attribute_map):
        obj_val = getattr(test_object, attr_name)
        if obj_val != exp_val:
            raise AssertionError('Values for attribute %s differ!'
                                 % attr_name)
开发者ID:b8va,项目名称:everest,代码行数:14,代码来源:testing.py


示例11: run

    def run(self, visitor):
        """
        Traverses this representer configuration traverser with the given
        visitor.

        :param visitor: :class:`RepresenterConfigVisitorBase` instance.
        """
        attr_option_map = self.__config.get_attribute_options()
        # Sorting the keys results in a depth-first traversal, which is just
        # what we want.
        for (key, key_attr_option_map) in sorted(iteritems_(attr_option_map)):
            if not self.__max_depth is None and len(key) > self.__max_depth:
                continue
            visitor.visit(key, key_attr_option_map)
开发者ID:helixyte,项目名称:everest,代码行数:14,代码来源:config.py


示例12: run

 def run(self):
     src_rack = self.__get_rack(self.__source_barcode)
     for tgt_bc in self.__target_barcodes:
         tgt_rack = self.__get_rack(tgt_bc)
         for pos, src_cnt_loc in iteritems_(src_rack.container_positions):
             if not src_cnt_loc.container is None:
                 src_cnt = src_cnt_loc.container
                 if not src_cnt.sample is None:
                     src_smpl = src_cnt.sample
                     tgt_cnt = tgt_rack.container_positions[pos]
                     tgt_smpl = tgt_cnt.make_sample(self.__transfer_volume)
                     for sm in src_smpl.sample_molecules:
                         tgt_smpl.make_sample_molecule(sm.molecule, sm.concentration)
         tgt_rack.status = get_item_status_managed()
开发者ID:helixyte,项目名称:TheLMA,代码行数:14,代码来源:platecopier.py


示例13: __init__

 def __init__(self, data=None):
     if data is None:
         data = {}
     self.fields = []
     self.data = []
     for attr_name, value in iteritems_(data):
         if not isinstance(value, CsvData):
             self.fields.append(attr_name)
             if len(self.data) == 0:
                 self.data.append([value])
             else:
                 for row in self.data:
                     row.append(value)
         else:
             self.expand(value)
开发者ID:helixyte,项目名称:everest,代码行数:15,代码来源:csv.py


示例14: to_strings

    def to_strings(self, resource):
        """
        Dumps the all resources reachable from the given resource to a map of
        string representations using the specified content_type (defaults
        to CSV).

        :returns: dictionary mapping resource member classes to string
            representations
        """
        collections = self.__collect(resource)
        # Build a map of representations.
        rpr_map = OrderedDict()
        for (mb_cls, coll) in iteritems_(collections):
            strm = NativeIO('w')
            dump_resource(coll, strm, content_type=self.__content_type)
            rpr_map[mb_cls] = strm.getvalue()
        return rpr_map
开发者ID:b8va,项目名称:everest,代码行数:17,代码来源:storing.py


示例15: __clone

 def __clone(self, entity, cache):
     clone = object.__new__(entity.__class__)
     # We add the clone with its ID set to the cache *before* we load it
     # so that circular references will work.
     clone.id = entity.id
     cache.add(clone)
     state = EntityState.get_state_data(entity)
     id_attr = None
     for attr, value in iteritems_(state):
         if attr.entity_attr == 'id':
             id_attr = attr
             continue
         attr_type = attr.attr_type
         if attr.kind != RESOURCE_ATTRIBUTE_KINDS.TERMINAL \
            and not self.__repository.is_registered_resource(attr_type):
             # Prevent loading of entities from other repositories.
             # FIXME: Doing this here is inconsistent, since e.g. the RDB
             #        session does not perform this kind of check.
             continue
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.MEMBER \
            and not value is None:
             ent_cls = get_entity_class(attr_type)
             new_value = self.load(ent_cls, value)
             state[attr] = new_value
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.COLLECTION \
              and len(value) > 0:
             value_type = type(value)
             new_value = value_type.__new__(value_type)
             if issubclass(value_type, MutableSequence):
                 add_op = new_value.append
             elif issubclass(value_type, MutableSet):
                 add_op = new_value.add
             else:
                 raise ValueError('Do not know how to clone value of type '
                                  '%s for resource attribute %s.'
                                  % (type(new_value), attr))
             ent_cls = get_entity_class(attr_type)
             for child in value:
                 child_clone = self.load(ent_cls, child)
                 add_op(child_clone)
             state[attr] = new_value
     # We set the ID already above.
     if not id_attr is None:
         del state[id_attr]
     EntityState.set_state_data(clone, state)
     return clone
开发者ID:helixyte,项目名称:everest,代码行数:46,代码来源:session.py


示例16: apply_request_extensions

def apply_request_extensions(request, extensions=None):
    """Apply request extensions (methods and properties) to an instance of
    :class:`pyramid.interfaces.IRequest`. This method is dependent on the
    ``request`` containing a properly initialized registry.

    After invoking this method, the ``request`` should have the methods
    and properties that were defined using
    :meth:`pyramid.config.Configurator.add_request_method`.
    """
    if extensions is None:
        extensions = request.registry.queryUtility(IRequestExtensions)
    if extensions is not None:
        for name, fn in iteritems_(extensions.methods):
            method = fn.__get__(request, request.__class__)
            setattr(request, name, method)

        InstancePropertyHelper.apply_properties(
            request, extensions.descriptors)
开发者ID:7924102,项目名称:pyramid,代码行数:18,代码来源:request.py


示例17: __collect_mapped_attributes

 def __collect_mapped_attributes(self, mapped_class, key):
     if isinstance(key, MappedAttributeKey):
         names = key.names
     else:
         names = key
     collected_mp_attrs = OrderedDict()
     is_mapped_cls = mapped_class is self.__mapped_cls
     if len(names) == 0 and is_mapped_cls:
         # Bootstrapping: fetch resource attributes and create new
         # mapped attributes.
         rc_attrs = get_resource_class_attributes(self.__mapped_cls)
         for rc_attr in itervalues_(rc_attrs):
             attr_key = names + (rc_attr.resource_attr,)
             attr_mp_opts = \
                 self.__configurations[-1].get_attribute_options(attr_key)
             new_mp_attr = MappedAttribute(rc_attr, options=attr_mp_opts)
             collected_mp_attrs[new_mp_attr.resource_attr] = new_mp_attr
     else:
         # Indirect access - fetch mapped attributes from some other
         # class' mapping and clone.
         if is_mapped_cls:
             mp = self
         elif len(names) == 0 and self.__is_collection_mapping:
             if provides_member_resource(mapped_class):
                 # Mapping a polymorphic member class.
                 mapped_coll_cls = get_collection_class(mapped_class)
             else:
                 # Mapping a derived collection class.
                 mapped_coll_cls = mapped_class
             mp = self.__mp_reg.find_or_create_mapping(mapped_coll_cls)
         else:
             mp = self.__mp_reg.find_or_create_mapping(mapped_class)
         mp_attrs = mp.get_attribute_map()
         for mp_attr in itervalues_(mp_attrs):
             attr_key = names + (mp_attr.name,)
             attr_mp_opts = \
                 dict(((k, v)
                       for (k, v) in
                         iteritems_(self.__configurations[-1]
                                    .get_attribute_options(attr_key))
                       if not v is None))
             clnd_mp_attr = mp_attr.clone(options=attr_mp_opts)
             collected_mp_attrs[mp_attr.name] = clnd_mp_attr
     return collected_mp_attrs
开发者ID:b8va,项目名称:everest,代码行数:44,代码来源:mapping.py


示例18: test_member_data_element

 def test_member_data_element(self):
     data_el = SimpleMemberDataElement.create()
     # Test nesteds.
     assert list(data_el.nesteds.keys()) == []
     parent_data_el = SimpleMemberDataElement.create()
     rc_nested_attr = \
         get_resource_class_attribute(MyEntityMember, 'parent')
     mp_nested_attr = MappedAttribute(rc_nested_attr)
     data_el.set_nested(mp_nested_attr, parent_data_el)
     assert data_el.get_nested(mp_nested_attr) is parent_data_el
     assert list(data_el.nesteds.keys()) == ['parent']
     # Test terminals.
     assert list(data_el.terminals.keys()) == []
     utc = timezone('UTC')
     ldt = datetime.datetime(2012, 8, 29, 16, 20, 0, tzinfo=utc)
     term_attr_data = OrderedDict(text='foo',
                                  number=0,
                                  date_time=ldt)
     for term_attr_name, term_attr_value in term_attr_data.items():
         rc_attr = get_resource_class_attribute(MyEntityMember,
                                                term_attr_name)
         mp_attr = MappedAttribute(rc_attr)
         # Check setting to None value.
         data_el.set_terminal(mp_attr, None)
         assert data_el.get_terminal(mp_attr) is None
         data_el.set_terminal_converted(mp_attr, None)
         assert data_el.get_terminal(mp_attr) is None
         # Check setting to value.
         data_el.set_terminal(mp_attr, term_attr_value)
         assert data_el.get_terminal(mp_attr) == term_attr_value
         rpr_val = data_el.get_terminal_converted(mp_attr)
         data_el.set_terminal_converted(mp_attr, rpr_val)
         assert data_el.get_terminal(mp_attr) == term_attr_value
     assert list(data_el.terminals.keys()) == list(term_attr_data.keys())
     # Printing.
     prt_str = str(data_el)
     assert prt_str.startswith(data_el.__class__.__name__)
     assert prt_str.endswith(')')
     # Attribute iteration.
     for attr_name, attr_value in iteritems_(term_attr_data):
         assert data_el.get_attribute(attr_name) == attr_value
     for de_attr_name, de_attr_value in data_el.iterator():
         if de_attr_name in term_attr_data:
             assert de_attr_value == term_attr_data[de_attr_name]
开发者ID:helixyte,项目名称:everest,代码行数:44,代码来源:test_dataelements.py


示例19: visit_member

    def visit_member(self, attribute_key, attribute, member_node, member_data,
                     is_link_node, parent_data, index=None):
        if is_link_node:
            mb_data = member_node.get_url()
        else:
            # Using an ordered dict gives us reproducible representations.
            mb_data = OrderedDict()
            for attr, value in iteritems_(member_data):
#                if attr.kind == RESOURCE_ATTRIBUTE_KINDS.TERMINAL:
                mb_data[attr.repr_name] = value
            # Use the relation for class hinting.
            mb_cls = member_node.mapping.mapped_class
            mb_data['__jsonclass__'] = mb_cls.relation
        if not index is None:
            parent_data[index] = mb_data
        elif len(attribute_key) == 0:
            self.__json_data = mb_data
        else:
            parent_data[attribute] = mb_data
开发者ID:helixyte,项目名称:everest,代码行数:19,代码来源:json.py


示例20: get_attribute_options

    def get_attribute_options(self, attribute=None):
        """
        Returns a copy of the mapping options for the given attribute name
        or a copy of all mapping options, if no attribute name is provided.
        All options that were not explicitly configured are given a default
        value of `None`.

        :param tuple attribute_key: attribute name or tuple specifying an
          attribute path.
        :returns: mapping options dictionary (including default `None` values)
        """
        attribute_key = self.__make_key(attribute)
        if attribute_key is None:
            opts = defaultdict(self._default_attributes_options.copy)
            for attr, mp_options in iteritems_(self.__attribute_options):
                opts[attr].update(mp_options)
        else:
            opts = self._default_attributes_options.copy()
            attr_opts = self.__attribute_options[attribute_key]
            opts.update(attr_opts)
        return opts
开发者ID:helixyte,项目名称:everest,代码行数:21,代码来源:config.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compat.native_函数代码示例发布时间:2022-05-27
下一篇:
Python compat.is_nonstr_iter函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap