def next(self): """Return the next DataOU object. Returns a ABCTypesError exception if object has errors in types. These objects should be skipped. Consume the next XML-element describing an organization, and return a suitable representation (DataOU). """ # This call with propagate StopIteration when all the (XML) elements # are exhausted. element = super(XMLOrg2Object, self).next() result = DataOU() # Iterate over *all* subelements for sub in element: value = None if sub.text: value = sub.text.strip().encode("latin1") if sub.tag == "orgid": if len(sub.attrib) != 1: raise ABCTypesError, "wrong number of arguments: %s" % value type = sub.attrib.get("orgidtype") result.add_id(ABCTypes.get_type("orgidtype", (type, )), value) elif sub.tag == "orgname": if len(sub.attrib) != 2: raise ABCTypesError, "not 2 attributes: %s" % value type = sub.attrib.get("orgnametype") # TODO: support lang lang = sub.attrib.get("lang") result.add_name(ABCTypes.get_type("orgnametype", (type, )), value) elif sub.tag == "realm": result.realm = value elif sub.tag == "address": if len(sub.attrib) != 1: raise ABCTypesError, "error in address: %s" % value type = sub.attrib.get("addresstype") addr_type = ABCTypes.get_type("addresstype", ("organization", type)) result.add_address(addr_type, self._make_address(sub)) elif sub.tag == "contactinfo": if len(sub.attrib) != 1: raise ABCTypesError, "error in contact: %s" % value if not sub.text: continue type = sub.attrib.get("contacttype") result.add_contact( ABCTypes.get_type("contacttype", ( "organization", type, )), value) elif sub.tag == "ou" and result.ou is None: # Rather tricky. We have to represent the trailing OUs with # something. Returning an iterator seems viable. result.ou = ABCFactory.get('OUParser')(iter( element.getiterator("ou"))) return result
def next(self): """Return the next DataOU object. Returns a ABCTypesError exception if object has errors in types. These objects should be skipped. Consume the next XML-element describing an organization, and return a suitable representation (DataOU). """ # This call with propagate StopIteration when all the (XML) elements # are exhausted. element = super(XMLOrg2Object, self).next() result = DataOU() # Iterate over *all* subelements for sub in element: value = None if sub.text: value = sub.text.strip() if sub.tag == "orgid": if len(sub.attrib) != 1: raise ABCTypesError( "wrong number of arguments: {}".format(value)) _type = sub.attrib.get("orgidtype") result.add_id(ABCTypes.get_type("orgidtype", (_type,)), value) elif sub.tag == "orgname": if len(sub.attrib) != 2: raise ABCTypesError("not 2 attributes: {}".format(value)) _type = sub.attrib.get("orgnametype") result.add_name(ABCTypes.get_type("orgnametype", (_type,)), value) elif sub.tag == "realm": result.realm = value elif sub.tag == "address": if len(sub.attrib) != 1: raise ABCTypesError("error in address: {}".format(value)) _type = sub.attrib.get("addresstype") addr_type = ABCTypes.get_type("addresstype", ("organization", _type)) result.add_address(addr_type, self._make_address(sub)) elif sub.tag == "contactinfo": if len(sub.attrib) != 1: raise ABCTypesError("error in contact: {}".format(value)) if not sub.text: continue _type = sub.attrib.get("contacttype") result.add_contact(ABCTypes.get_type("contacttype", ("organization", _type,)), value) elif sub.tag == "ou" and result.ou is None: # Rather tricky. We have to represent the trailing OUs with # something. Returning an iterator seems viable. result.ou = ABCFactory.get('OUParser')( iter(element.getiterator("ou"))) return result
def next(self): """Return the next DataOU object. Returns a ABCTypesError exception if object has errors in types. These objects should be skipped. Consume the next XML-element describing an OU, and return a suitable representation (DataOU). """ # This call with propagate StopIteration when all the (XML) elements # are exhausted. element = super(XMLOU2Object, self).next() result = DataOU() # Iterate over *all* subelements for sub in element.getiterator(): value = None if sub.text: value = sub.text.strip().encode("latin1") if sub.tag == "ouid": if len(sub.attrib) != 1: raise ABCTypesError, "error in ouid: %s" % value type = sub.attrib.get("ouidtype") result.add_id(ABCTypes.get_type("ouidtype", (type, )), value) elif sub.tag == "tag": if len(sub.attrib) != 1: raise ABCTypesError, "error in tag: %s" % value type = sub.attrib.get("tagtype") result.add_tag(ABCTypes.get_type("tagtype", ("ou", type)), value) elif sub.tag == "ouname": if len(sub.attrib) != 2: raise ABCTypesError, "error in ouname: %s" % value type = sub.attrib.get("ounametype") # TODO: support lang lang = sub.attrib.get("lang") result.add_name(ABCTypes.get_type("ounametype", (type, )), value) elif sub.tag == "parentid": if len(sub.attrib) != 1: raise ABCTypesError, "error in parentid: %s" % value type = sub.attrib.get("ouidtype") result.parent = (ABCTypes.get_type("ouidtype", (type, )), value) elif sub.tag == "address": if len(sub.attrib) != 1: raise ABCTypesError, "error in address: %s" % value type = sub.attrib.get("addresstype") addr_type = ABCTypes.get_type("addresstype", ("ou", type)) result.add_address(addr_type, self._make_address(sub)) elif sub.tag == "contactinfo": if len(sub.attrib) != 1: raise ABCTypesError, "error on contactinfo: %s" % value if not sub.text: continue type = sub.attrib.get("contacttype") result.add_contact( ABCTypes.get_type("contacttype", ( "ou", type, )), value) # NB! This is crucial to save memory on XML elements element.clear() return result
def next(self): """Return the next DataOU object. Returns a ABCTypesError exception if object has errors in types. These objects should be skipped. Consume the next XML-element describing an OU, and return a suitable representation (DataOU). """ # This call with propagate StopIteration when all the (XML) elements # are exhausted. element = super(XMLOU2Object, self).next() result = DataOU() # Iterate over *all* subelements for sub in element.getiterator(): value = None if sub.text: value = sub.text.strip() if sub.tag == "ouid": if len(sub.attrib) != 1: raise ABCTypesError("error in ouid: {}".format(value)) _type = sub.attrib.get("ouidtype") result.add_id(ABCTypes.get_type("ouidtype", (_type,)), value) elif sub.tag == "tag": if len(sub.attrib) != 1: raise ABCTypesError("error in tag: {}".format(value)) _type = sub.attrib.get("tagtype") result.add_tag(ABCTypes.get_type("tagtype", ("ou", _type)), value) elif sub.tag == "ouname": if len(sub.attrib) != 2: raise ABCTypesError("error in ouname: {}".format(value)) _type = sub.attrib.get("ounametype") result.add_name(ABCTypes.get_type("ounametype", (_type,)), value) elif sub.tag == "parentid": if len(sub.attrib) != 1: raise ABCTypesError("error in parentid: {}".format(value)) _type = sub.attrib.get("ouidtype") result.parent = (ABCTypes.get_type("ouidtype", (_type,)), value) elif sub.tag == "address": if len(sub.attrib) != 1: raise ABCTypesError("error in address: {}".format(value)) _type = sub.attrib.get("addresstype") addr_type = ABCTypes.get_type("addresstype", ("ou", _type)) result.add_address(addr_type, self._make_address(sub)) elif sub.tag == "contactinfo": if len(sub.attrib) != 1: raise ABCTypesError("error on contactinfo: {}" .format(value)) if not sub.text: continue _type = sub.attrib.get("contacttype") result.add_contact(ABCTypes.get_type("contacttype", ("ou", _type,)), value) # NB! This is crucial to save memory on XML elements element.clear() return result