| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,11 +5,10 @@ | |||
| 5 | 5 | A class which defines a composite object which can store | |
| 6 | 6 | hieararchical dictionaries with names. | |
| 7 | 7 | ||
| 8 | - This class is same as a hiearchical dictionary, but it | ||
| 9 | - provides methods to add/access/modify children by name, | ||
| 10 | - like a Composite. | ||
| 8 | + This class is same as a hiearchical dictionary, but it provides methods | ||
| 9 | + to add/access/modify children by name, like a Composite. | ||
| 11 | 10 | ||
| 12 | - Created Anand B Pillai <abpillai@gmail.com> | ||
| 11 | + Created Anand B Pillai <abpillai@gmail.com> | ||
| 13 | 12 | ||
| 14 | 13 | """ | |
| 15 | 14 | __author__ = "Anand B Pillai" | |
@@ -18,8 +17,10 @@ | |||
| 18 | 17 | ||
| 19 | 18 | ||
| 20 | 19 | def normalize(val): | |
| 21 | - """ Normalize a string so that it can be used as an attribute | ||
| 22 | - to a Python object """ | ||
| 20 | + """Normalize a string so that it can be used as an attribute to a Python | ||
| 21 | + | ||
| 22 | + object | ||
| 23 | + """ | ||
| 23 | 24 | ||
| 24 | 25 | if val.find('-') != -1: | |
| 25 | 26 | val = val.replace('-', '_') | |
@@ -38,8 +39,7 @@ def denormalize(val): | |||
| 38 | 39 | ||
| 39 | 40 | class SpecialDict(dict): | |
| 40 | 41 | ||
| 41 | - """ A dictionary type which allows direct attribute | ||
| 42 | - access to its keys """ | ||
| 42 | + """A dictionary type which allows direct attribute access to its keys """ | ||
| 43 | 43 | ||
| 44 | 44 | def __getattr__(self, name): | |
| 45 | 45 | ||
@@ -127,11 +127,13 @@ def isLeaf(self): | |||
| 127 | 127 | return not self._children | |
| 128 | 128 | ||
| 129 | 129 | def getName(self): | |
| 130 | + | ||
| 130 | 131 | """ Return the name of this ConfigInfo object """ | |
| 131 | 132 | ||
| 132 | 133 | return self._name | |
| 133 | 134 | ||
| 134 | 135 | def getIndex(self, child): | |
| 136 | + | ||
| 135 | 137 | """ Return the index of the child ConfigInfo object 'child' """ | |
| 136 | 138 | ||
| 137 | 139 | if child in self._children: | |
@@ -145,29 +147,31 @@ def getDict(self): | |||
| 145 | 147 | return self[self._name] | |
| 146 | 148 | ||
| 147 | 149 | def getProperty(self, child, key): | |
| 148 | - """ Return the value for the property for child | ||
| 149 | - 'child' with key 'key' """ | ||
| 150 | + | ||
| 151 | + """Return the value for the property for child 'child' with key 'key' """ | ||
| 150 | 152 | ||
| 151 | 153 | # First get the child's dictionary | |
| 152 | 154 | childDict = self.getInfoDict(child) | |
| 153 | 155 | if childDict: | |
| 154 | 156 | return childDict.get(key, None) | |
| 155 | 157 | ||
| 156 | - def setProperty(self, child, key, value): | ||
| 157 | - """ Set the value for the property 'key' for | ||
| 158 | - the child 'child' to 'value' """ | ||
| 158 | + def setProperty(self, child, key, value): | ||
| 159 | + | ||
| 160 | + """Set the value for the property 'key' for the child 'child' to 'value' """ | ||
| 159 | 161 | ||
| 160 | 162 | # First get the child's dictionary | |
| 161 | 163 | childDict = self.getInfoDict(child) | |
| 162 | 164 | if childDict: | |
| 163 | 165 | childDict[key] = value | |
| 164 | 166 | ||
| 165 | 167 | def getChildren(self): | |
| 168 | + | ||
| 166 | 169 | """ Return the list of immediate children of this object """ | |
| 167 | 170 | ||
| 168 | 171 | return self._children | |
| 169 | 172 | ||
| 170 | 173 | def getAllChildren(self): | |
| 174 | + | ||
| 171 | 175 | """ Return the list of all children of this object """ | |
| 172 | 176 | ||
| 173 | 177 | l = [] | |
@@ -178,13 +182,15 @@ def getAllChildren(self): | |||
| 178 | 182 | return l | |
| 179 | 183 | ||
| 180 | 184 | def getChild(self, name): | |
| 185 | + | ||
| 181 | 186 | """ Return the immediate child object with the given name """ | |
| 182 | 187 | ||
| 183 | 188 | for child in self._children: | |
| 184 | 189 | if child.getName() == name: | |
| 185 | 190 | return child | |
| 186 | 191 | ||
| 187 | 192 | def findChild(self, name): | |
| 193 | + | ||
| 188 | 194 | """ Return the child with the given name from the tree """ | |
| 189 | 195 | ||
| 190 | 196 | # Note - this returns the first child of the given name | |
@@ -196,6 +202,7 @@ def findChild(self, name): | |||
| 196 | 202 | return child | |
| 197 | 203 | ||
| 198 | 204 | def findChildren(self, name): | |
| 205 | + | ||
| 199 | 206 | """ Return a list of children with the given name from the tree """ | |
| 200 | 207 | ||
| 201 | 208 | # Note: this returns a list of all the children of a given | |
@@ -210,6 +217,7 @@ def findChildren(self, name): | |||
| 210 | 217 | return children | |
| 211 | 218 | ||
| 212 | 219 | def getPropertyDict(self): | |
| 220 | + | ||
| 213 | 221 | """ Return the property dictionary """ | |
| 214 | 222 | ||
| 215 | 223 | d = self.getChild('__properties') | |
@@ -219,6 +227,7 @@ def getPropertyDict(self): | |||
| 219 | 227 | return {} | |
| 220 | 228 | ||
| 221 | 229 | def getParent(self): | |
| 230 | + | ||
| 222 | 231 | """ Return the person who created me """ | |
| 223 | 232 | ||
| 224 | 233 | return self._father | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,8 @@ | |||
| 10 | 10 | class Provider: | |
| 11 | 11 | ||
| 12 | 12 | def __init__(self): | |
| 13 | - self.msg_queue = [] | ||
| 14 | - self.subscribers = {} | ||
| 15 | - | ||
| 13 | + self.subscribe_queue = {} | ||
| 14 | + self.msg_queue=[] | ||
| 16 | 15 | def notify(self, msg): | |
| 17 | 16 | self.msg_queue.append(msg) | |
| 18 | 17 | ||
@@ -25,12 +24,14 @@ def subscribe(self, msg, subscriber): | |||
| 25 | 24 | ||
| 26 | 25 | def unsubscribe(self, msg, subscriber): | |
| 27 | 26 | self.subscribers[msg].remove(subscriber) | |
| 27 | + if !self.subscribe[msg]: | ||
| 28 | + del self.subscribe[msg] | ||
| 28 | 29 | ||
| 29 | 30 | def update(self): | |
| 30 | 31 | for msg in self.msg_queue: | |
| 31 | - if msg in self.subscribers: | ||
| 32 | - for sub in self.subscribers[msg]: | ||
| 33 | - sub.run(msg) | ||
| 32 | + if msg in self.subscribers.keys(): | ||
| 33 | + for suber in self.subscribers[msg]: | ||
| 34 | + suber.get(msg) | ||
| 34 | 35 | self.msg_queue = [] | |
| 35 | 36 | ||
| 36 | 37 | ||
@@ -52,7 +53,7 @@ def __init__(self, name, msg_center): | |||
| 52 | 53 | def subscribe(self, msg): | |
| 53 | 54 | self.provider.subscribe(msg, self) | |
| 54 | 55 | ||
| 55 | - def run(self, msg): | ||
| 56 | + def get(self, msg): | ||
| 56 | 57 | print("{} got {}".format(self.name, msg)) | |
| 57 | 58 | ||
| 58 | 59 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments