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


Python XPIManager.get_file_data方法代码示例

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


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

示例1: _do_test

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def _do_test(path, test, failure=True,
             require_install=False, set_type=0):
    
    package_data = open(path, "rb")
    package = XPIManager(package_data, path)
    contents = package.get_file_data()
    err = ErrorBundle()
    
    # Populate in the dependencies.
    if set_type:
        err.set_type(set_type) # Conduit test requires type
    if require_install:
        err.save_resource("has_install_rdf", True)
        rdf_data = package.read("install.rdf")
        install_rdf = RDFParser(rdf_data)
        err.save_resource("install_rdf", install_rdf)
    
    test(err, contents, package)
    
    print err.print_summary(verbose=True)
    
    if failure:
        assert err.failed()
    else:
        assert not err.failed()
    
    return err
开发者ID:nmaier,项目名称:amo-validator,代码行数:29,代码来源:helper.py

示例2: test_blacklisted_files

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_blacklisted_files():
    """Tests the validator's ability to hash each individual file and
    (based on this information) determine whether the addon passes or
    fails the validation process."""

    package_data = open("tests/resources/libraryblacklist/blocked.xpi")
    package = XPIManager(package_data, "blocked.xpi")
    contents = package.get_file_data()
    err = ErrorBundle()

    libblacklist.test_library_blacklist(err, contents, package)

    print err.print_summary()

    assert err.notices
开发者ID:nmaier,项目名称:amo-validator,代码行数:17,代码来源:test_libraryblacklist.py

示例3: _test_type

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def _test_type(file_, expectation, failure=False):
    "Tests a file against the expectations"

    err = ErrorBundle(None, True)
    package = XPIManager(open(file_, "rb"), file_)
    contents = package.get_file_data()

    # We need to have an install.rdf.
    assert "install.rdf" in contents

    # Load up the install.rdf into an RDFParser
    install_file = package.read("install.rdf")
    install_rdf = RDFParser(install_file)

    results = typedetection.detect_type(err, install_rdf, package)

    assert results == expectation
    if not failure:
        assert not err.failed()
    else:
        assert err.failed()
开发者ID:nmaier,项目名称:amo-validator,代码行数:23,代码来源:test_typedetection.py

示例4: test_package

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_package(err, file_, name, expectation=PACKAGE_ANY):
    "Begins tests for the package."
    
    # Load up a new instance of an XPI.
    package = XPIManager(file_, name)
    if not package.zf:
        # Die on this one because the file won't open.
        return err.error(("main",
                          "test_package",
                          "unopenable"),
                         "The XPI could not be opened.")
    
    # Test the XPI file for corruption.
    if package.test():
        err.reject = True
        return err.error(("main",
                          "test_package",
                          "corrupt"),
                         "XPI package appears to be corrupt.")
    
    if package.extension in assumed_extensions:
        assumed_type = assumed_extensions[package.extension]
        # Is the user expecting a different package type?
        if not expectation in (PACKAGE_ANY, assumed_type):
            err.error(("main",
                       "test_package",
                       "unexpected_type"),
                      "Unexpected package type (found theme)")
                      
    # Cache a copy of the package contents.
    package_contents = package.get_file_data()
    
    # Test the install.rdf file to see if we can get the type that way.
    has_install_rdf = "install.rdf" in package_contents
    if has_install_rdf:
        _load_install_rdf(err, package, expectation)
    
    return test_inner_package(err, package_contents, package)
开发者ID:nmaier,项目名称:amo-validator,代码行数:40,代码来源:submain.py

示例5: test_valid_name

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_valid_name():
    "Test that the manager can retrieve the correct file name"
    z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
    contents = z.get_file_data()
    assert "install.rdf" in contents
    assert z.test() == False
开发者ID:nmaier,项目名称:amo-validator,代码行数:8,代码来源:test_xpimanager.py

示例6: test_get_list

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_get_list():
    "Test that the manager can read the file listing"
    z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
    assert z.get_file_data()
开发者ID:nmaier,项目名称:amo-validator,代码行数:6,代码来源:test_xpimanager.py

