Skip to content

Instantly share code, notes, and snippets.

@micaiahparker
Created March 5, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micaiahparker/1479b5da444cc8d629b2 to your computer and use it in GitHub Desktop.
Save micaiahparker/1479b5da444cc8d629b2 to your computer and use it in GitHub Desktop.
class Build:
tag = 'build'
known = {}
def __init__(self, xml):
self.name = ""
self.desc = ""
self.contents = {}
self.get_known()
self.build(xml)
def get_keys(self):
return self.__dict__.keys()
def set_value(self, key, value):
self.__setattr__(key, value)
def get_known(self):
if self.known == {}:
pass
def build(self, xml):
for attr in xml.attrib:
if attr in self.get_keys():
self.set_value(attr, xml.attrib[attr])
for child in xml.child:
self.add_item(child)
def add_item(self, item):
if item.tag in self.known:
content = self.make_item(item)
self.contents[content.name] = content
def make_item(self, item):
return self.known[item.tag](item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment