當前位置: 首頁>>代碼示例>>Python>>正文


Python etree.LXML_VERSION屬性代碼示例

本文整理匯總了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.") 
開發者ID:MarcelloLins,項目名稱:ServerlessCrawler-VancouverRealState,代碼行數:26,代碼來源:diagnose.py

示例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} 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:31,代碼來源:uploader.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:__init__.py

示例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
        ) 
開發者ID:facelessuser,項目名稱:soupsieve,代碼行數:36,代碼來源:test_defined.py

示例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 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:52,代碼來源:diagnose.py

示例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) 
開發者ID:the-ethan-hunt,項目名稱:B.E.N.J.I.,代碼行數:62,代碼來源:diagnose.py

示例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) 
開發者ID:gantsign,項目名稱:ansible-role-intellij,代碼行數:58,代碼來源:intellij_configure_jdk.py

示例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) 
開發者ID:gantsign,項目名稱:ansible-role-intellij,代碼行數:57,代碼來源:intellij_set_default_jdk.py

示例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) 
開發者ID:gantsign,項目名稱:ansible-role-intellij,代碼行數:56,代碼來源:intellij_set_default_inspection_profile.py

示例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) 
開發者ID:gantsign,項目名稱:ansible-role-intellij,代碼行數:56,代碼來源:intellij_set_default_maven.py


注:本文中的lxml.etree.LXML_VERSION屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。