本文整理汇总了Python中lxml.etree.LXML_VERSION属性的典型用法代码示例。如果您正苦于以下问题:Python etree.LXML_VERSION属性的具体用法?Python etree.LXML_VERSION怎么用?Python etree.LXML_VERSION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类lxml.etree
的用法示例。
在下文中一共展示了etree.LXML_VERSION属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: diagnose
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def diagnose(data):
"""Diagnostic suite for isolating common problems."""
print "Diagnostic running on Beautiful Soup %s" % __version__
print "Python version %s" % sys.version
basic_parsers = ["html.parser", "html5lib", "lxml"]
for name in basic_parsers:
for builder in builder_registry.builders:
if name in builder.features:
break
else:
basic_parsers.remove(name)
print (
"I noticed that %s is not installed. Installing it may help." %
name)
if 'lxml' in basic_parsers:
basic_parsers.append(["lxml", "xml"])
try:
from lxml import etree
print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION))
except ImportError, e:
print (
"lxml is not installed or couldn't be imported.")
示例2: get_versions
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def get_versions():
if not use_generic_pdf_cover:
IVersion = ImageVersion.MAGICK_VERSION
WVersion = ImageVersion.VERSION
else:
IVersion = u'not installed'
WVersion = u'not installed'
if use_pdf_meta:
PVersion='v'+PyPdfVersion
else:
PVersion=u'not installed'
if lxmlversion:
XVersion = 'v'+'.'.join(map(str, lxmlversion))
else:
XVersion = u'not installed'
if use_PIL:
PILVersion = 'v' + PILversion
else:
PILVersion = u'not installed'
if comic.use_comic_meta:
ComicVersion = comic.comic_version or u'installed'
else:
ComicVersion = u'not installed'
return {'Image Magick': IVersion,
'PyPdf': PVersion,
'lxml':XVersion,
'Wand': WVersion,
'Pillow': PILVersion,
'Comic_API': ComicVersion}
示例3: lxml_available
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def lxml_available():
try:
from lxml.etree import LXML_VERSION
LXML = LXML_VERSION >= (3, 3, 1, 0)
if not LXML:
import warnings
warnings.warn("The installed version of lxml is too old to be used with openpyxl")
return False # we have it, but too old
else:
return True # we have it, and recent enough
except ImportError:
return False # we don't even have it
示例4: test_defined_xhtml
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def test_defined_xhtml(self):
"""Test defined XHTML."""
markup = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="0"></div>
<div-custom id="1"></div-custom>
<prefix:div id="2"></prefix:div>
<!--
lxml seems to strip away the prefix in versions less than 4.4.0.
This was most likely because prefix with no namespace is not really valid.
XML does allow colons in names, but encourages them to be used for namespaces.
This is a quirk of LXML, but it appears to be fine in 4.4.0+.
-->
<prefix:div-custom id="3"></prefix:div-custom>
</body>
</html>
"""
from lxml import etree
self.assert_selector(
markup,
'body :defined',
# We should get 3, but for LXML versions less than 4.4.0 we don't for reasons stated above.
['0', '2'] if etree.LXML_VERSION < (4, 4, 0, 0) else ['0', '1', '2'],
flags=util.XHTML
)
示例5: diagnose
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def diagnose(data):
"""Diagnostic suite for isolating common problems."""
print "Diagnostic running on Beautiful Soup %s" % __version__
print "Python version %s" % sys.version
basic_parsers = ["html.parser", "html5lib", "lxml"]
for name in basic_parsers:
for builder in builder_registry.builders:
if name in builder.features:
break
else:
basic_parsers.remove(name)
print (
"I noticed that %s is not installed. Installing it may help." %
name)
if 'lxml' in basic_parsers:
basic_parsers.append(["lxml", "xml"])
from lxml import etree
print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION))
if 'html5lib' in basic_parsers:
import html5lib
print "Found html5lib version %s" % html5lib.__version__
if hasattr(data, 'read'):
data = data.read()
elif os.path.exists(data):
print '"%s" looks like a filename. Reading data from the file.' % data
data = open(data).read()
elif data.startswith("http:") or data.startswith("https:"):
print '"%s" looks like a URL. Beautiful Soup is not an HTTP client.' % data
print "You need to use some other library to get the document behind the URL, and feed that document to Beautiful Soup."
return
print
for parser in basic_parsers:
print "Trying to parse your markup with %s" % parser
success = False
try:
soup = BeautifulSoup(data, parser)
success = True
except Exception, e:
print "%s could not parse the markup." % parser
traceback.print_exc()
if success:
print "Here's what %s did with the markup:" % parser
print soup.prettify()
print "-" * 80
示例6: diagnose
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def diagnose(data):
"""Diagnostic suite for isolating common problems."""
print("Diagnostic running on Beautiful Soup %s" % __version__)
print("Python version %s" % sys.version)
basic_parsers = ["html.parser", "html5lib", "lxml"]
for name in basic_parsers:
for builder in builder_registry.builders:
if name in builder.features:
break
else:
basic_parsers.remove(name)
print((
"I noticed that %s is not installed. Installing it may help." %
name))
if 'lxml' in basic_parsers:
basic_parsers.append(["lxml", "xml"])
try:
from lxml import etree
print("Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION)))
except ImportError as e:
print (
"lxml is not installed or couldn't be imported.")
if 'html5lib' in basic_parsers:
try:
import html5lib
print("Found html5lib version %s" % html5lib.__version__)
except ImportError as e:
print (
"html5lib is not installed or couldn't be imported.")
if hasattr(data, 'read'):
data = data.read()
elif os.path.exists(data):
print('"%s" looks like a filename. Reading data from the file.' % data)
with open(data) as fp:
data = fp.read()
elif data.startswith("http:") or data.startswith("https:"):
print('"%s" looks like a URL. Beautiful Soup is not an HTTP client.' % data)
print("You need to use some other library to get the document behind the URL, and feed that document to Beautiful Soup.")
return
print()
for parser in basic_parsers:
print("Trying to parse your markup with %s" % parser)
success = False
try:
soup = BeautifulSoup(data, parser)
success = True
except Exception as e:
print("%s could not parse the markup." % parser)
traceback.print_exc()
if success:
print("Here's what %s did with the markup:" % parser)
print(soup.prettify())
print("-" * 80)
示例7: run_module
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def run_module():
module_args = dict(
intellij_user_config_dir=dict(type='str', required=True),
jdk_name=dict(type='str', required=True),
jdk_home=dict(type='str', required=True),
owner=dict(type='str', required=True),
group=dict(type='str', required=True))
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
owner = module.params['owner']
group = module.params['group']
try:
uid = int(owner)
except ValueError:
uid = pwd.getpwnam(owner).pw_uid
username = pwd.getpwuid(uid).pw_name
try:
gid = int(group)
except ValueError:
gid = grp.getgrnam(group).gr_gid
intellij_user_config_dir = os.path.expanduser(
os.path.join('~' + username, module.params['intellij_user_config_dir']))
jdk_name = module.params['jdk_name']
jdk_home = os.path.expanduser(module.params['jdk_home'])
# Check if we have lxml 2.3.0 or newer installed
if not HAS_LXML:
module.fail_json(
msg=
'The xml ansible module requires the lxml python library installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('2.3.0'):
module.fail_json(
msg=
'The xml ansible module requires lxml 2.3.0 or newer installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('3.0.0'):
module.warn(
'Using lxml version lower than 3.0.0 does not guarantee predictable element attribute order.'
)
changed, diff = configure_jdk(module, intellij_user_config_dir, jdk_name, jdk_home, uid, gid)
if changed:
msg = 'JDK %s has been configured' % jdk_name
else:
msg = 'JDK %s was already configured' % jdk_name
module.exit_json(changed=changed, msg=msg, diff=diff)
示例8: run_module
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def run_module():
module_args = dict(
intellij_user_config_dir=dict(type='str', required=True),
jdk_name=dict(type='str', required=True),
owner=dict(type='str', required=True),
group=dict(type='str', required=True))
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
owner = module.params['owner']
group = module.params['group']
try:
uid = int(owner)
except ValueError:
uid = pwd.getpwnam(owner).pw_uid
username = pwd.getpwuid(uid).pw_name
try:
gid = int(group)
except ValueError:
gid = grp.getgrnam(group).gr_gid
intellij_user_config_dir = os.path.expanduser(
os.path.join('~' + username, module.params['intellij_user_config_dir']))
jdk_name = os.path.expanduser(module.params['jdk_name'])
# Check if we have lxml 2.3.0 or newer installed
if not HAS_LXML:
module.fail_json(
msg=
'The xml ansible module requires the lxml python library installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('2.3.0'):
module.fail_json(
msg=
'The xml ansible module requires lxml 2.3.0 or newer installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('3.0.0'):
module.warn(
'Using lxml version lower than 3.0.0 does not guarantee predictable element attribute order.'
)
changed, diff = set_default_jdk(module, intellij_user_config_dir, jdk_name, uid, gid)
if changed:
msg = '%s is now the default JDK' % jdk_name
else:
msg = '%s is already the default JDK' % jdk_name
module.exit_json(changed=changed, msg=msg, diff=diff)
示例9: run_module
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def run_module():
module_args = dict(
intellij_user_config_dir=dict(type='str', required=True),
profile_name=dict(type='str', required=True),
owner=dict(type='str', required=True),
group=dict(type='str', required=True))
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
owner = module.params['owner']
group = module.params['group']
try:
uid = int(owner)
except ValueError:
uid = pwd.getpwnam(owner).pw_uid
username = pwd.getpwuid(uid).pw_name
try:
gid = int(group)
except ValueError:
gid = grp.getgrnam(group).gr_gid
intellij_user_config_dir = os.path.expanduser(
os.path.join('~' + username, module.params['intellij_user_config_dir']))
profile_name = os.path.expanduser(module.params['profile_name'])
# Check if we have lxml 2.3.0 or newer installed
if not HAS_LXML:
module.fail_json(
msg=
'The xml ansible module requires the lxml python library installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('2.3.0'):
module.fail_json(
msg=
'The xml ansible module requires lxml 2.3.0 or newer installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('3.0.0'):
module.warn(
'Using lxml version lower than 3.0.0 does not guarantee predictable element attribute order.'
)
changed, diff = set_default_inspection_profile(module, intellij_user_config_dir, profile_name, uid, gid)
if changed:
msg = '%s is now the default inspection profile' % profile_name
else:
msg = '%s is already the default inspection profile' % profile_name
module.exit_json(changed=changed, msg=msg, diff=diff)
示例10: run_module
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import LXML_VERSION [as 别名]
def run_module():
module_args = dict(
intellij_user_config_dir=dict(type='str', required=True),
maven_home=dict(type='str', required=True),
owner=dict(type='str', required=True),
group=dict(type='str', required=True))
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
owner = module.params['owner']
group = module.params['group']
try:
uid = int(owner)
except ValueError:
uid = pwd.getpwnam(owner).pw_uid
username = pwd.getpwuid(uid).pw_name
try:
gid = int(group)
except ValueError:
gid = grp.getgrnam(group).gr_gid
intellij_user_config_dir = os.path.expanduser(
os.path.join('~' + username, module.params['intellij_user_config_dir']))
maven_home = os.path.expanduser(module.params['maven_home'])
# Check if we have lxml 2.3.0 or newer installed
if not HAS_LXML:
module.fail_json(
msg=
'The xml ansible module requires the lxml python library installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('2.3.0'):
module.fail_json(
msg=
'The xml ansible module requires lxml 2.3.0 or newer installed on the managed machine'
)
elif LooseVersion('.'.join(
to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('3.0.0'):
module.warn(
'Using lxml version lower than 3.0.0 does not guarantee predictable element attribute order.'
)
changed, diff = set_default_maven(module, intellij_user_config_dir, maven_home, uid, gid)
if changed:
msg = '%s is now the default Maven installation' % maven_home
else:
msg = '%s is already the default Maven installation' % maven_home
module.exit_json(changed=changed, msg=msg, diff=diff)