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


Python UserDict.__setitem__方法代码示例

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


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

示例1: addLazySingleton

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def addLazySingleton(self, item_key, value_callable, *pargs, **kwargs):
		"""This is like addLazyItem except value_callable will only be called
		a maximum of 1 time and the result will be cached for future requests."""
		self.lazy_items[item_key] = \
			self._LazyItem(value_callable, pargs, kwargs, True)
		# make it show up in self.keys(), etc...
		UserDict.__setitem__(self, item_key, None)
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:9,代码来源:__init__.py

示例2: addLazyItem

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def addLazyItem(self, item_key, value_callable, *pargs, **kwargs):
		"""Add a lazy item for the given key.  When the item is requested,
		value_callable will be called with *pargs and **kwargs arguments."""
		self.lazy_items[item_key] = \
			self._LazyItem(value_callable, pargs, kwargs, False)
		# make it show up in self.keys(), etc...
		UserDict.__setitem__(self, item_key, None)
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:9,代码来源:__init__.py

示例3: __deepcopy__

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def __deepcopy__(self, memo=None):
		"""
		This forces evaluation of each contained lazy item, and deepcopy of
		the result. A TypeError is raised if any contained lazy item is not
		a singleton, since it is not necessarily possible for the behavior
		of this type of item to be safely preserved.
		"""
		if memo is None:
			memo = {}
		result = self.__class__()
		memo[id(self)] = result
		for k in self:
			k_copy = deepcopy(k, memo)
			lazy_item = self.lazy_items.get(k)
			if lazy_item is not None:
				if not lazy_item.singleton:
					raise TypeError(_unicode_decode("LazyItemsDict " + \
						"deepcopy is unsafe with lazy items that are " + \
						"not singletons: key=%s value=%s") % (k, lazy_item,))
			UserDict.__setitem__(result, k_copy, deepcopy(self[k], memo))
		return result
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:23,代码来源:__init__.py

示例4: update

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def update(self, *args, **kwargs):
		if len(args) > 1:
			raise TypeError(
				"expected at most 1 positional argument, got " + \
				repr(len(args)))
		if args:
			map_obj = args[0]
		else:
			map_obj = None
		if map_obj is None:
			pass
		elif isinstance(map_obj, LazyItemsDict):
			for k in map_obj:
				if k in map_obj.lazy_items:
					UserDict.__setitem__(self, k, None)
				else:
					UserDict.__setitem__(self, k, map_obj[k])
			self.lazy_items.update(map_obj.lazy_items)
		else:
			UserDict.update(self, map_obj)
		if kwargs:
			UserDict.update(self, kwargs)
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:24,代码来源:__init__.py

示例5: __deepcopy__

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def __deepcopy__(self, memo=None):
		"""
		WARNING: If any of the lazy items contains a bound method then it's
		typical for deepcopy() to raise an exception like this:

			File "/usr/lib/python2.5/copy.py", line 189, in deepcopy
				y = _reconstruct(x, rv, 1, memo)
			File "/usr/lib/python2.5/copy.py", line 322, in _reconstruct
				y = callable(*args)
			File "/usr/lib/python2.5/copy_reg.py", line 92, in __newobj__
				return cls.__new__(cls, *args)
			TypeError: instancemethod expected at least 2 arguments, got 0

		If deepcopy() needs to work, this problem can be avoided by
		implementing lazy items with normal (non-bound) functions.

		If deepcopy() raises a TypeError for a lazy item that has been added
		via a call to addLazySingleton(), the singleton will be automatically
		evaluated and deepcopy() will instead be called on the result.
		"""
		if memo is None:
			memo = {}
		result = self.__class__()
		memo[id(self)] = result
		for k in self:
			k_copy = deepcopy(k, memo)
			if k in self.lazy_items:
				lazy_item = self.lazy_items[k]
				try:
					result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
				except TypeError:
					if not lazy_item.singleton:
						raise
					UserDict.__setitem__(result,
						k_copy, deepcopy(self[k], memo))
				else:
					UserDict.__setitem__(result, k_copy, None)
			else:
				UserDict.__setitem__(result, k_copy, deepcopy(self[k], memo))
		return result
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:42,代码来源:__init__.py

示例6: __setitem__

# 需要导入模块: from portage.cache.mappings import UserDict [as 别名]
# 或者: from portage.cache.mappings.UserDict import __setitem__ [as 别名]
	def __setitem__(self, item_key, value):
		if item_key in self.lazy_items:
			del self.lazy_items[item_key]
		UserDict.__setitem__(self, item_key, value)
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:6,代码来源:__init__.py


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