• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xpi.XPIManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _do_test

def _do_test(path, test, failure=True,
             require_install=False, set_type=0,
             listed=False, xpi_mode="r"):

    package_data = open(path, "rb")
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource("listed", True)

    # Populate in the dependencies.
    if set_type:
        err.detected_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(err, rdf_data)
        err.save_resource("install_rdf", install_rdf)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
开发者ID:dimonov,项目名称:amo-validator,代码行数:31,代码来源:helper.py


示例2: _do_test

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,代码行数:27,代码来源:helper.py


示例3: test_bad_file

def test_bad_file():
    """Tests that the XPI manager correctly reports a bad XPI file."""
    try:
        x = XPIManager(get_path("junk.xpi"))
    except BadZipfile:
        pass
    x = XPIManager(get_path("corrupt.xpi"))
    assert x.test()
开发者ID:robhudson,项目名称:amo-validator,代码行数:8,代码来源:test_xpimanager.py


示例4: test_bad_file

def test_bad_file():
    "Tests that the XPI manager correctly reports a bad XPI file."
    
    x = XPIManager("tests/resources/junk.xpi")
    assert not x.zf
    
    x = XPIManager("tests/resources/corrupt.xpi")
    assert x.test()
开发者ID:nmaier,项目名称:amo-validator,代码行数:8,代码来源:test_xpimanager.py


示例5: test_get_list

def test_get_list():
    """Test that the manager can read the file listing."""
    z = XPIManager(get_path('xpi/install_rdf_only.xpi'))
    assert not z.contents_cache
    assert z.package_contents()
    assert z.contents_cache  # Spelling check!
    z.contents_cache = 'foo'
    eq_(z.package_contents(), 'foo')
开发者ID:Archaeopteryx,项目名称:amo-validator,代码行数:8,代码来源:test_xpimanager.py


示例6: test_get_list

def test_get_list():
    "Test that the manager can read the file listing"

    z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
    assert not z.contents_cache
    assert z.package_contents()
    assert z.contents_cache  # Spelling check!
    z.contents_cache = "foo"
    eq_(z.package_contents(), "foo")
开发者ID:clouserw,项目名称:amo-validator,代码行数:9,代码来源:test_xpimanager.py


示例7: test_bad_file

def test_bad_file():
    "Tests that the XPI manager correctly reports a bad XPI file."

    try:
        x = XPIManager("tests/resources/junk.xpi")
    except zipfile.BadZipfile:
        pass

    x = XPIManager("tests/resources/corrupt.xpi")
    assert x.test()
开发者ID:krupa,项目名称:amo-validator,代码行数:10,代码来源:test_xpimanager.py


示例8: test_write_file

def test_write_file():
    """Test that a file can be written in UTF-8 to the package."""
    with tempfile.NamedTemporaryFile(delete=False) as t:
        temp_fn = t.name
        try:
            z = XPIManager(temp_fn, mode='w')
            f, d = 'install.rdf', '注目のコレクション'.decode('utf-8')
            z.write(f, d)
            eq_(z.read(f), d.encode('utf-8'))
        finally:
            os.unlink(temp_fn)
开发者ID:Archaeopteryx,项目名称:amo-validator,代码行数:11,代码来源:test_xpimanager.py


示例9: clean_xpifile

 def clean_xpifile(self):
     "Make sure that the uploaded file is a valid XPI file."
     xpifile = self.cleaned_data['xpifile']
     if xpifile:
         try:
             xpi = XPIManager(xpifile, name=xpifile.name)
             if xpi.test():
                 raise
         except:
             raise forms.ValidationError(_("File doesn't seem to be valid XPI"))
     return xpifile
开发者ID:rmoorman,项目名称:transifex-adofex,代码行数:11,代码来源:forms.py


示例10: test_blacklisted_files

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,代码行数:15,代码来源:test_libraryblacklist.py


示例11: test_package

