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


Python collections.MutableMapping类代码示例

本文整理汇总了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]
开发者ID:brian-team,项目名称:brian2,代码行数:7,代码来源:preferences.py

示例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
开发者ID:selvendran-varathan,项目名称:python-development,代码行数:29,代码来源:keyedlist.py

示例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")
开发者ID:3D-e-Chem,项目名称:kripodb,代码行数:7,代码来源:db.py

示例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))
开发者ID:MartinMartimeo,项目名称:avalon,代码行数:9,代码来源:mutable.py

示例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)
开发者ID:dmitryTsatsarin,项目名称:schematics,代码行数:11,代码来源:datastructures.py

示例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)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:11,代码来源:multidict.py

示例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))))
开发者ID:dylan171,项目名称:ControlSystemWeb,代码行数:17,代码来源:url.py

示例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]
开发者ID:brian-team,项目名称:brian2,代码行数:17,代码来源:preferences.py

示例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. """
开发者ID:mdavezac,项目名称:LaDa,代码行数:6,代码来源:basis.py

示例10:

from collections import MutableMapping

from ._sortedmap import sortedmap


MutableMapping.register(sortedmap)
del MutableMapping


__version__ = '0.2.0'


__all__ = [
    'sortedmap',
]
开发者ID:llllllllll,项目名称:sortedmap,代码行数:15,代码来源:__init__.py

示例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'),
开发者ID:alekibango,项目名称:celery,代码行数:31,代码来源:collections.py

示例12: clear

 def clear(self):
     if len(self._dict) > 0:
         MutableMapping.clear(self)
开发者ID:mlilien,项目名称:sloth,代码行数:3,代码来源:model.py

示例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
开发者ID:mbodenhamer,项目名称:syn,代码行数:30,代码来源:base.py

示例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)
开发者ID:DasIch,项目名称:awwparse,代码行数:5,代码来源:utils.py

示例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}]
    """
开发者ID:SamiHiltunen,项目名称:jsonalchemy,代码行数:30,代码来源:wrappers.py


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