00001 class Node(object): 00002 def __init__( self ): 00003 """__init__ 00004 """ 00005 self.__dict__.setdefault('nodeid',0) 00006 self.__dict__.setdefault('nodelabel','ROOT') 00007 self.__dict__.setdefault('lft',0) 00008 self.__dict__.setdefault('rgt',0) 00009 self.__dict__.setdefault('parentid',0) 00010 self.__dict__.setdefault('globalsince',0) 00011 self.__dict__.setdefault('globaltill',0) 00012 self.__dict__.setdefault('tagid',0) 00013 def __repr__( self ): 00014 """__repr__ 00015 """ 00016 return self.__dict__.__repr__() 00017 def __setattr__( self, name, value ): 00018 if not name in self.__dict__: 00019 raise AttributeError("Unknown attribute "+name) 00020 self.__dict__[name]=value 00021 def __getattr__( self, name ): 00022 if not name in self.__dict__: 00023 raise AttributeError("Unknown attribute "+name) 00024 return self.__dict__[name] 00025 def empty( self ): 00026 if self.__dict__['nodelabel']=='': 00027 return True 00028 return False 00029 class LeafNode(Node): 00030 """The leaf node 00031 """ 00032 def __init__( self ): 00033 """__init__ 00034 """ 00035 super(Node,self).__init__() 00036 super(Node,self).__setattr__( 'tagid',0 ) 00037 self.__dict__.setdefault('tagname','') 00038 #self.__dict__.setdefault('tagid',0) 00039 self.__dict__.setdefault('pfn','') 00040 self.__dict__.setdefault('recordname','') 00041 self.__dict__.setdefault('objectname','') 00042 self.__dict__.setdefault('labelname','') 00043 def __repr__( self ): 00044 """__repr__ 00045 """ 00046 if self.tagname=='': 00047 return '' 00048 return self.__dict__.__repr__() 00049 if __name__ == "__main__": 00050 node=Node() 00051 node.nodeid=1 00052 print node.nodeid 00053 print node.nodelabel 00054 print node.lft 00055 try: 00056 node.foreign='a' 00057 except AttributeError: 00058 print 'caught right exception' 00059 except Exception, er: 00060 print 'unexpected error' 00061 print str(er) 00062 leaf=LeafNode() 00063 print leaf.__class__.__name__,'isLeaf',str(leaf.tagid) 00064 print node.__class__.__name__,'isLeaf',str(node.tagid)