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

Python chromemanifest.ChromeManifest类代码示例

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

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



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

示例1: _get_locales

def _get_locales(err, xpi_package):
    "Returns a list of locales from the chrome.manifest file."
    
    # Retrieve the chrome.manifest if it's cached.
    if err is not None and \
       err.get_resource("chrome.manifest"): # pragma: no cover
        chrome = err.get_resource("chrome.manifest")
    else:
        chrome_data = xpi_package.read("chrome.manifest")
        chrome = ChromeManifest(chrome_data)
        if err is not None:
            err.save_resource("chrome.manifest", chrome)
        
    pack_locales = chrome.get_triples("locale")
    locales = {}
    # Find all of the locales referenced in the chrome.manifest file.
    for locale in pack_locales:
        locale_jar = locale["object"].split()

        location = locale_jar[-1]
        if not location.startswith("jar:"):
            continue
        full_location = location[4:].split("!")
        locale_desc = {"predicate": locale["predicate"],
                       "path": full_location[0],
                       "target": full_location[1],
                       "name": locale_jar[0]}
        locale_name = "%s:%s" % (locale["predicate"], locale_jar[0])
        if locale_name not in locales:
            locales[locale_name] = locale_desc
    
    return locales
开发者ID:nmaier,项目名称:amo-validator,代码行数:32,代码来源:l10ncompleteness.py


示例2: test_reverse_lookup

def test_reverse_lookup():
    """Test that the chrome reverse lookup function works properly."""

    c = ChromeManifest("""
    content ns1 /dir1/
    content ns2 /dir2/foo/
    content nsbad1 /dir3
    content ns3 jar:foo.jar!/subdir1/
    content ns3 jar:zap.jar!/altdir1/
    content ns4 jar:bar.jar!/subdir2
    """, "chrome.manifest")

    eq_(c.reverse_lookup(MockPackStack(), "random.js"), None)
    eq_(c.reverse_lookup(MockPackStack(), "/dir1/x.js"),
        "chrome://ns1/x.js")
    eq_(c.reverse_lookup(MockPackStack(), "/dir2/x.js"), None)
    eq_(c.reverse_lookup(MockPackStack(), "/dir2/foo/x.js"),
        "chrome://ns2/x.js")
    eq_(c.reverse_lookup(MockPackStack(), "/dir3/x.js"),
        "chrome://nsbad1/x.js")
    eq_(c.reverse_lookup(MockPackStack(["foo.jar"]), "/x.js"),
        "chrome://ns3/subdir1/x.js")
    eq_(c.reverse_lookup(MockPackStack(["foo.jar"]), "/zap/x.js"),
        "chrome://ns3/subdir1/zap/x.js")
    eq_(c.reverse_lookup(MockPackStack(["bar.jar"]), "/x.js"),
        "chrome://ns4/subdir2/x.js")
    eq_(c.reverse_lookup(MockPackStack(["zap.jar"]), "/x.js"),
        "chrome://ns3/altdir1/x.js")
开发者ID:clouserw,项目名称:amo-validator,代码行数:28,代码来源:test_chromemanifest.py


示例3: test_reverse_lookup

def test_reverse_lookup():
    """Test that the chrome reverse lookup function works properly."""

    c = ChromeManifest("""
    content ns1 /dir1/
    content ns2 /dir2/foo/
    content nsbad1 /dir3
    content ns3 jar:foo.jar!/subdir1/
    content ns3 jar:zap.jar!/altdir1/
    content ns4 jar:bar.jar!/subdir2
    """, 'chrome.manifest')

    assert c.reverse_lookup(MockPackStack(), 'random.js') is None
    assert c.reverse_lookup(MockPackStack(),
                            '/dir1/x.js') == 'chrome://ns1/x.js'
    assert c.reverse_lookup(MockPackStack(), '/dir2/x.js') is None
    assert c.reverse_lookup(MockPackStack(),
                            '/dir2/foo/x.js') == 'chrome://ns2/x.js'
    assert c.reverse_lookup(MockPackStack(),
                            '/dir3/x.js') == 'chrome://nsbad1/x.js'
    assert c.reverse_lookup(MockPackStack(['foo.jar']),
                            '/x.js') == 'chrome://ns3/subdir1/x.js'
    assert c.reverse_lookup(MockPackStack(['foo.jar']),
                            '/zap/x.js') == 'chrome://ns3/subdir1/zap/x.js'
    assert c.reverse_lookup(MockPackStack(['bar.jar']),
                            '/x.js') == 'chrome://ns4/subdir2/x.js'
    assert c.reverse_lookup(MockPackStack(['zap.jar']),
                            '/x.js') == 'chrome://ns3/altdir1/x.js'
开发者ID:AutomatedTester,项目名称:amo-validator,代码行数:28,代码来源:test_chromemanifest.py


