本文整理汇总了Python中xml.etree方法的典型用法代码示例。如果您正苦于以下问题:Python xml.etree方法的具体用法?Python xml.etree怎么用?Python xml.etree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml.etree方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_etree
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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
示例2: test_multiplePackages
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)
示例3: test_multiplePackagesFinalModule
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)
示例4: test_multiplePackagesObject
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)
示例5: test_failsWithMultiplePackagesMissingModuleOrPackage
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)
示例6: test_ignored_modules_invalid_pattern
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)
示例7: test_ignored_modules_patterns
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
def test_ignored_modules_patterns(self):
node = astroid.extract_node(
"""
import xml
xml.etree.portocola #@
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)
示例8: test_ignored_classes_no_recursive_pattern
# 需要导入模块: import xml [as 别名]
# 或者: from xml import etree [as 别名]
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)