diff options
Diffstat (limited to 'bitbake/lib/bb/COW.py')
-rw-r--r-- | bitbake/lib/bb/COW.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/bitbake/lib/bb/COW.py b/bitbake/lib/bb/COW.py index ca206cf4b4..224213db5c 100644 --- a/bitbake/lib/bb/COW.py +++ b/bitbake/lib/bb/COW.py | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | # This is a copy on write dictionary and set which abuses classes to try and be nice and fast. | 4 | # This is a copy on write dictionary and set which abuses classes to try and be nice and fast. |
5 | # | 5 | # |
6 | # Copyright (C) 2006 Tim Amsell | 6 | # Copyright (C) 2006 Tim Amsell |
7 | # | 7 | # |
8 | # This program is free software; you can redistribute it and/or modify | 8 | # This program is free software; you can redistribute it and/or modify |
9 | # it under the terms of the GNU General Public License version 2 as | 9 | # it under the terms of the GNU General Public License version 2 as |
@@ -18,7 +18,7 @@ | |||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 | # | 20 | # |
21 | #Please Note: | 21 | #Please Note: |
22 | # Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW. | 22 | # Be careful when using mutable types (ie Dict and Lists) - operations involving these are SLOW. |
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 | # |
@@ -40,7 +40,7 @@ MUTABLE = "__mutable__" | |||
40 | 40 | ||
41 | class COWMeta(type): | 41 | class COWMeta(type): |
42 | pass | 42 | pass |
43 | 43 | ||
44 | class COWDictMeta(COWMeta): | 44 | class COWDictMeta(COWMeta): |
45 | __warn__ = False | 45 | __warn__ = False |
46 | __hasmutable__ = False | 46 | __hasmutable__ = False |
@@ -64,7 +64,7 @@ class COWDictMeta(COWMeta): | |||
64 | cls.__hasmutable__ = True | 64 | cls.__hasmutable__ = True |
65 | key += MUTABLE | 65 | key += MUTABLE |
66 | setattr(cls, key, value) | 66 | setattr(cls, key, value) |
67 | 67 | ||
68 | def __getmutable__(cls, key, readonly=False): | 68 | def __getmutable__(cls, key, readonly=False): |
69 | nkey = key + MUTABLE | 69 | nkey = key + MUTABLE |
70 | try: | 70 | try: |
@@ -98,8 +98,8 @@ class COWDictMeta(COWMeta): | |||
98 | value = getattr(cls, key) | 98 | value = getattr(cls, key) |
99 | except AttributeError: | 99 | except AttributeError: |
100 | value = cls.__getmutable__(key, readonly) | 100 | value = cls.__getmutable__(key, readonly) |
101 | 101 | ||
102 | # This is for values which have been deleted | 102 | # This is for values which have been deleted |
103 | if value is cls.__marker__: | 103 | if value is cls.__marker__: |
104 | raise AttributeError("key %s does not exist." % key) | 104 | raise AttributeError("key %s does not exist." % key) |
105 | 105 | ||
@@ -127,7 +127,7 @@ class COWDictMeta(COWMeta): | |||
127 | def iter(cls, type, readonly=False): | 127 | def iter(cls, type, readonly=False): |
128 | for key in dir(cls): | 128 | for key in dir(cls): |
129 | if key.startswith("__"): | 129 | if key.startswith("__"): |
130 | continue | 130 | continue |
131 | 131 | ||
132 | if key.endswith(MUTABLE): | 132 | if key.endswith(MUTABLE): |
133 | key = key[:-len(MUTABLE)] | 133 | key = key[:-len(MUTABLE)] |
@@ -176,13 +176,13 @@ class COWSetMeta(COWDictMeta): | |||
176 | 176 | ||
177 | def remove(cls, value): | 177 | def remove(cls, value): |
178 | COWDictMeta.__delitem__(cls, repr(hash(value))) | 178 | COWDictMeta.__delitem__(cls, repr(hash(value))) |
179 | 179 | ||
180 | def __in__(cls, value): | 180 | def __in__(cls, value): |
181 | return COWDictMeta.has_key(repr(hash(value))) | 181 | return COWDictMeta.has_key(repr(hash(value))) |
182 | 182 | ||
183 | def iterkeys(cls): | 183 | def iterkeys(cls): |
184 | raise TypeError("sets don't have keys") | 184 | raise TypeError("sets don't have keys") |
185 | 185 | ||
186 | def iteritems(cls): | 186 | def iteritems(cls): |
187 | raise TypeError("sets don't have 'items'") | 187 | raise TypeError("sets don't have 'items'") |
188 | 188 | ||
@@ -286,7 +286,7 @@ if __name__ == "__main__": | |||
286 | print "Boo!" | 286 | print "Boo!" |
287 | else: | 287 | else: |
288 | print "Yay - has_key with delete works!" | 288 | print "Yay - has_key with delete works!" |
289 | 289 | ||
290 | print "a", a | 290 | print "a", a |
291 | for x in a.iteritems(): | 291 | for x in a.iteritems(): |
292 | print x | 292 | print x |