示例7: test_lp_xpi

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_lp_xpi(err, package_contents, xpi_package):
    "Tests a language pack for L10n completeness"
    
    # Don't even both with the test(s) if there's no chrome.manifest.
    if "chrome.manifest" not in package_contents:
        return None

    locales = _get_locales(err, xpi_package);
    
    # Get the reference packages.
    references = []
    support_references = err.get_resource("supports")
    if not support_references:
        references.append("firefox")
        err.info(("testcases_l10ncompleteness",
                  "test_lp_xpi",
                  "missing_app_support"),
                 "Supported app missing during L10n completeness.",
                 """While testing for L10n comleteness, a list of
                 supported applications for the language pack was not
                 found. This is likely because there are no listed
                 <em:targetApplication> elements in the install.rdf
                 file.""")
    else:
        for support in support_references:
            ref_xpi = XPIManager(os.path.join(os.path.dirname(__file__),
                                              "langpacks/%s.xpi" % support))
            ref_xpi.app_name = support
            reference_locales = _get_locales(None, ref_xpi)

            references.append((ref_xpi, reference_locales))
            
    # Iterate each supported reference package
    for (ref_xpi, ref_locales) in references:
        # Iterate each locale in each supported reference package
        ref_pack = _get_locale_manager(err,
                                       ref_xpi,
                                       "en-US.jar",
                                       ref_xpi.get_file_data(),
                                       no_cache=True)
        for ref_locale_name in ref_locales:
            ref_locale = ref_locales[ref_locale_name]
            ref_predicate = ref_locale["predicate"]
            corresp_locales = [locales[name] for name
                               in locales
                               if locales[name]["predicate"] == ref_predicate]
            # If we found no matching locale, then it's missing from the pack
            if not corresp_locales:
                err.warning(("testcases_l10ncompleteness",
                             "test_lp_xpi",
                             "find_corresponding_locale"),
                            "Could not find corresponding locale",
                            ["A locale was found in the reference package, "
                             "however it was not found in the target package.",
                             "Missing locale: %s" % ref_predicate],
                            filename="chrome.manifest")
                continue
            
            target_locale = corresp_locales[0]
            target_pack = _get_locale_manager(err,
                                              xpi_package,
                                              target_locale["path"],
                                              package_contents)
            if target_pack is None:
                continue

            results = _compare_packages(reference=ref_pack,
                                        target=target_pack,
                                        ref_base=ref_locale["target"],
                                        locale_base=target_locale["target"])

            # Report the findings after each supported app's locale
            _aggregate_results(err, results, target_locale)
    
    # Clear the cache at the end of the test
    LOCALE_CACHE = {}
开发者ID:nmaier,项目名称:amo-validator,代码行数:78,代码来源:l10ncompleteness.py

示例8: test_packed_packages

# 需要导入模块: from validator.xpi import XPIManager [as 别名]
# 或者: from validator.xpi.XPIManager import get_file_data [as 别名]
def test_packed_packages(err, package_contents=None, xpi_package=None):
    "Tests XPI and JAR files for naughty content."
    
    processed_files = 0

    hash_whitelist = [x[:-1] for x in
                      open(os.path.join(os.path.dirname(__file__),
                                        'whitelist_hashes.txt')).readlines()]
    
    # Iterate each item in the package.
    for name, data in package_contents.items():
        
        if name.startswith("__MACOSX") or \
           name.startswith(".DS_Store"):
            continue
        
        if name.split("/")[-1].startswith("._"):
            err.notice(("testcases_content",
                        "test_packed_packages",
                        "macintosh_junk"),
                       "Garbage file found.",
                       ["""A junk file has been detected. It may cause
                        problems with proper operation of the add-on down the
                        road.""",
                        "It is recommended that you delete the file"],
                       name)
        
        try:
            file_data = xpi_package.read(name)
        except KeyError: # pragma: no cover
            _read_error(err, name)

        # Skip over whitelisted hashes
        hash = hashlib.sha1(file_data).hexdigest()
        if hash in hash_whitelist:
            continue

        processed = False
        # If that item is a container file, unzip it and scan it.
        if data["extension"] == "jar":
            # This is either a subpackage or a nested theme.
            
            # Whether this is a subpackage or a nested theme is
            # determined by whether it is in the root folder or not.
            # Subpackages are always found in a directory such as
            # /chrome or /content.
            is_subpackage = name.count("/") > 0
            
            # Unpack the package and load it up.
            package = StringIO(file_data)
            sub_xpi = XPIManager(package, name, is_subpackage)
            if not sub_xpi.zf:
                err.error(("testcases_content",
                           "test_packed_packages",
                           "jar_subpackage_corrupt"),
                          "Subpackage corrupt.",
                          """The subpackage could not be opened due to
                          issues with corruption. Ensure that the file
                          is valid.""",
                          name)
                continue
            
            temp_contents = sub_xpi.get_file_data()
            
            # Let the error bunder know we're in a sub-package.
            err.push_state(data["name_lower"])
            err.set_type(PACKAGE_SUBPACKAGE) # Subpackage
            testendpoint_validator.test_inner_package(err,
                                                      temp_contents,
                                                      sub_xpi)
            err.tier = 2
            package.close()
            err.pop_state()
            
        elif data["extension"] == "xpi":
            # It's not a subpackage, it's a nested extension. These are
            # found in multi-extension packages.
            
            # Unpack!
            package = StringIO(file_data)
            
            err.push_state(data["name_lower"])
            

            # There are no expected types for packages within a multi-
            # item package.
            testendpoint_validator.test_package(err, package, name)
            err.tier = 2 # Reset to the current tier
            
            package.close()
            err.pop_state()
            
        elif data["extension"] in ("xul", "xml", "html", "xhtml"):
            
            parser = testendpoint_markup.MarkupParser(err)
            parser.process(name,
                           charsethelper.decode(file_data),
                           data["extension"])
            
            processed = True
#.........这里部分代码省略.........
开发者ID:nmaier,项目名称:amo-validator,代码行数:103,代码来源:content.py


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