Python xml.etree() Examples

The following are 18 code examples of xml.etree(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xml , or try the search function .
Example #1
Source File: xmldict.py    From eppy with MIT License 6 votes vote down vote up
def import_etree():
    import xml
    # first try the usual way
    try:
        import xml.etree
        return xml.etree
    except ImportError:
        pass
    # do it by hook or by crook...
    import os
    import imp
    xml_site_package = os.path.join(os.path.dirname(os.__file__), 'xml')
    m = imp.find_module('etree', [xml_site_package])

    etree = imp.load_module('xml.etree', *m)
    setattr(xml, 'etree', etree)
    return etree 
Example #2
Source File: test_discover.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_multiplePackages(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest package described by dotted FQPN.
        """
        import xml.etree
        self.assertModuleWrapperRefersTo(self.wrapFQPN('xml.etree'), xml.etree) 
Example #3
Source File: test_discover.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_failsWithMultiplePackagesMissingModuleOrPackage(self):
        """
        L{wrapFQPN} raises L{NoObject} when given an FQPN that contains a
        missing attribute, module, or package.
        """
        for bad in ('xml.etree.nope!',
                    'xml.etree.nope!.but.the.rest.is.believable'):
            with self.assertRaises(self.NoObject):
                self.wrapFQPN(bad) 
Example #4
Source File: test_discover.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_multiplePackagesObject(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonAttribute}
        referring to the deepest object described by an FQPN,
        descending through several packages.
        """
        import xml.etree.ElementTree
        import automat

        for fqpn, obj in [('xml.etree.ElementTree.fromstring',
                           xml.etree.ElementTree.fromstring),
                          ('automat.MethodicalMachine.__doc__',
                           automat.MethodicalMachine.__doc__)]:
            self.assertAttributeWrapperRefersTo(
                self.wrapFQPN(fqpn), fqpn, obj) 
Example #5
Source File: test_discover.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_multiplePackagesFinalModule(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest module described by dotted FQPN.
        """
        import xml.etree.ElementTree
        self.assertModuleWrapperRefersTo(
            self.wrapFQPN('xml.etree.ElementTree'), xml.etree.ElementTree) 
Example #6
Source File: test_discover.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_multiplePackages(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest package described by dotted FQPN.
        """
        import xml.etree
        self.assertModuleWrapperRefersTo(self.wrapFQPN('xml.etree'), xml.etree) 
Example #7
Source File: test_discover.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_failsWithMultiplePackagesMissingModuleOrPackage(self):
        """
        L{wrapFQPN} raises L{NoObject} when given an FQPN that contains a
        missing attribute, module, or package.
        """
        for bad in ('xml.etree.nope!',
                    'xml.etree.nope!.but.the.rest.is.believable'):
            with self.assertRaises(self.NoObject):
                self.wrapFQPN(bad) 
Example #8
Source File: test_discover.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_multiplePackagesObject(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonAttribute}
        referring to the deepest object described by an FQPN,
        descending through several packages.
        """
        import xml.etree.ElementTree
        import automat

        for fqpn, obj in [('xml.etree.ElementTree.fromstring',
                           xml.etree.ElementTree.fromstring),
                          ('automat.MethodicalMachine.__doc__',
                           automat.MethodicalMachine.__doc__)]:
            self.assertAttributeWrapperRefersTo(
                self.wrapFQPN(fqpn), fqpn, obj) 
Example #9
Source File: test_discover.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_multiplePackagesFinalModule(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest module described by dotted FQPN.
        """
        import xml.etree.ElementTree
        self.assertModuleWrapperRefersTo(
            self.wrapFQPN('xml.etree.ElementTree'), xml.etree.ElementTree) 
Example #10
Source File: test_discover.py    From automat with MIT License 5 votes vote down vote up
def test_multiplePackages(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest package described by dotted FQPN.
        """
        import xml.etree
        self.assertModuleWrapperRefersTo(self.wrapFQPN('xml.etree'), xml.etree) 
Example #11
Source File: unittest_checker_typecheck.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_ignored_modules_patterns(self):
        node = astroid.extract_node(
            """
        import xml
        xml.etree.portocola #@
        """
        )
        with self.assertNoMessages():
            self.checker.visit_attribute(node) 
Example #12
Source File: unittest_checker_typecheck.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_ignored_modules_invalid_pattern(self):
        node = astroid.extract_node(
            """
        import xml
        xml.etree.Lala
        """
        )
        message = Message(
            "no-member", node=node, args=("Module", "xml.etree", "Lala", "")
        )
        with self.assertAddsMessages(message):
            self.checker.visit_attribute(node) 
Example #13
Source File: unittest_checker_typecheck.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_ignored_classes_no_recursive_pattern(self):
        node = astroid.extract_node(
            """
        import xml
        xml.etree.ElementTree.Test
        """
        )
        message = Message(
            "no-member", node=node, args=("Module", "xml.etree.ElementTree", "Test", "")
        )
        with self.assertAddsMessages(message):
            self.checker.visit_attribute(node) 
Example #14
Source File: unittest_checker_typecheck.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_ignored_modules_patterns(self):
        node = astroid.extract_node(
            """
        import xml
        xml.etree.portocola #@
        """
        )
        with self.assertNoMessages():
            self.checker.visit_attribute(node) 
Example #15
Source File: unittest_checker_typecheck.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_ignored_modules_invalid_pattern(self):
        node = astroid.extract_node(
            """
        import xml
        xml.etree.Lala
        """
        )
        message = Message(
            "no-member", node=node, args=("Module", "xml.etree", "Lala", "")
        )
        with self.assertAddsMessages(message):
            self.checker.visit_attribute(node) 
Example #16
Source File: test_discover.py    From automat with MIT License 5 votes vote down vote up
def test_failsWithMultiplePackagesMissingModuleOrPackage(self):
        """
        L{wrapFQPN} raises L{NoObject} when given an FQPN that contains a
        missing attribute, module, or package.
        """
        for bad in ('xml.etree.nope!',
                    'xml.etree.nope!.but.the.rest.is.believable'):
            with self.assertRaises(self.NoObject):
                self.wrapFQPN(bad) 
Example #17
Source File: test_discover.py    From automat with MIT License 5 votes vote down vote up
def test_multiplePackagesObject(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonAttribute}
        referring to the deepest object described by an FQPN,
        descending through several packages.
        """
        import xml.etree.ElementTree
        import automat

        for fqpn, obj in [('xml.etree.ElementTree.fromstring',
                           xml.etree.ElementTree.fromstring),
                          ('automat.MethodicalMachine.__doc__',
                           automat.MethodicalMachine.__doc__)]:
            self.assertAttributeWrapperRefersTo(
                self.wrapFQPN(fqpn), fqpn, obj) 
Example #18
Source File: test_discover.py    From automat with MIT License 5 votes vote down vote up
def test_multiplePackagesFinalModule(self):
        """
        L{wrapFQPN} returns a L{twisted.python.modules.PythonModule}
        referring to the deepest module described by dotted FQPN.
        """
        import xml.etree.ElementTree
        self.assertModuleWrapperRefersTo(
            self.wrapFQPN('xml.etree.ElementTree'), xml.etree.ElementTree)