Ejemplo n.º 1
0
 def test_iterparse_method_with_unicode(self):
     xsd_string = """
         <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
             <\u0192-root><test></test></\u0192-root>
         </xs:schema>
     """
     XSDTree.iterparse(xsd_string, ("end", ))
Ejemplo n.º 2
0
    def test_iterparse_method_without_decoded_symbols(self):
        xsd_string = """
            <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
                <ƒ-root><test></test></ƒ-root>
            </xs:schema>
        """

        with self.assertRaises(XMLError):
            XSDTree.iterparse(xsd_string, ("end", ))
Ejemplo n.º 3
0
def get_global_namespace(xsd_string):
    """ Get global namespace used in schema (defined by xmlns=<namespace>)

    Returns:

    """
    # events to look for during iterparse
    events = "start", "start-ns"
    # Initialize global namespace
    global_namespace = None
    # iterate file namespaces
    for event, elem in XSDTree.iterparse(xsd_string, events):
        if event == "start-ns":
            if len(elem[0]) == 0:
                global_namespace = elem[1]
        elif event == "start":
            break

    return global_namespace
Ejemplo n.º 4
0
def get_namespaces(xsd_string):
    """Returns dict of prefix and namespaces

    Args:
        xsd_string:

    Returns:

    """
    # events to look for during iterparse
    events = "start", "start-ns"
    # initialize namespaces dictionary
    namespaces = {'xml': xml_utils_constants.XML_NAMESPACE}
    # iterate file namespaces
    for event, elem in XSDTree.iterparse(xsd_string, events):
        if event == "start-ns":
            if len(elem[0]) > 0 and len(elem[1]) > 0:
                namespaces[elem[0]] = "%s" % elem[1]
        elif event == "start":
            break

    return namespaces
Ejemplo n.º 5
0
 def test_iterparse_method_without_unicode(self):
     xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><root><test></test></root></xs:schema>"
     XSDTree.iterparse(xsd_string, ('end', ))