def test_package(err, file_, name, expectation=PACKAGE_ANY,
                 for_appversions=None):
    "Begins tests for the package."

    # Load up a new instance of an XPI.
    try:
        package = XPIManager(file_, mode="r", name=name)
    except:
        # 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():
        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)")

    # Test the install.rdf file to see if we can get the type that way.
    has_install_rdf = "install.rdf" in package
    if has_install_rdf:
        _load_install_rdf(err, package, expectation)

    try:
        output = test_inner_package(err, package, for_appversions)
    except ValidationTimeout as ex:
        err.error(
                err_id=("main", "test_package", "timeout"),
                error="Validation timed out",
                description=["The validation process took too long to "
                             "complete. Contact an addons.mozilla.org editor "
                             "for more information.",
                             str(ex)])
        output = None

    return output
开发者ID:andymckay,项目名称:amo-validator,代码行数:48,代码来源:submain.py


示例12: _test_type

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,代码行数:21,代码来源:test_typedetection.py


示例13: test_package

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,代码行数:38,代码来源:submain.py


示例14: _test_type

def _test_type(file_, expectation, failure=False):
    'Tests a file against the expectations'

    err = ErrorBundle(None, True)
    package = XPIManager(open(file_), mode='r', name=file_)
    contents = package.package_contents()

    # 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(err, install_file)

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

    assert results == expectation
    if not failure:
        assert not err.failed()
    else:
        assert err.failed()

    return err
开发者ID:kewisch,项目名称:amo-validator,代码行数:23,代码来源:test_typedetection.py


示例15: _do_test

def _do_test(path, test, failure=True,
             require_install=False, set_type=0,
             listed=False, xpi_mode='r'):

    package_data = open(path, 'rb')
    package = XPIManager(package_data, mode=xpi_mode, name=path)
    err = ErrorBundle()
    if listed:
        err.save_resource('listed', True)

    # Populate in the dependencies.
    if set_type:
        err.detected_type = set_type # Conduit test requires type
    if require_install:
        if 'install.rdf' in package:
            err.save_resource('has_install_rdf', True)
            rdf_data = package.read('install.rdf')
            install_rdf = RDFParser(err, rdf_data)
            err.save_resource('install_rdf', install_rdf)
        elif 'manifest.json' in package:
            err.save_resource('has_manifest_json', True)
            manifest_data = package.read('manifest.json')
            manifest_json = ManifestJsonParser(err, manifest_data)
            err.save_resource('install_rdf', manifest_json)

    populate_chrome_manifest(err, package)

    test(err, package)

    print err.print_summary(verbose=True)

    if failure:
        assert err.failed()
    else:
        assert not err.failed()

    return err
开发者ID:diox,项目名称:amo-validator,代码行数:37,代码来源:helper.py


示例16: test_package

def test_package(err, file_, name, expectation=PACKAGE_ANY,
                 for_appversions=None):
    "Begins tests for the package."

    # Load up a new instance of an XPI.
    try:
        package = XPIManager(file_, mode="r", name=name)
    except:
        # 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():
        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)")

    # Test the install.rdf file to see if we can get the type that way.
    has_install_rdf = "install.rdf" in package
    if has_install_rdf:
        _load_install_rdf(err, package, expectation)

    return test_inner_package(err, package, for_appversions)
开发者ID:clouserw,项目名称:amo-validator,代码行数:36,代码来源:submain.py


示例17: test_packed_packages

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,代码行数:101,代码来源:content.py


示例18: test_read_file

def test_read_file():
    """Test that a file can be read from the package."""
    z = XPIManager(get_path('xpi/install_rdf_only.xpi'))
    assert z.read('install.rdf') is not None
开发者ID:Archaeopteryx,项目名称:amo-validator,代码行数:4,代码来源:test_xpimanager.py


示例19: test_valid_name

def test_valid_name():
    "Test that the manager can retrieve the correct file name."
    z = XPIManager(get_path('xpi/install_rdf_only.xpi'))
    contents = z.package_contents()
    assert 'install.rdf' in contents
开发者ID:Archaeopteryx,项目名称:amo-validator,代码行数:5,代码来源:test_xpimanager.py


示例20: test_get_list

def test_get_list():
    "Test that the manager can read the file listing"
    z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
    assert z.package_contents()
开发者ID:krupa,项目名称:amo-validator,代码行数:4,代码来源:test_xpimanager.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python validators.url函数代码示例发布时间:2022-05-26
下一篇:
Python validate.validate函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap