o $ x`R@sdZddlmZddlmZddlmZGdddeZGdddej eZ Gd d d eZ Gd d d ej e Z Gd dde e ZGddde ZGdddeZGdddeZGddde ZGdddejeeeeZdS)ah Mapping Interfaces. Importing this module does *not* mark any standard classes as implementing any of these interfaces. While this module is not deprecated, new code should generally use :mod:`zope.interface.common.collections`, specifically :class:`~zope.interface.common.collections.IMapping` and :class:`~zope.interface.common.collections.IMutableMapping`. This module is occasionally useful for its extremely fine grained breakdown of interfaces. The standard library :class:`dict` and :class:`collections.UserDict` implement ``IMutableMapping``, but *do not* implement any of the interfaces in this module. ) Interface)PYTHON2) collectionsc@eZdZdZddZdS) IItemMappingz%Simplest readable mapping object cCdS)z`Get a value for a key A `KeyError` is raised if there is no value for the key. Nkeyrr?/usr/lib/python3/dist-packages/zope/interface/common/mapping.py __getitem__'zIItemMapping.__getitem__N)__name__ __module__ __qualname____doc__r rrrr r#s rc@s"eZdZdZdddZddZdS) IReadMappingz^ Basic mapping interface. .. versionchanged:: 5.0.0 Extend ``IContainer`` NcCr)zaGet a value for a key The default is returned if there is no value for the key. Nrr defaultrrr get6r zIReadMapping.getcCr)z$Tell if a key exists in the mapping.Nrr rrr __contains__<r zIReadMapping.__contains__N)rrrrrrrrrr r.s  rc@s eZdZdZddZddZdS) IWriteMappingz!Mapping methods for changing datacCr)z.Delete a value from the mapping using the key.Nrr rrr __delitem__Dr zIWriteMapping.__delitem__cCr)zSet a new item in the mapping.Nr)r valuerrr __setitem__Gr zIWriteMapping.__setitem__N)rrrrrrrrrr rAs rc@s0eZdZdZddZddZddZdd Zd S) IEnumerableMappingzp Mapping objects whose items can be enumerated. .. versionchanged:: 5.0.0 Extend ``ISized`` cCr)z/Return the keys of the mapping object. Nrrrrr keysSr zIEnumerableMapping.keyscCr)z?Return an iterator for the keys of the mapping object. Nrrrrr __iter__Wr zIEnumerableMapping.__iter__cCr)z1Return the values of the mapping object. Nrrrrr values[r zIEnumerableMapping.valuescCr)z0Return the items of the mapping object. Nrrrrr items_r zIEnumerableMapping.itemsN)rrrrrrrr rrrr rKs  rc@eZdZdZdS)IMappingz Simple mapping interface Nrrrrrrrr r"csr"c@s0eZdZdZerddZddZddZdSdS) IIterableMappingzA mapping that has distinct methods for iterating without copying. On Python 2, a `dict` has these methods, but on Python 3 the methods defined in `IEnumerableMapping` already iterate without copying. cCr)z-iterate over keys; equivalent to ``__iter__``Nrrrrr iterkeyspr zIIterableMapping.iterkeyscCr)ziterate over valuesNrrrrr itervaluessr zIIterableMapping.itervaluescCr)ziterate over itemsNrrrrr iteritemsvr zIIterableMapping.iteritemsN)rrrrPY2r%r&r'rrrr r$fs r$c@r)IClonableMappingzSSomething that can produce a copy of itself. This is available in `dict`. cCr)zreturn copy of dictNrrrrr copyr zIClonableMapping.copyN)rrrrr*rrrr r)ys r)c@s eZdZdZerddZdSdS)IExtendedReadMappingz Something with a particular method equivalent to ``__contains__``. On Python 2, `dict` provides this method, but it was removed in Python 3. cCr)zCTell if a key exists in the mapping; equivalent to ``__contains__``Nrr rrr has_keyr zIExtendedReadMapping.has_keyN)rrrrr(r,rrrr r+s  r+c@s<eZdZdZddZddZd ddZd d d Zd d ZdS)IExtendedWriteMappingzHAdditional mutation methods. These are all provided by `dict`. cCr)zdelete all itemsNrrrrr clearr zIExtendedWriteMapping.clearcCr)z0 Update D from E: for k in E.keys(): D[k] = E[k]Nr)drrr updater zIExtendedWriteMapping.updateNcCr)z@D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in DNrrrrr setdefaultr z IExtendedWriteMapping.setdefaultcCr)a  pop(k[,default]) -> value Remove specified key and return the corresponding value. If key is not found, *default* is returned if given, otherwise `KeyError` is raised. Note that *default* must not be passed by name. Nr)krrrr popr zIExtendedWriteMapping.popcCr)zeremove and return some (key, value) pair as a 2-tuple; but raise KeyError if mapping is emptyNrrrrr popitemr zIExtendedWriteMapping.popitemr) rrrrr.r0r1r3r4rrrr r-s   r-c@r!) IFullMappinga$ Full mapping interface. Most uses of this interface should instead use :class:`~zope.interface.commons.collections.IMutableMapping` (one of the bases of this interface). The required methods are the same. .. versionchanged:: 5.0.0 Extend ``IMutableMapping`` Nr#rrrr r5sr5N)rzope.interfacerzope.interface._compatrr(zope.interface.commonrr IContainerrrISizedrr"r$r)r+r-IMutableMappingr5rrrr s"