forked from faif/python-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
56 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,10 @@ | |
A class which defines a composite object which can store | ||
hieararchical dictionaries with names. | ||
This class is same as a hiearchical dictionary, but it | ||
provides methods to add/access/modify children by name, | ||
like a Composite. | ||
This class is same as a hiearchical dictionary, but it provides methods | ||
to add/access/modify children by name, like a Composite. | ||
Created Anand B Pillai <[email protected]> | ||
Created Anand B Pillai <[email protected]> | ||
""" | ||
__author__ = "Anand B Pillai" | ||
|
@@ -18,8 +17,10 @@ | |
|
||
|
||
def normalize(val): | ||
""" Normalize a string so that it can be used as an attribute | ||
to a Python object """ | ||
"""Normalize a string so that it can be used as an attribute to a Python | ||
object | ||
""" | ||
|
||
if val.find('-') != -1: | ||
val = val.replace('-', '_') | ||
|
@@ -38,8 +39,7 @@ def denormalize(val): | |
|
||
class SpecialDict(dict): | ||
|
||
""" A dictionary type which allows direct attribute | ||
access to its keys """ | ||
"""A dictionary type which allows direct attribute access to its keys """ | ||
|
||
def __getattr__(self, name): | ||
|
||
|
@@ -127,11 +127,13 @@ def isLeaf(self): | |
return not self._children | ||
|
||
def getName(self): | ||
|
||
""" Return the name of this ConfigInfo object """ | ||
|
||
return self._name | ||
|
||
def getIndex(self, child): | ||
|
||
""" Return the index of the child ConfigInfo object 'child' """ | ||
|
||
if child in self._children: | ||
|
@@ -145,29 +147,31 @@ def getDict(self): | |
return self[self._name] | ||
|
||
def getProperty(self, child, key): | ||
""" Return the value for the property for child | ||
'child' with key 'key' """ | ||
|
||
"""Return the value for the property for child 'child' with key 'key' """ | ||
|
||
# First get the child's dictionary | ||
childDict = self.getInfoDict(child) | ||
if childDict: | ||
return childDict.get(key, None) | ||
|
||
def setProperty(self, child, key, value): | ||
""" Set the value for the property 'key' for | ||
the child 'child' to 'value' """ | ||
def setProperty(self, child, key, value): | ||
"""Set the value for the property 'key' for the child 'child' to 'value' """ | ||
|
||
# First get the child's dictionary | ||
childDict = self.getInfoDict(child) | ||
if childDict: | ||
childDict[key] = value | ||
|
||
def getChildren(self): | ||
|
||
""" Return the list of immediate children of this object """ | ||
|
||
return self._children | ||
|
||
def getAllChildren(self): | ||
|
||
""" Return the list of all children of this object """ | ||
|
||
l = [] | ||
|
@@ -178,13 +182,15 @@ def getAllChildren(self): | |
return l | ||
|
||
def getChild(self, name): | ||
|
||
""" Return the immediate child object with the given name """ | ||
|
||
for child in self._children: | ||
if child.getName() == name: | ||
return child | ||
|
||
def findChild(self, name): | ||
|
||
""" Return the child with the given name from the tree """ | ||
|
||
# Note - this returns the first child of the given name | ||
|
@@ -196,6 +202,7 @@ def findChild(self, name): | |
return child | ||
|
||
def findChildren(self, name): | ||
|
||
""" Return a list of children with the given name from the tree """ | ||
|
||
# Note: this returns a list of all the children of a given | ||
|
@@ -210,6 +217,7 @@ def findChildren(self, name): | |
return children | ||
|
||
def getPropertyDict(self): | ||
|
||
""" Return the property dictionary """ | ||
|
||
d = self.getChild('__properties') | ||
|
@@ -219,6 +227,7 @@ def getPropertyDict(self): | |
return {} | ||
|
||
def getParent(self): | ||
|
||
""" Return the person who created me """ | ||
|
||
return self._father | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.