diff options
Diffstat (limited to 'bitbake/lib/bb/COW.py')
| -rw-r--r-- | bitbake/lib/bb/COW.py | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/bitbake/lib/bb/COW.py b/bitbake/lib/bb/COW.py index 224213db5c..b0afb5fa08 100644 --- a/bitbake/lib/bb/COW.py +++ b/bitbake/lib/bb/COW.py | |||
| @@ -23,6 +23,7 @@ | |||
| 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 | import copy | 27 | import copy |
| 27 | import types | 28 | import types |
| 28 | types.ImmutableTypes = tuple([ \ | 29 | types.ImmutableTypes = tuple([ \ |
| @@ -77,7 +78,7 @@ class COWDictMeta(COWMeta): | |||
| 77 | return value | 78 | return value |
| 78 | 79 | ||
| 79 | if not cls.__warn__ is False and not isinstance(value, COWMeta): | 80 | if not cls.__warn__ is False and not isinstance(value, COWMeta): |
| 80 | print >> cls.__warn__, "Warning: Doing a copy because %s is a mutable type." % key | 81 | print("Warning: Doing a copy because %s is a mutable type." % key, file=cls.__warn__) |
| 81 | try: | 82 | try: |
| 82 | value = value.copy() | 83 | value = value.copy() |
| 83 | except AttributeError, e: | 84 | except AttributeError, e: |
| @@ -153,11 +154,11 @@ class COWDictMeta(COWMeta): | |||
| 153 | return cls.iter("keys") | 154 | return cls.iter("keys") |
| 154 | def itervalues(cls, readonly=False): | 155 | def itervalues(cls, readonly=False): |
| 155 | if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: | 156 | if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: |
| 156 | print >> cls.__warn__, "Warning: If you arn't going to change any of the values call with True." | 157 | print("Warning: If you arn't going to change any of the values call with True.", file=cls.__warn__) |
| 157 | return cls.iter("values", readonly) | 158 | return cls.iter("values", readonly) |
| 158 | def iteritems(cls, readonly=False): | 159 | def iteritems(cls, readonly=False): |
| 159 | if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: | 160 | if not cls.__warn__ is False and cls.__hasmutable__ and readonly is False: |
| 160 | print >> cls.__warn__, "Warning: If you arn't going to change any of the values call with True." | 161 | print("Warning: If you arn't going to change any of the values call with True.", file=cls.__warn__) |
| 161 | return cls.iter("items", readonly) | 162 | return cls.iter("items", readonly) |
| 162 | 163 | ||
| 163 | class COWSetMeta(COWDictMeta): | 164 | class COWSetMeta(COWDictMeta): |
| @@ -199,120 +200,120 @@ if __name__ == "__main__": | |||
| 199 | import sys | 200 | import sys |
| 200 | COWDictBase.__warn__ = sys.stderr | 201 | COWDictBase.__warn__ = sys.stderr |
| 201 | a = COWDictBase() | 202 | a = COWDictBase() |
| 202 | print "a", a | 203 | print("a", a) |
| 203 | 204 | ||
| 204 | a['a'] = 'a' | 205 | a['a'] = 'a' |
| 205 | a['b'] = 'b' | 206 | a['b'] = 'b' |
| 206 | a['dict'] = {} | 207 | a['dict'] = {} |
| 207 | 208 | ||
| 208 | b = a.copy() | 209 | b = a.copy() |
| 209 | print "b", b | 210 | print("b", b) |
| 210 | b['c'] = 'b' | 211 | b['c'] = 'b' |
| 211 | 212 | ||
| 212 | 213 | print() | |
| 213 | 214 | ||
| 214 | print "a", a | 215 | print("a", a) |
| 215 | for x in a.iteritems(): | 216 | for x in a.iteritems(): |
| 216 | print x | 217 | print(x) |
| 217 | print "--" | 218 | print("--") |
| 218 | print "b", b | 219 | print("b", b) |
| 219 | for x in b.iteritems(): | 220 | for x in b.iteritems(): |
| 220 | print x | 221 | print(x) |
| 221 | 222 | print() | |
| 222 | 223 | ||
| 223 | b['dict']['a'] = 'b' | 224 | b['dict']['a'] = 'b' |
| 224 | b['a'] = 'c' | 225 | b['a'] = 'c' |
| 225 | 226 | ||
| 226 | print "a", a | 227 | print("a", a) |
| 227 | for x in a.iteritems(): | 228 | for x in a.iteritems(): |
| 228 | print x | 229 | print(x) |
| 229 | print "--" | 230 | print("--") |
| 230 | print "b", b | 231 | print("b", b) |
| 231 | for x in b.iteritems(): | 232 | for x in b.iteritems(): |
| 232 | print x | 233 | print(x) |
| 233 | 234 | print() | |
| 234 | 235 | ||
| 235 | try: | 236 | try: |
| 236 | b['dict2'] | 237 | b['dict2'] |
| 237 | except KeyError, e: | 238 | except KeyError, e: |
| 238 | print "Okay!" | 239 | print("Okay!") |
| 239 | 240 | ||
| 240 | a['set'] = COWSetBase() | 241 | a['set'] = COWSetBase() |
| 241 | a['set'].add("o1") | 242 | a['set'].add("o1") |
| 242 | a['set'].add("o1") | 243 | a['set'].add("o1") |
| 243 | a['set'].add("o2") | 244 | a['set'].add("o2") |
| 244 | 245 | ||
| 245 | print "a", a | 246 | print("a", a) |
| 246 | for x in a['set'].itervalues(): | 247 | for x in a['set'].itervalues(): |
| 247 | print x | 248 | print(x) |
| 248 | print "--" | 249 | print("--") |
| 249 | print "b", b | 250 | print("b", b) |
| 250 | for x in b['set'].itervalues(): | 251 | for x in b['set'].itervalues(): |
| 251 | print x | 252 | print(x) |
| 252 | 253 | print() | |
| 253 | 254 | ||
| 254 | b['set'].add('o3') | 255 | b['set'].add('o3') |
| 255 | 256 | ||
| 256 | print "a", a | 257 | print("a", a) |
| 257 | for x in a['set'].itervalues(): | 258 | for x in a['set'].itervalues(): |
| 258 | print x | 259 | print(x) |
| 259 | print "--" | 260 | print("--") |
| 260 | print "b", b | 261 | print("b", b) |
| 261 | for x in b['set'].itervalues(): | 262 | for x in b['set'].itervalues(): |
| 262 | print x | 263 | print(x) |
| 263 | 264 | print() | |
| 264 | 265 | ||
| 265 | a['set2'] = set() | 266 | a['set2'] = set() |
| 266 | a['set2'].add("o1") | 267 | a['set2'].add("o1") |
| 267 | a['set2'].add("o1") | 268 | a['set2'].add("o1") |
| 268 | a['set2'].add("o2") | 269 | a['set2'].add("o2") |
| 269 | 270 | ||
| 270 | print "a", a | 271 | print("a", a) |
| 271 | for x in a.iteritems(): | 272 | for x in a.iteritems(): |
| 272 | print x | 273 | print(x) |
| 273 | print "--" | 274 | print("--") |
| 274 | print "b", b | 275 | print("b", b) |
| 275 | for x in b.iteritems(readonly=True): | 276 | for x in b.iteritems(readonly=True): |
| 276 | print x | 277 | print(x) |
| 277 | 278 | print() | |
| 278 | 279 | ||
| 279 | del b['b'] | 280 | del b['b'] |
| 280 | try: | 281 | try: |
| 281 | print b['b'] | 282 | print(b['b']) |
| 282 | except KeyError: | 283 | except KeyError: |
| 283 | print "Yay! deleted key raises error" | 284 | print("Yay! deleted key raises error") |
| 284 | 285 | ||
| 285 | if b.has_key('b'): | 286 | if b.has_key('b'): |
| 286 | print "Boo!" | 287 | print("Boo!") |
| 287 | else: | 288 | else: |
| 288 | print "Yay - has_key with delete works!" | 289 | print("Yay - has_key with delete works!") |
| 289 | 290 | ||
| 290 | print "a", a | 291 | print("a", a) |
| 291 | for x in a.iteritems(): | 292 | for x in a.iteritems(): |
| 292 | print x | 293 | print(x) |
| 293 | print "--" | 294 | print("--") |
| 294 | print "b", b | 295 | print("b", b) |
| 295 | for x in b.iteritems(readonly=True): | 296 | for x in b.iteritems(readonly=True): |
| 296 | print x | 297 | print(x) |
| 297 | 298 | print() | |
| 298 | 299 | ||
| 299 | b.__revertitem__('b') | 300 | b.__revertitem__('b') |
| 300 | 301 | ||
| 301 | print "a", a | 302 | print("a", a) |
| 302 | for x in a.iteritems(): | 303 | for x in a.iteritems(): |
| 303 | print x | 304 | print(x) |
| 304 | print "--" | 305 | print("--") |
| 305 | print "b", b | 306 | print("b", b) |
| 306 | for x in b.iteritems(readonly=True): | 307 | for x in b.iteritems(readonly=True): |
| 307 | print x | 308 | print(x) |
| 308 | 309 | print() | |
| 309 | 310 | ||
| 310 | b.__revertitem__('dict') | 311 | b.__revertitem__('dict') |
| 311 | print "a", a | 312 | print("a", a) |
| 312 | for x in a.iteritems(): | 313 | for x in a.iteritems(): |
| 313 | print x | 314 | print(x) |
| 314 | print "--" | 315 | print("--") |
| 315 | print "b", b | 316 | print("b", b) |
| 316 | for x in b.iteritems(readonly=True): | 317 | for x in b.iteritems(readonly=True): |
| 317 | print x | 318 | print(x) |
| 318 | 319 | print() | |
