1 |
Author: zmedico |
2 |
Date: 2008-04-27 07:22:58 +0000 (Sun, 27 Apr 2008) |
3 |
New Revision: 9994 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/__init__.py |
7 |
Log: |
8 |
Take the classes that initialize variables in __slots__ with keyword |
9 |
constructor arguments and make them all derive from a new SlotObject |
10 |
class. |
11 |
|
12 |
|
13 |
Modified: main/trunk/pym/_emerge/__init__.py |
14 |
=================================================================== |
15 |
--- main/trunk/pym/_emerge/__init__.py 2008-04-27 06:38:37 UTC (rev 9993) |
16 |
+++ main/trunk/pym/_emerge/__init__.py 2008-04-27 07:22:58 UTC (rev 9994) |
17 |
@@ -829,15 +829,26 @@ |
18 |
else: |
19 |
yield flag |
20 |
|
21 |
-class AbstractDepPriority(object): |
22 |
- __slots__ = ("__weakref__", "buildtime", "runtime", "runtime_post") |
23 |
+class SlotObject(object): |
24 |
+ __slots__ = ("__weakref__") |
25 |
+ |
26 |
def __init__(self, **kwargs): |
27 |
- for myattr in chain(self.__slots__, AbstractDepPriority.__slots__): |
28 |
- if myattr == "__weakref__": |
29 |
+ classes = [self.__class__] |
30 |
+ while classes: |
31 |
+ c = classes.pop() |
32 |
+ if c is SlotObject: |
33 |
continue |
34 |
- myvalue = kwargs.get(myattr, False) |
35 |
- setattr(self, myattr, myvalue) |
36 |
+ classes.extend(c.__bases__) |
37 |
+ slots = getattr(c, "__slots__", None) |
38 |
+ if not slots: |
39 |
+ continue |
40 |
+ for myattr in slots: |
41 |
+ myvalue = kwargs.get(myattr, None) |
42 |
+ setattr(self, myattr, myvalue) |
43 |
|
44 |
+class AbstractDepPriority(SlotObject): |
45 |
+ __slots__ = ("buildtime", "runtime", "runtime_post") |
46 |
+ |
47 |
def __lt__(self, other): |
48 |
return self.__int__() < other |
49 |
|
50 |
@@ -1207,28 +1218,14 @@ |
51 |
shown_licenses.add(l) |
52 |
return have_eapi_mask |
53 |
|
54 |
-class Task(object): |
55 |
- __slots__ = ("__weakref__", "_hash_key",) |
56 |
+class Task(SlotObject): |
57 |
+ __slots__ = ("_hash_key",) |
58 |
|
59 |
- def __init__(self, **kwargs): |
60 |
- classes = [self.__class__] |
61 |
- while classes: |
62 |
- c = classes.pop() |
63 |
- if c is Task: |
64 |
- continue |
65 |
- classes.extend(c.__bases__) |
66 |
- slots = getattr(c, "__slots__", None) |
67 |
- if not slots: |
68 |
- continue |
69 |
- for myattr in slots: |
70 |
- myvalue = kwargs.get(myattr, None) |
71 |
- setattr(self, myattr, myvalue) |
72 |
- |
73 |
def _get_hash_key(self): |
74 |
- try: |
75 |
- return self._hash_key |
76 |
- except AttributeError: |
77 |
+ hash_key = getattr(self, "_hash_key", None) |
78 |
+ if hash_key is None: |
79 |
raise NotImplementedError(self) |
80 |
+ return hash_key |
81 |
|
82 |
def __eq__(self, other): |
83 |
return self._get_hash_key() == other |
84 |
@@ -1258,9 +1255,8 @@ |
85 |
__slots__ = ("root", "atom", "satisfied") |
86 |
|
87 |
def _get_hash_key(self): |
88 |
- try: |
89 |
- return self._hash_key |
90 |
- except AttributeError: |
91 |
+ hash_key = getattr(self, "_hash_key", None) |
92 |
+ if hash_key is None: |
93 |
self._hash_key = \ |
94 |
("blocks", self.root, self.atom) |
95 |
return self._hash_key |
96 |
@@ -1276,9 +1272,8 @@ |
97 |
self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"]) |
98 |
|
99 |
def _get_hash_key(self): |
100 |
- try: |
101 |
- return self._hash_key |
102 |
- except AttributeError: |
103 |
+ hash_key = getattr(self, "_hash_key", None) |
104 |
+ if hash_key is None: |
105 |
operation = "merge" |
106 |
if self.onlydeps or self.installed: |
107 |
operation = "nomerge" |
108 |
@@ -1307,9 +1302,8 @@ |
109 |
class Uninstall(Package): |
110 |
__slots__ = () |
111 |
def _get_hash_key(self): |
112 |
- try: |
113 |
- return self._hash_key |
114 |
- except AttributeError: |
115 |
+ hash_key = getattr(self, "_hash_key", None) |
116 |
+ if hash_key is None: |
117 |
self._hash_key = \ |
118 |
(self.type_name, self.root, self.cpv, "uninstall") |
119 |
return self._hash_key |
120 |
@@ -1341,16 +1335,11 @@ |
121 |
self.set = set |
122 |
self.name = self.arg[len(SETPREFIX):] |
123 |
|
124 |
-class Dependency(object): |
125 |
- __slots__ = ("__weakref__", "atom", "blocker", "depth", |
126 |
+class Dependency(SlotObject): |
127 |
+ __slots__ = ("atom", "blocker", "depth", |
128 |
"parent", "onlydeps", "priority", "root") |
129 |
def __init__(self, **kwargs): |
130 |
- for myattr in self.__slots__: |
131 |
- if myattr == "__weakref__": |
132 |
- continue |
133 |
- myvalue = kwargs.get(myattr, None) |
134 |
- setattr(self, myattr, myvalue) |
135 |
- |
136 |
+ SlotObject.__init__(self, **kwargs) |
137 |
if self.priority is None: |
138 |
self.priority = DepPriority() |
139 |
if self.depth is None: |
140 |
|
141 |
-- |
142 |
gentoo-commits@l.g.o mailing list |