本文整理汇总了Python中collections.MutableMapping类的典型用法代码示例。如果您正苦于以下问题:Python MutableMapping类的具体用法?Python MutableMapping怎么用?Python MutableMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __delattr__
def __delattr__(self, name):
# Names starting with an underscore are not preferences but normal
# instance attributes
if name.startswith('_'):
MutableMapping.__delattr__(self, name)
else:
del self._all_prefs[self._basename + '.' + name]
示例2: update
def update(self, *args, **kwargs):
if len(args) > 1:
raise TypeError("update() takes at most 1 positional "
"arguments ({} given)".format(len(args)))
if len(args) >= 1:
other = args[0]
if isinstance(other, KeyedList):
# Merge
for key, value in other.all_items():
self[key] = value
else:
MutableMapping.update(self, other)
for key, value in kwargs.items():
if isinstance(value, KeyedList):
try:
subkl = self[key]
except KeyError:
subkl = KeyedList()
self[key] = subkl
else:
if not isinstance(subkl, KeyedList):
raise KeyError('target key "%s" is a value, cannot '
'update value against another keyed list' %
(key,))
subkl.update(value)
else:
self[key] = value
示例3: update
def update(*args, **kwds):
self = args[0]
with FastInserter(self.cursor):
MutableMapping.update(*args, **kwds)
# make table and index stored contiguously
self.cursor.execute("VACUUM")
示例4: __init__
def __init__(self, *state: tuple):
MutableMapping.__init__(self)
MutableComposite.__init__(self)
try:
for i, name in enumerate(self._fields):
setattr(self, name, state[i])
except IndexError:
IndexError("Instantiate %s with %u elements, but required are: %s"
% (self.__class__.__name__, len(state), self._fields))
示例5: __init__
def __init__(*args, **kwargs):
if not args:
raise TypeError("OrderedDict.__init__() needs an instance as the first argument")
self = args[0]
args = args[1:]
if len(args) > 1:
raise TypeError("OrderedDict() takes at most 1 positional argument, got %d" % len(args))
dict.__init__(self)
if not self:
self._keys = []
MutableMapping.update(self, *args, **kwargs)
示例6: update
def update(self, *args, **kw):
if args:
lst = args[0]
if len(lst) != len(dict(lst)):
# this does not catch the cases where we overwrite existing
# keys, but those would produce too many warning
msg = ("Behavior of MultiDict.update() has changed "
"and overwrites duplicate keys. Consider using .extend()"
)
warnings.warn(msg, UserWarning, stacklevel=2)
MutableMapping.update(self, *args, **kw)
示例7: __init__
def __init__(self, query="", sort_keys=False, lower_keys=False, upper_keys=False):
MutableMapping.__init__(self)
self._parameters = []
self._sort_keys = sort_keys
self._lower_keys = lower_keys
self._upper_keys = upper_keys
if isinstance(query, Mapping):
if isinstance(query, _ParamMap):
if query.is_sort_keys():
self.set_sort_keys()
if query.is_lower_keys():
self.set_lower_keys()
if query.is_upper_keys():
self.set_upper_keys()
self.update(query)
elif query is not None:
self.update(OrderedDict(urlparse.parse_qsl(str(query))))
示例8: __getattr__
def __getattr__(self, name):
if name in self.__dict__ or name.startswith('__'):
return MutableMapping.__getattr__(self, name)
# This function might get called from BrianGlobalPreferencesView with
# a prefixed name -- therefore the name can contain dots!
if name in self.pref_register:
# This asks for a category, not a single preference
return BrianGlobalPreferencesView(name, self)
basename, _ = parse_preference_name(name)
if len(basename) and basename not in self.pref_register:
raise AssertionError(('__getattr__ received basename %s which is '
'unregistered. This should never happen!') %
basename)
return self[name]
示例9: __init__
def __init__(self, **kwargs):
MutableMapping.__init__(self)
self.modifications = {}
""" Holds chemical modifications. """
self.breaksym = kwargs.get('breaksym', not kwargs.get('keepsymm', False))
""" Whether to break symmetries or not. """
示例10:
from collections import MutableMapping
from ._sortedmap import sortedmap
MutableMapping.register(sortedmap)
del MutableMapping
__version__ = '0.2.0'
__all__ = [
'sortedmap',
]
示例11: keys
else:
def keys(self):
# type: () -> List[Any]
return list(self)
def items(self):
# type: () -> List[Tuple[Any, Any]]
return list(self._iterate_items())
def values(self):
# type: () -> List[Any]
return list(self._iterate_values())
MutableMapping.register(DictAttribute) # noqa: E305
class ChainMap(MutableMapping):
"""Key lookup on a sequence of maps."""
key_t = None
changes = None
defaults = None
maps = None
def __init__(self, *maps, **kwargs):
# type: (*Mapping, **Any) -> None
maps = list(maps or [{}])
self.__dict__.update(
key_t=kwargs.get('key_t'),
示例12: clear
def clear(self):
if len(self._dict) > 0:
MutableMapping.clear(self)
示例13: TypeWrapper
self.vars[key] = TypeWrapper(value)
else:
self.vars[key] = SetWrapper(value)
def copy(self, *args, **kwargs):
return type(self)(self.vars.copy(*args, **kwargs))
def display(self, **kwargs):
ret = 'Domain('
strs = ['{} = {}'.format(var, vals.display(**kwargs))
for var, vals in sorted(self.vars.items(), key=itemgetter(0))]
ret += ',\n '.join(strs) + ')'
return ret
MutableMapping.register(Domain)
#-------------------------------------------------------------------------------
# Constraint
class Constraint(Base):
_attrs = dict(args = Attr(Sequence,
init=lambda self: tuple()))
_opts = dict(init_validate = True,
args = ('args',),
make_hashable = True)
def check(self, **kwargs):
raise NotImplementedError
示例14: popitem
def popitem(self, last=True):
if not self:
raise KeyError("dict is empty")
key = next(reversed(self) if last else iter(self))
return key, MutableMapping.pop(self, key)
示例15: get
def get(self, key, default=None):
"""Return value for given ``key`` or ``default`` value."""
try:
return self[key]
except KeyError:
return default
def set(self, key, value, extend=False, **kwargs):
"""Extended standard set function."""
self.__setitem__(key, value, extend, **kwargs)
def update(self, E, **F):
"""Proxy `dict` update method."""
self._dict.update(E, **F)
MutableMapping.register(SmartDict)
class DotableDict(dict):
"""Make nested python dictionaries accessable using dot notation.
Example:
.. code-block:: python
>>> dotable = DotableDict({'a': [{'b': 3, 'c': 5}]})
>>> dotable.a
... [{'b': 3, 'c': 5}]
"""