def __init__(self, x): self.name = x.name.upper() try: self.settings = [Setting(self.name, s) for s in xmlobject.ensure_list(x.setting)] except AttributeError: self.settings = []
def __init__(self, m, field_klass, **field_kwargs): self._field_kwargs = field_kwargs self.name = m.name.upper() if int(m.id) <= 255 and int(m.id) > 0: self.id = int(m.id) else: raise Exception("Message IDs must be 0 > ID <= 255") try: self.fields = [field_klass(f, **self._field_kwargs) for f in xmlobject.ensure_list(m.field)] except AttributeError: self.fields = [] try: self.is_command = m.command == "1" except AttributeError: self.is_command = False self.size = 0 self.num_values = 0 for f in self.fields: self.size += f.length self.num_values += f.num_elements self.num_fields = len(self.fields)
def __init__(self, **kwargs): """ **Keywords:** - debug - should extra information be printed while parsing *messages.xml* - path - a pathname from which the file can be read - file - an open file object from which the raw xml can be read - raw - the raw xml itself - root - name of root tag, if not reading content """ self._debug = kwargs.get("debug", False) path = kwargs.get("path") if path and not os.path.exists(path): raise Exception("Could not find message file") try: # Must have >= 1 message element messages = xmlobject.XMLFile(**kwargs).root.message self._messages = xmlobject.ensure_list(messages) except AttributeError: raise Exception("Error parsing messages") self._msgs_by_id = {} self._msgs_by_name = {}
def __init__(self, m, field_klass, **field_kwargs): self._field_kwargs = field_kwargs self.name = m.name.upper() if int(m.id) <= 255 and int(m.id) > 0: self.id = int(m.id) else: raise Exception("Message IDs must be 0 > ID <= 255") try: self.fields = [ field_klass(f, **self._field_kwargs) for f in xmlobject.ensure_list(m.field) ] except AttributeError: self.fields = [] try: self.is_command = m.command == "1" except AttributeError: self.is_command = False try: self.doc = m.doc except AttributeError: self.doc = "" self.size = 0 self.num_values = 0 for f in self.fields: self.size += f.length self.num_values += f.num_elements self.num_fields = len(self.fields)
def __init__(self, **kwargs): """ **Keywords:** - debug - should extra information be printed while parsing *messages.xml* - path - a pathname from which the file can be read - file - an open file object from which the raw xml can be read - raw - the raw xml itself - root - name of root tag, if not reading content """ self._debug = kwargs.get("debug", False) path = kwargs.get("path") if path and not os.path.exists(path): raise Exception("Could not find message file") try: root = xmlobject.XMLFile(**kwargs).root except AttributeError: raise Exception("Invalid XML") try: #Must have >= 1 message element self._messages = xmlobject.ensure_list( root.message ) except AttributeError: raise Exception("Missing <message> elements") self._values = {} try: for v in xmlobject.ensure_list( root.value ): if v.name in self._values: raise Exception("Duplicate <value> element") self._values[v.name] = v.values.split("|") except AttributeError: #Values are optional (at this stage of parsing) pass self._msgs_by_id = {} self._msgs_by_name = {}
def __init__(self, **kwargs): """ **Keywords:** - debug - should extra information be printed while parsing *messages.xml* - path - a pathname from which the file can be read - file - an open file object from which the raw xml can be read - raw - the raw xml itself - root - name of root tag, if not reading content """ self._debug = kwargs.get("debug", False) path = kwargs.get("path") if path and not os.path.exists(path): raise Exception("Could not find message file") try: root = xmlobject.XMLFile(**kwargs).root except AttributeError: raise Exception("Invalid XML") try: #Must have >= 1 message element self._messages = xmlobject.ensure_list(root.message) except AttributeError: raise Exception("Missing <message> elements") self._values = {} try: for v in xmlobject.ensure_list(root.value): if v.name in self._values: raise Exception("Duplicate <value> element") self._values[v.name] = v.values.split("|") except AttributeError: #Values are optional (at this stage of parsing) pass self._msgs_by_id = {} self._msgs_by_name = {}
def __init__(self, **kwargs): """ **Keywords:** - debug - should extra information be printed while parsing *messages.xml* - path - a pathname from which the file can be read - file - an open file object from which the raw xml can be read - raw - the raw xml itself - root - name of root tag, if not reading content """ self._debug = kwargs.get("debug", False) path = kwargs.get("path") if path and not os.path.exists(path): raise Exception("Could not find settings file") self.all_settings = [] self.all_sections = [] self.settible = [] self.gettible = [] self._settings_by_name = {} self._settings_by_id = {} try: x = xmlobject.XMLFile(**kwargs) self.all_sections = [Section(s) for s in xmlobject.ensure_list(x.root.section)] i = 1 for sect in self.all_sections: for s in sect.settings: self.all_settings.append(s) self._settings_by_name[s.name] = s self._settings_by_id[s.id] = s if s.set: self.settible.append(s) if s.get: self.gettible.append(s) if s.dynamic: s.set_id(i) i += 1 except: raise Exception("Could not parse settings file")