comparison mercurial/thirdparty/zope/interface/common/mapping.py @ 37178:68ee61822182

thirdparty: port zope.interface to relative imports By using relative imports, we're guaranteed to get modules vendored with Mercurial rather than other random modules that might be in sys.path. My editor strips trailing whitespace on save. So some minor source code cleanup was also performed as part of this commit. # no-check-commit because some modified lines have double newlines Differential Revision: https://phab.mercurial-scm.org/D2930
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 21 Mar 2018 19:52:30 -0700
parents 943d77fc07a3
children
comparison
equal deleted inserted replaced
37177:338367d44d34 37178:68ee61822182
11 # FOR A PARTICULAR PURPOSE. 11 # FOR A PARTICULAR PURPOSE.
12 # 12 #
13 ############################################################################## 13 ##############################################################################
14 """Mapping Interfaces 14 """Mapping Interfaces
15 """ 15 """
16 from zope.interface import Interface 16
17 from __future__ import absolute_import
18
19 from .. import Interface
17 20
18 class IItemMapping(Interface): 21 class IItemMapping(Interface):
19 """Simplest readable mapping object 22 """Simplest readable mapping object
20 """ 23 """
21 24
40 """Tell if a key exists in the mapping.""" 43 """Tell if a key exists in the mapping."""
41 44
42 45
43 class IWriteMapping(Interface): 46 class IWriteMapping(Interface):
44 """Mapping methods for changing data""" 47 """Mapping methods for changing data"""
45 48
46 def __delitem__(key): 49 def __delitem__(key):
47 """Delete a value from the mapping using the key.""" 50 """Delete a value from the mapping using the key."""
48 51
49 def __setitem__(key, value): 52 def __setitem__(key, value):
50 """Set a new item in the mapping.""" 53 """Set a new item in the mapping."""
51 54
52 55
53 class IEnumerableMapping(IReadMapping): 56 class IEnumerableMapping(IReadMapping):
54 """Mapping objects whose items can be enumerated. 57 """Mapping objects whose items can be enumerated.
55 """ 58 """
56 59
87 90
88 def iteritems(): 91 def iteritems():
89 "iterate over items" 92 "iterate over items"
90 93
91 class IClonableMapping(Interface): 94 class IClonableMapping(Interface):
92 95
93 def copy(): 96 def copy():
94 "return copy of dict" 97 "return copy of dict"
95 98
96 class IExtendedReadMapping(IIterableMapping): 99 class IExtendedReadMapping(IIterableMapping):
97 100
98 def has_key(key): 101 def has_key(key):
99 """Tell if a key exists in the mapping; equivalent to __contains__""" 102 """Tell if a key exists in the mapping; equivalent to __contains__"""
100 103
101 class IExtendedWriteMapping(IWriteMapping): 104 class IExtendedWriteMapping(IWriteMapping):
102 105
103 def clear(): 106 def clear():
104 "delete all items" 107 "delete all items"
105 108
106 def update(d): 109 def update(d):
107 " Update D from E: for k in E.keys(): D[k] = E[k]" 110 " Update D from E: for k in E.keys(): D[k] = E[k]"
108 111
109 def setdefault(key, default=None): 112 def setdefault(key, default=None):
110 "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D" 113 "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"
111 114
112 def pop(k, *args): 115 def pop(k, *args):
113 """remove specified key and return the corresponding value 116 """remove specified key and return the corresponding value
114 *args may contain a single default value, or may not be supplied. 117 *args may contain a single default value, or may not be supplied.
115 If key is not found, default is returned if given, otherwise 118 If key is not found, default is returned if given, otherwise
116 KeyError is raised""" 119 KeyError is raised"""
117 120
118 def popitem(): 121 def popitem():
119 """remove and return some (key, value) pair as a 122 """remove and return some (key, value) pair as a
120 2-tuple; but raise KeyError if mapping is empty""" 123 2-tuple; but raise KeyError if mapping is empty"""
121 124
122 class IFullMapping( 125 class IFullMapping(