Changeset 2684
- Timestamp:
- 02/07/07 15:49:30 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/parser.py
r2683 r2684 56 56 ''' merges (adds) dictionary to existing self.CHILDREN dictionary ''' 57 57 dict1 = dict 58 if hasattr(obj, 'CHILDREN'):58 if 'CHILDREN' in obj.__dict__: 59 59 dict2=obj.CHILDREN 60 60 else: … … 70 70 def addatts(obj, atts): 71 71 ''' merges self.ATTRIBUTES of inherited classes''' 72 if hasattr(obj, 'ATTRIBUTES'):72 if 'ATTRIBUTES' in obj.__dict__: 73 73 for att in atts: 74 74 obj.ATTRIBUTES.append(att) … … 81 81 def addelems(obj, elems): 82 82 ''' merges self.elems of inherited classes''' 83 if hasattr(obj, 'ELEMORDER'):83 if 'ELEMORDER' in obj.__dict__: 84 84 for elem in elems: 85 85 obj.ELEMORDER.append(elem) … … 90 90 #Some variable definitions: these things are often repeated so store in variables. 91 91 FILEFORMATS=[CSML('NetCDFExtract'),CSML('NASAAmesExtract'), CSML('GRIBExtract'),CSML('CDMLExtract'), CSML('RawFileExtract'), CSML('ImageFileExtract'), CSML('AggregatedArray')] 92 93 92 94 93 class csElement(object): … … 112 111 113 112 def __setattr__(self, name, value): 114 if hasattr(self, CSML(name)):113 if CSML(name) in self.__dict__: 115 114 object.__setattr__(self, CSML(name), value) 116 115 object.__setattr__(self, name, value) 117 elif hasattr(self,GML(name)):116 elif GML(name) in self.__dict__: 118 117 object.__setattr__(self, GML(name), value) 119 118 object.__setattr__(self, name, value) 120 elif hasattr(self,XLINK(name)):119 elif XLINK(name) in self.__dict__: 121 120 object.__setattr__(self, XLINK(name), value) 122 object.__setattr__(self, name, value) 121 object.__setattr__(self, name, value) 123 122 else: 124 if hasattr(self, 'ATTRIBUTES'):123 if 'ATTRIBUTES' in self.__dict__: 125 124 if CSML(name) in self.__dict__['ATTRIBUTES']: 126 125 object.__setattr__(self, CSML(name), value) … … 173 172 def addChildElem(self, childname, childobj): 174 173 #sometimes you want to add a child element but don't know if there is one already. In which case you want to create a list of child objects. 175 if hasattr(self, childname):174 if childname in self.__dict__: 176 175 currentattribute=getattr(self,childname) 177 176 if type(getattr(self,childname)) is list: … … 186 185 def toXML(self, csmlfrag, **kwargs): 187 186 #process self and convert to XML 188 if hasattr(self, 'CONTENT'):187 if 'CONTENT' in self.__dict__: 189 188 if self.CONTENT is not None: csmlfrag.text=self.CONTENT 190 if hasattr(self, 'ATTRIBUTES'):189 if 'ATTRIBUTES' in self.__dict__: 191 190 for item in self.__dict__: 192 191 if item in self.ATTRIBUTES: … … 277 276 childobj.fromXML(frag) 278 277 #set this object to be an attribute of the 'parent' (self) object 279 if hasattr(self, child):278 if child in self.__dict__: 280 279 if type(self.__dict__[child]) is not list: 281 280 tmp=self.__dict__[child] … … 300 299 301 300 #set this object to be an attribute of the 'parent' (self) object 302 if hasattr(self, child):301 if child in self.__dict__: 303 302 if type(self.__dict__[child]) is not list: 304 303 tmp=self.__dict__[child]
Note: See TracChangeset
for help on using the changeset viewer.