def start_element(self, name=None, type=None, ref=None, substitutionGroup=None, minOccurs=None, maxOccurs=None):
        element = Element()
        element.name = name

        if ref:
            (namespacename, localname) = QName.split(ref)

            if namespacename in self.schema.prefixmappings:
                elementref = QName(self.schema.prefixmappings[namespacename], localname)
            else:
                elementref = QName(namespacename, localname)

            element.ref = elementref

        if type:
            (namespacename, localname) = QName.split(type)

            if namespacename in self.schema.prefixmappings:
                typename = QName(self.schema.prefixmappings[namespacename], localname)
            else:
                typename = QName(namespacename, localname)

            element.typename = typename

        if substitutionGroup:
            (namespacename, localname) = QName.split(substitutionGroup)

            if namespacename in self.schema.prefixmappings:
                elementref = QName(self.schema.prefixmappings[namespacename], localname)
            else:
                elementref = QName(namespacename, localname)

            element.substitutiongroup = elementref

        if minOccurs:
            try:
                element.minoccurs = int(minOccurs)
            except ValueError:
                element.minoccurs = minOccurs

        if maxOccurs:
            try:
                element.maxoccurs = int(maxOccurs)
            except ValueError:
                element.maxoccurs = maxOccurs

        self.handleelement(element)
    def start_extension(self, base):
        extension = Extension()
        basetyperef = QName(*QName.split(base))

        if basetyperef.namespacename in self.schema.prefixmappings:
            basetyperef = QName(self.schema.prefixmappings[basetyperef.namespacename], basetyperef.localname)

        extension.basetypereference = basetyperef

        parent = self.elementstack[-1]

        if isinstance(parent, (SimpleContent, ComplexContent)):
            parent.extension = extension

        self.startxmlelement(extension)
예제 #3
0
def test_split():
    parts = QName.split("somename.org:directory")

    assert parts[0] == "somename.org"
    assert parts[1] == "directory"