当前位置: 首页>>代码示例>>Python>>正文


Python ChromeManifest.get_value方法代码示例

本文整理汇总了Python中validator.chromemanifest.ChromeManifest.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python ChromeManifest.get_value方法的具体用法?Python ChromeManifest.get_value怎么用?Python ChromeManifest.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validator.chromemanifest.ChromeManifest的用法示例。


在下文中一共展示了ChromeManifest.get_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_open

# 需要导入模块: from validator.chromemanifest import ChromeManifest [as 别名]
# 或者: from validator.chromemanifest.ChromeManifest import get_value [as 别名]
def test_open():
    """Open a chrome file and ensure that data can be pulled from it."""

    chrome = open("tests/resources/chromemanifest/chrome.manifest")
    chrome_data = chrome.read()

    manifest = ChromeManifest(chrome_data, "chrome.manifest")
    assert manifest is not None

    assert manifest.get_value("locale", "basta")["object"] == "resource"

    g_obj = list(manifest.get_objects("subject", "predicate"))

    assert len(g_obj) == 1
    assert g_obj[0] == "object"

    obj_resource = list(manifest.get_triples(None, None, "resource"))
    assert len(obj_resource) == 2

    pred_pred = list(manifest.get_triples(None, "predicate", None))
    assert len(pred_pred) == 2

    sub_locale = list(manifest.get_triples("locale", None, None))
    assert len(sub_locale) == 2
开发者ID:clouserw,项目名称:amo-validator,代码行数:26,代码来源:test_chromemanifest.py

示例2: test_conduittoolbar

# 需要导入模块: from validator.chromemanifest import ChromeManifest [as 别名]
# 或者: from validator.chromemanifest.ChromeManifest import get_value [as 别名]
def test_conduittoolbar(err, package_contents=None, xpi_manager=None):
    "Find and blacklist Conduit toolbars"

    # Ignore non-extension types
    if err.detected_type in (PACKAGE_ANY, PACKAGE_THEME, PACKAGE_SEARCHPROV):
        return None

    # Tests regarding the install.rdf file.
    if err.get_resource("has_install_rdf"):

        # Go out and fetch the install.rdf instance object
        install = err.get_resource("install_rdf")

        # Define a list of specifications to search for Conduit with
        parameters = {
            "http://www.conduit.com/": install.uri("homepageURL"),
            "Conduit Ltd.": install.uri("creator"),
            "More than just a toolbar.": install.uri("description"),
        }

        # Iterate each specification and test for it.
        for k, uri_reference in parameters.items():
            # Retrieve the value
            results = install.get_object(None, uri_reference)
            # If the value exists, test for the appropriate content
            if results == k:
                err.reject = True
                err_mesg = "Conduit value (%s) found in install.rdf" % k
                return err.warning(
                    ("testcases_conduit", "test_conduittoolbar", "detected_rdf"),
                    "Detected Conduit toolbar.",
                    err_mesg,
                    "install.rdf",
                )

        # Also test for the update URL
        update_url_value = "https://ffupdate.conduit-services.com/"

        results = install.get_object(None, install.uri("updateURL"))
        if results and results.startswith(update_url_value):
            err.reject = True
            return err.warning(
                ("testcases_conduit", "test_conduittoolbar", "detected_updateurl"),
                "Detected Conduit toolbar.",
                "Conduit update URL found in install.rdf.",
                "install.rdf",
            )

    # Do some matching on the files in the package
    conduit_files = ("components/Conduit*", "searchplugin/conduit*")
    for file_ in package_contents:
        for bad_file in conduit_files:
            # If there's a matching file, it's Conduit
            if fnmatch.fnmatch(file_, bad_file):
                err.reject = True
                return err.warning(
                    ("testcases_conduit", "test_conduittoolbar", "detected_files"),
                    "Detected Conduit toolbar.",
                    "Conduit directory (%s) found." % bad_file,
                )

    # Do some tests on the chrome.manifest file if it exists
    if "chrome.manifest" in package_contents:
        # Grab the chrome manifest
        if err.get_resource("chrome.manifest"):  # pragma: no cover
            # It's cached in the error bundler
            chrome = err.get_resource("chrome.manifest")
        else:
            # Not cached, so we grab it.
            chrome_data = xpi_manager.read("chrome.manifest")
            chrome = ChromeManifest(chrome_data)
            err.save_resource("chrome.manifest", chrome)

        # Get all styles for customizing the toolbar
        data = chrome.get_value("style", "chrome://global/content/customizeToolbar.xul")

        # If the style exists and it contains "ebtoolbarstyle"...
        if data is not None and data["object"].count("ebtoolbarstyle") > 0:
            err.reject = True
            return err.warning(
                ("testcases_conduit", "test_conduittoolbar", "detected_chrome_manifest"),
                "Detected Conduit toolbar.",
                "'ebtoolbarstyle' found in chrome.manifest",
                "chrome.manifest",
                line=data["line"],
                context=chrome.context,
            )
开发者ID:nmaier,项目名称:amo-validator,代码行数:89,代码来源:conduit.py


注:本文中的validator.chromemanifest.ChromeManifest.get_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。