本文整理汇总了Python中collections.Mapping.register方法的典型用法代码示例。如果您正苦于以下问题:Python Mapping.register方法的具体用法?Python Mapping.register怎么用?Python Mapping.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections.Mapping
的用法示例。
在下文中一共展示了Mapping.register方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeprecationWarning
# 需要导入模块: from collections import Mapping [as 别名]
# 或者: from collections.Mapping import register [as 别名]
DeprecationWarning(
"variables set in a base template "
"will no longer leak into the child "
"context in future versions. Happened "
"when " + detail
)
)
return base_rv
return self_rv
# register the context as mapping if possible
try:
from collections import Mapping
Mapping.register(Context)
except ImportError:
pass
class BlockReference(object):
"""One block on a template reference."""
def __init__(self, name, context, stack, depth):
self.name = name
self._context = context
self._stack = stack
self._depth = depth
@property
def super(self):
示例2: pmap
# 需要导入模块: from collections import Mapping [as 别名]
# 或者: from collections.Mapping import register [as 别名]
>>> m1
pmap({'a': 1, 'b': 2})
The changes are kept in the evolver. An updated pmap can be created using the
persistent() function on the evolver.
>>> m2 = e.persistent()
>>> m2
pmap({'c': 3, 'b': 2})
The new pmap will share data with the original pmap in the same way that would have
been done if only using operations on the pmap.
"""
return self._Evolver(self)
Mapping.register(PMap)
Hashable.register(PMap)
def _turbo_mapping(initial, pre_size):
size = pre_size or (2 * len(initial)) or 8
buckets = size * [None]
if not isinstance(initial, Mapping):
# Make a dictionary of the initial data if it isn't already,
# that will save us some job further down since we can assume no
# key collisions
initial = dict(initial)
for k, v in six.iteritems(initial):
h = hash(k)
示例3: __iter__
# 需要导入模块: from collections import Mapping [as 别名]
# 或者: from collections.Mapping import register [as 别名]
return 0
def __iter__(self):
return ()
def __getitem__(self, key):
raise KeyError(key)
def __nonzero__(self):
return False
__bool__ = __nonzero__
def __enter__(self):
return _null_context
def __exit__(self, exc_type, exc_value, traceback):
return False
def get(self, name, default=None):
return default
_null_context = NullContext()
from collections import Mapping
Mapping.register(NullContext)
del Mapping
示例4: list
# 需要导入模块: from collections import Mapping [as 别名]
# 或者: from collections.Mapping import register [as 别名]
for key in list(other.keys()):
self[key] = other[key]
else:
for key, value in other:
self[key] = value
for key, value in list(kwds.items()):
self[key] = value
def setdefault(self, key, default=None):
try:
return self[key]
except KeyError:
self[key] = default
return default
_Mapping.register(Mapping)
else:
# In Python 3 we can just use MutableMapping directly, because it defines
# __slots__.
from collections import MutableMapping
class BaseContainer(object):
"""Base container class."""
# Minimizes memory usage and disallows assignment to other attributes.
__slots__ = ['_message_listener', '_values']
def __init__(self, message_listener):
示例5: values
# 需要导入模块: from collections import Mapping [as 别名]
# 或者: from collections.Mapping import register [as 别名]
def values(self):
"""D.values() -> list of D's values."""
return self._dict.values()
def __iter__(self):
"""x.__iter__() <==> iter(x)."""
return iter(self._dict)
def __len__(self):
"""x.__len__() <==> len(x)."""
return self._dict.__len__()
def get(self, key, default=None):
"""D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."""
return self._dict.get(sympify(key), default)
def __contains__(self, key):
"""D.__contains__(k) -> True if D has a key k, else False."""
return sympify(key) in self._dict
def __lt__(self, other):
return sympify(self.args < other.args)
@property
def _sorted_args(self):
from ..utilities import default_sort_key
return tuple(sorted(self.args, key=default_sort_key))
Mapping.register(Dict)