def get_tile(node, obj): a = node.childNodes[1] b = a.childNodes[1] #holds nothing c = b.attributes.items() id = node.attributes.items() tile_info = StorageClass() tup = [] for i in c: tup.append(i[1]) if len(tup) is 2: vars(tile_info)[str(tup[0])] = convert(tup[0]) tup = [] obj[convert(id[0][1])] = tile_info
def iterNodeVars(self, attr, namespace): if attr != None : for attr in attr.items(): k = str(attr[0]) v = convert(attr[1]) #print 'var', k,v vars(namespace)[k] = v
def spider(self, node, namespace, mapobj): if node != None: SpecialCaseFlag = None if node.hasChildNodes(): name = convert(node.localName) print 'in', namespace,' in node:', name #, namespace try: obj = self.function_map[name]() except KeyError: obj = self.function_map[FormatConstants.default]() if name == FormatConstants.layer: mapobj.layers.append(obj) elif name == FormatConstants.tileset: mapobj.tilesets[convert(node.getAttribute(FormatConstants.name))] = obj #special cases for dicts #generalise and combine these two elif name == FormatConstants.properties: SpecialCaseFlag = FormatConstants.properties #vars(namespace)[FormatConstants.properties] = obj if hasattr(namespace,FormatConstants.properties): obj = vars(namespace)[FormatConstants.properties] else: vars(namespace)[FormatConstants.properties] = obj elif name == FormatConstants.tile: SpecialCaseFlag = FormatConstants.tile #vars(namespace)[FormatConstants.tile] = obj #vars(namespace)[FormatConstants.properties] = obj #vars(namespace)["properties"] = obj if hasattr(namespace,FormatConstants.properties): obj = vars(namespace)[FormatConstants.properties] else: vars(namespace)[FormatConstants.properties] = obj else: ## Otherwise ## create a storage class of name [name] vars(namespace)[name] = obj if SpecialCaseFlag is None: namespace = obj if SpecialCaseFlag is None: self.NodeHasChild(node, namespace) for child in node.childNodes: self.spider(child, namespace, mapobj) child = child.nextSibling ##be very carefull adding special cases if (SpecialCaseFlag is FormatConstants.tile): def get_tile(node, obj): a = node.childNodes[1] b = a.childNodes[1] #holds nothing c = b.attributes.items() id = node.attributes.items() tile_info = StorageClass() tup = [] for i in c: tup.append(i[1]) if len(tup) is 2: vars(tile_info)[str(tup[0])] = convert(tup[0]) tup = [] obj[convert(id[0][1])] = tile_info get_tile(node, obj) elif (SpecialCaseFlag is FormatConstants.properties): def get_properties(node): if node.hasChildNodes(): for child in node.childNodes: if child.attributes is not None: tup = [] for i in child.attributes.items(): tup.append(i[1]) # attrubutes are in key value pairs so for 1 # key/value pair we need to do 2 iterations if len(tup) is 2: yield tup get_properties(node.nextSibling) for i in get_properties(node): obj[convert(i[0])] = convert(i[1])