diff options
Diffstat (limited to 'bitbake/lib/bb/COW.py')
-rw-r--r-- | bitbake/lib/bb/COW.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/bitbake/lib/bb/COW.py b/bitbake/lib/bb/COW.py index 6917ec378a..77a05cfe35 100644 --- a/bitbake/lib/bb/COW.py +++ b/bitbake/lib/bb/COW.py | |||
@@ -23,19 +23,17 @@ | |||
23 | # Assign a file to __warn__ to get warnings about slow operations. | 23 | # Assign a file to __warn__ to get warnings about slow operations. |
24 | # | 24 | # |
25 | 25 | ||
26 | from __future__ import print_function | 26 | |
27 | import copy | 27 | import copy |
28 | import types | 28 | import types |
29 | ImmutableTypes = ( | 29 | ImmutableTypes = ( |
30 | types.NoneType, | ||
31 | bool, | 30 | bool, |
32 | complex, | 31 | complex, |
33 | float, | 32 | float, |
34 | int, | 33 | int, |
35 | long, | ||
36 | tuple, | 34 | tuple, |
37 | frozenset, | 35 | frozenset, |
38 | basestring | 36 | str |
39 | ) | 37 | ) |
40 | 38 | ||
41 | MUTABLE = "__mutable__" | 39 | MUTABLE = "__mutable__" |
@@ -61,7 +59,7 @@ class COWDictMeta(COWMeta): | |||
61 | __call__ = cow | 59 | __call__ = cow |
62 | 60 | ||
63 | def __setitem__(cls, key, value): | 61 | def __setitem__(cls, key, value): |
64 | if not isinstance(value, ImmutableTypes): | 62 | if value is not None and not isinstance(value, ImmutableTypes): |
65 | if not isinstance(value, COWMeta): | 63 | if not isinstance(value, COWMeta): |
66 | cls.__hasmutable__ = True | 64 | cls.__hasmutable__ = True |
67 | key += MUTABLE | 65 | key += MUTABLE |
@@ -116,7 +114,7 @@ class COWDictMeta(COWMeta): | |||
116 | cls.__setitem__(key, cls.__marker__) | 114 | cls.__setitem__(key, cls.__marker__) |
117 | 115 | ||
118 | def __revertitem__(cls, key): | 116 | def __revertitem__(cls, key): |
119 | if not cls.__dict__.has_key(key): | 117 | if key not in cls.__dict__: |
120 | key += MUTABLE | 118 | key += MUTABLE |
121 | delattr(cls, key) | 119 | delattr(cls, key) |
122 | 120 | ||
@@ -183,7 +181,7 @@ class COWSetMeta(COWDictMeta): | |||
183 | COWDictMeta.__delitem__(cls, repr(hash(value))) | 181 | COWDictMeta.__delitem__(cls, repr(hash(value))) |
184 | 182 | ||
185 | def __in__(cls, value): | 183 | def __in__(cls, value): |
186 | return COWDictMeta.has_key(repr(hash(value))) | 184 | return repr(hash(value)) in COWDictMeta |
187 | 185 | ||
188 | def iterkeys(cls): | 186 | def iterkeys(cls): |
189 | raise TypeError("sets don't have keys") | 187 | raise TypeError("sets don't have keys") |
@@ -192,12 +190,10 @@ class COWSetMeta(COWDictMeta): | |||
192 | raise TypeError("sets don't have 'items'") | 190 | raise TypeError("sets don't have 'items'") |
193 | 191 | ||
194 | # These are the actual classes you use! | 192 | # These are the actual classes you use! |
195 | class COWDictBase(object): | 193 | class COWDictBase(object, metaclass = COWDictMeta): |
196 | __metaclass__ = COWDictMeta | ||
197 | __count__ = 0 | 194 | __count__ = 0 |
198 | 195 | ||
199 | class COWSetBase(object): | 196 | class COWSetBase(object, metaclass = COWSetMeta): |
200 | __metaclass__ = COWSetMeta | ||
201 | __count__ = 0 | 197 | __count__ = 0 |
202 | 198 | ||
203 | if __name__ == "__main__": | 199 | if __name__ == "__main__": |
@@ -217,11 +213,11 @@ if __name__ == "__main__": | |||
217 | print() | 213 | print() |
218 | 214 | ||
219 | print("a", a) | 215 | print("a", a) |
220 | for x in a.iteritems(): | 216 | for x in a.items(): |
221 | print(x) | 217 | print(x) |
222 | print("--") | 218 | print("--") |
223 | print("b", b) | 219 | print("b", b) |
224 | for x in b.iteritems(): | 220 | for x in b.items(): |
225 | print(x) | 221 | print(x) |
226 | print() | 222 | print() |
227 | 223 | ||
@@ -229,11 +225,11 @@ if __name__ == "__main__": | |||
229 | b['a'] = 'c' | 225 | b['a'] = 'c' |
230 | 226 | ||
231 | print("a", a) | 227 | print("a", a) |
232 | for x in a.iteritems(): | 228 | for x in a.items(): |
233 | print(x) | 229 | print(x) |
234 | print("--") | 230 | print("--") |
235 | print("b", b) | 231 | print("b", b) |
236 | for x in b.iteritems(): | 232 | for x in b.items(): |
237 | print(x) | 233 | print(x) |
238 | print() | 234 | print() |
239 | 235 | ||
@@ -248,22 +244,22 @@ if __name__ == "__main__": | |||
248 | a['set'].add("o2") | 244 | a['set'].add("o2") |
249 | 245 | ||
250 | print("a", a) | 246 | print("a", a) |
251 | for x in a['set'].itervalues(): | 247 | for x in a['set'].values(): |
252 | print(x) | 248 | print(x) |
253 | print("--") | 249 | print("--") |
254 | print("b", b) | 250 | print("b", b) |
255 | for x in b['set'].itervalues(): | 251 | for x in b['set'].values(): |
256 | print(x) | 252 | print(x) |
257 | print() | 253 | print() |
258 | 254 | ||
259 | b['set'].add('o3') | 255 | b['set'].add('o3') |
260 | 256 | ||
261 | print("a", a) | 257 | print("a", a) |
262 | for x in a['set'].itervalues(): | 258 | for x in a['set'].values(): |
263 | print(x) | 259 | print(x) |
264 | print("--") | 260 | print("--") |
265 | print("b", b) | 261 | print("b", b) |
266 | for x in b['set'].itervalues(): | 262 | for x in b['set'].values(): |
267 | print(x) | 263 | print(x) |
268 | print() | 264 | print() |
269 | 265 | ||
@@ -273,7 +269,7 @@ if __name__ == "__main__": | |||
273 | a['set2'].add("o2") | 269 | a['set2'].add("o2") |
274 | 270 | ||
275 | print("a", a) | 271 | print("a", a) |
276 | for x in a.iteritems(): | 272 | for x in a.items(): |
277 | print(x) | 273 | print(x) |
278 | print("--") | 274 | print("--") |
279 | print("b", b) | 275 | print("b", b) |
@@ -287,13 +283,13 @@ if __name__ == "__main__": | |||
287 | except KeyError: | 283 | except KeyError: |
288 | print("Yay! deleted key raises error") | 284 | print("Yay! deleted key raises error") |
289 | 285 | ||
290 | if b.has_key('b'): | 286 | if 'b' in b: |
291 | print("Boo!") | 287 | print("Boo!") |
292 | else: | 288 | else: |
293 | print("Yay - has_key with delete works!") | 289 | print("Yay - has_key with delete works!") |
294 | 290 | ||
295 | print("a", a) | 291 | print("a", a) |
296 | for x in a.iteritems(): | 292 | for x in a.items(): |
297 | print(x) | 293 | print(x) |
298 | print("--") | 294 | print("--") |
299 | print("b", b) | 295 | print("b", b) |
@@ -304,7 +300,7 @@ if __name__ == "__main__": | |||
304 | b.__revertitem__('b') | 300 | b.__revertitem__('b') |
305 | 301 | ||
306 | print("a", a) | 302 | print("a", a) |
307 | for x in a.iteritems(): | 303 | for x in a.items(): |
308 | print(x) | 304 | print(x) |
309 | print("--") | 305 | print("--") |
310 | print("b", b) | 306 | print("b", b) |
@@ -314,7 +310,7 @@ if __name__ == "__main__": | |||
314 | 310 | ||
315 | b.__revertitem__('dict') | 311 | b.__revertitem__('dict') |
316 | print("a", a) | 312 | print("a", a) |
317 | for x in a.iteritems(): | 313 | for x in a.items(): |
318 | print(x) | 314 | print(x) |
319 | print("--") | 315 | print("--") |
320 | print("b", b) | 316 | print("b", b) |