示例4: _list_locales

def _list_locales(err, xpi_package=None):
    'Returns a raw list of locales from chrome.manifest'

    chrome = None
    if xpi_package is not None:
        # Handle a reference XPI
        chrome = ChromeManifest(xpi_package, 'chrome.manifest', err)
    else:
        # Handle the current XPI
        chrome = err.get_resource('chrome.manifest')
    if not chrome:
        return None

    return list(chrome.get_entries('locale'))
开发者ID:kmaglione,项目名称:amo-validator,代码行数:14,代码来源:l10ncompleteness.py


示例5: test_duplicate_subjects

def test_duplicate_subjects():
    """Test that two triplets with the same subject can be retrieved."""

    c = ChromeManifest("""
    foo bar abc
    foo bar def
    foo bam test
    oof rab cba
    """, "chrome.manifest")

    assert len(list(c.get_triples(subject="foo"))) == 3
    assert len(list(c.get_triples(subject="foo", predicate="bar"))) == 2
    assert len(list(c.get_triples(subject="foo",
                                  predicate="bar",
                                  object_="abc"))) == 1
开发者ID:clouserw,项目名称:amo-validator,代码行数:15,代码来源:test_chromemanifest.py


示例6: test_lines

def test_lines():
    """Test that the correct line numbers are given in a chrome.manifest."""

    c = ChromeManifest("""
    zero foo bar
    one bar foo
    two abc def
    #comment
    four def abc
    """.strip(), "chrome.manifest")

    eq_(list(c.get_triples(subject="zero"))[0]["line"], 1)
    eq_(list(c.get_triples(subject="one"))[0]["line"], 2)
    eq_(list(c.get_triples(subject="two"))[0]["line"], 3)
    eq_(list(c.get_triples(subject="four"))[0]["line"], 5)
开发者ID:clouserw,项目名称:amo-validator,代码行数:15,代码来源:test_chromemanifest.py


示例7: test_duplicate_subjects

def test_duplicate_subjects():
    """Test that two triplets with the same subject can be retrieved."""

    c = ChromeManifest("""
    foo bar abc
    foo bar def
    foo bam test
    oof rab cba
    """, 'chrome.manifest')

    assert len(list(c.get_triples(subject='foo'))) == 3
    assert len(list(c.get_triples(subject='foo', predicate='bar'))) == 2
    assert len(list(c.get_triples(subject='foo',
                                  predicate='bar',
                                  object_='abc'))) == 1
开发者ID:AutomatedTester,项目名称:amo-validator,代码行数:15,代码来源:test_chromemanifest.py


示例8: _list_locales

def _list_locales(err, xpi_package=None):
    "Returns a raw list of locales from chrome.manifest"

    chrome = None
    if xpi_package is not None:
        # Handle a reference XPI
        chrome = ChromeManifest(xpi_package.read("chrome.manifest"), "chrome.manifest")
    else:
        # Handle the current XPI
        chrome = err.get_resource("chrome.manifest")
    if not chrome:
        return None

    pack_locales = chrome.get_triples("locale")
    return list(pack_locales)
开发者ID:robhudson,项目名称:amo-validator,代码行数:15,代码来源:l10ncompleteness.py


示例9: test_lines

def test_lines():
    """Test that the correct line numbers are given in a chrome.manifest."""

    c = ChromeManifest("""
    zero foo bar
    one bar foo
    two abc def
    #comment
    four def abc
    """.strip(), 'chrome.manifest')

    assert list(c.get_triples(subject='zero'))[0]['line'] == 1
    assert list(c.get_triples(subject='one'))[0]['line'] == 2
    assert list(c.get_triples(subject='two'))[0]['line'] == 3
    assert list(c.get_triples(subject='four'))[0]['line'] == 5
开发者ID:AutomatedTester,项目名称:amo-validator,代码行数:15,代码来源:test_chromemanifest.py


示例10: test_open

def test_open():
    """Open a chrome file and ensure that data can be pulled from it."""

    xpi = MockXPI({
        'chrome.manifest': 'tests/resources/chromemanifest/chrome.manifest'})

    manifest = ChromeManifest(xpi, 'chrome.manifest')
    assert manifest is not None

    g_obj = list(manifest.get_entries('subject', 'predicate'))

    assert len(g_obj) == 1
    assert g_obj[0]['args'][1] == 'object'

    sub_locale = list(manifest.get_entries('locale'))
    assert len(sub_locale) == 2
开发者ID:kmaglione,项目名称:amo-validator,代码行数:16,代码来源:test_chromemanifest.py


示例11: get_translation_xpi

