本文整理汇总了Python中pyramid.compat.iteritems_函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems_函数的具体用法?Python iteritems_怎么用?Python iteritems_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteritems_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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),
)
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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)
示例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
示例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