def get_translation_xpi(request, project_slug, lang_code):
    """ Compile project's XPI in given language
    """
    project = get_object_or_404(Project, slug=project_slug)
    language = get_object_or_404(Language, code=lang_code)
    xpi = get_object_or_404(XpiFile, project=project)

    zip_orig = zipfile.ZipFile(os.path.join(settings.XPI_DIR,xpi.filename), "r")

    zip_buffer = StringIO()
    zip_file = zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED)

    # copy all the contents from original file except META-INF,
    # to make it unsigned
    for item in zip_orig.infolist():
        if not (item.filename.startswith('META-INF') or
                item.filename == 'chrome.manifest'):
            fn = item.filename
            data = zip_orig.read(item.filename)
            zip_file.writestr(item, data)

    # write our localization
    for resource in Resource.objects.filter(project=project):
        template = _compile_translation_template(resource, language)
        zip_file.writestr("tx-locale/%s/%s" % (lang_code, resource.name), template)

    chrome_str = zip_orig.read("chrome.manifest")
    manifest = ChromeManifest(chrome_str, "manifest")

    zip_file.writestr("chrome.manifest", chrome_str +\
        "\nlocale %(predicate)s %(code)s tx-locale/%(code)s/\n" % {
            'predicate': list(manifest.get_triples("locale"))[0]['predicate'],
            'code': lang_code,
        })

    zip_file.close()
    zip_buffer.flush()
    zip_contents = zip_buffer.getvalue()

    response = HttpResponse(mimetype='application/x-xpinstall')
    response['Content-Disposition'] = 'filename=%s.xpi' % project_slug
    response.write(zip_contents)
    return response
开发者ID:AntoineTurmel,项目名称:adofex,代码行数:43,代码来源:views.py


示例12: test_overlay_object

def test_overlay_object():
    """Test that overlay instructions have all its properties."""

    err = ErrorBundle()
    c = ChromeManifest("""
    content namespace /foo/bar
    overlay namespace /uri/goes/here
    """, "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    c.get_applicable_overlays(err)
    assert not err.failed()
    assert not err.notices

    err = ErrorBundle()
    c = ChromeManifest("""
    content namespace /foo/bar
    overlay /uri/goes/here
    """, "chrome.manifest")
    err.save_resource("chrome.manifest", c)
    c.get_applicable_overlays(err)
    assert err.failed()
    assert not err.notices
开发者ID:Archaeopteryx,项目名称:amo-validator,代码行数:22,代码来源:test_chromemanifest.py


示例13: test_open

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


示例14: populate_chrome_manifest

def populate_chrome_manifest(err, xpi_package):
    "Loads the chrome.manifest if it's present"

    if 'chrome.manifest' in xpi_package:
        chrome_data = xpi_package.read('chrome.manifest')
        chrome = ChromeManifest(chrome_data, 'chrome.manifest')

        chrome_recursion_buster = set()

        # Handle the case of manifests linked from the manifest.
        def get_linked_manifest(path, from_path, from_chrome, from_triple):

            if path in chrome_recursion_buster:
                err.warning(
                    err_id=('submain', 'populate_chrome_manifest',
                            'recursion'),
                    warning='Linked manifest recursion detected.',
                    description='A chrome registration file links back to '
                                'itself. This can cause a multitude of '
                                'issues.',
                    filename=path)
                return

            # Make sure the manifest is properly linked
            if path not in xpi_package:
                err.notice(
                    err_id=('submain', 'populate_chrome_manifest', 'linkerr'),
                    notice='Linked manifest could not be found.',
                    description=('A linked manifest file could not be found '
                                 'in the package.',
                                 'Path: %s' % path),
                    filename=from_path,
                    line=from_triple['line'],
                    context=from_chrome.context)
                return

            chrome_recursion_buster.add(path)

            manifest = ChromeManifest(xpi_package.read(path), path)
            for triple in manifest.triples:
                yield triple

                if triple['subject'] == 'manifest':
                    subpath = triple['predicate']
                    # If the path is relative, make it relative to the current
                    # file.
                    if not subpath.startswith('/'):
                        subpath = '%s/%s' % (
                            '/'.join(path.split('/')[:-1]), subpath)

                    subpath = subpath.lstrip('/')

                    for subtriple in get_linked_manifest(
                            subpath, path, manifest, triple):
                        yield subtriple

            chrome_recursion_buster.discard(path)

        chrome_recursion_buster.add('chrome.manifest')

        # Search for linked manifests in the base manifest.
        for extra_manifest in chrome.get_triples(subject='manifest'):
            # When one is found, add its triples to our own.
            for triple in get_linked_manifest(extra_manifest['predicate'],
                                              'chrome.manifest', chrome,
                                              extra_manifest):
                chrome.triples.append(triple)

        chrome_recursion_buster.discard('chrome.manifest')

        # Create a reference so we can get the chrome manifest later, but make
        # it pushable so we don't run chrome manifests in JAR files.
        err.save_resource('chrome.manifest', chrome, pushable=True)
        # Create a non-pushable reference for tests that need to access the
        # chrome manifest from within JAR files.
        err.save_resource('chrome.manifest_nopush', chrome, pushable=False)
开发者ID:AutomatedTester,项目名称:amo-validator,代码行数:76,代码来源:submain.py


示例15: test_conduittoolbar

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


示例16: populate_chrome_manifest

def populate_chrome_manifest(err, xpi_package):
    "Loads the chrome.manifest if it's present"

    if "chrome.manifest" in xpi_package:
        chrome_data = xpi_package.read("chrome.manifest")
        chrome = ChromeManifest(chrome_data, "chrome.manifest")

        chrome_recursion_buster = set()

        # Handle the case of manifests linked from the manifest.
        def get_linked_manifest(path, from_path, from_chrome, from_triple):

            if path in chrome_recursion_buster:
                err.warning(
                    err_id=("submain", "populate_chrome_manifest",
                            "recursion"),
                    warning="Linked manifest recursion detected.",
                    description="A chrome registration file links back to "
                                "itself. This can cause a multitude of "
                                "issues.",
                    filename=path)
                return

            # Make sure the manifest is properly linked
            if path not in xpi_package:
                err.notice(
                    err_id=("submain", "populate_chrome_manifest", "linkerr"),
                    notice="Linked manifest could not be found.",
                    description=["A linked manifest file could not be found "
                                 "in the package.",
                                 "Path: %s" % path],
                    filename=from_path,
                    line=from_triple["line"],
                    context=from_chrome.context)
                return

            chrome_recursion_buster.add(path)

            manifest = ChromeManifest(xpi_package.read(path), path)
            for triple in manifest.triples:
                yield triple

                if triple["subject"] == "manifest":
                    for subtriple in get_linked_manifest(
                            triple["predicate"], path, manifest, triple):
                        yield subtriple

            chrome_recursion_buster.discard(path)

        chrome_recursion_buster.add("chrome.manifest")

        # Search for linked manifests in the base manifest.
        for extra_manifest in chrome.get_triples(subject="manifest"):
            # When one is found, add its triples to our own.
            for triple in get_linked_manifest(extra_manifest["predicate"],
                                              "chrome.manifest", chrome,
                                              extra_manifest):
                chrome.triples.append(triple)

        chrome_recursion_buster.discard("chrome.manifest")

        # Create a reference so we can get the chrome manifest later, but make
        # it pushable so we don't run chrome manifests in JAR files.
        err.save_resource("chrome.manifest", chrome, pushable=True)
        # Create a non-pushable reference for tests that need to access the
        # chrome manifest from within JAR files.
        err.save_resource("chrome.manifest_nopush", chrome, pushable=False)
开发者ID:clouserw,项目名称:amo-validator,代码行数:67,代码来源:submain.py


示例17: __init__

    def __init__(self, filename, project=None, release=None, name=None):
        """
        Fills in a list of locales from the chrome.manifest file.
        """
        Bundle.__init__(self, project, release)
        self.xpi = XPIManager(filename, name=name)
         # here we will store managers for jarfiles
        self.jarfiles = {}
        chrome = ChromeManifest(self.xpi.read("chrome.manifest"), "manifest")
        locales = list(chrome.get_triples("locale"))

        if not locales:
            return None

        # read the list
        for locale in locales:
            code, location = locale["object"].split()

            # finding out the language of the locale
            try:
                lang = self._get_lang(code)
            except Language.DoesNotExist:
                self.log("Locale %s SKIPPED" % code, "font-weight:bold")
                continue

            # Locales can be bundled in JARs
            jarred = location.startswith("jar:")
            if jarred:
                # We just care about the JAR path
                location = location[4:]
                split_location = location.split("!", 2)
                # Ignore malformed JAR URIs.
                if len(split_location) < 2:
                    continue
                jarname, location = split_location

                # missing file mentioned
                if jarname not in self.xpi:
                    continue
                # may be we have already read this one
                if jarname in self.jarfiles:
                    package = self.jarfiles[jarname]
                else:
                    jar = StringIO(self.xpi.read(jarname))
                    package = XPIManager(jar, mode="r", name=jarname)
            else:
                package = self.xpi

            # and now we read files from there
            location = location.strip('/')
            result = {}
            for f in package.package_contents():
                f = f.strip("/")
                if f.startswith(location) and f != location:
                    result[f.split("/")[-1]] = package.read(f)

            # file with same name in different jars can get overwritten
            if lang not in self.locales:
                self.locales[lang] = result
            else:
                self.locales[lang].update(result)
开发者ID:rmoorman,项目名称:transifex-adofex,代码行数:61,代码来源:bundle.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python decorator.version_range函数代码示例发布时间:2022-05-26
下一篇:
Python validator.Validator类代码示例发布时间: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