本文整理汇总了Python中validator.chromemanifest.ChromeManifest类的典型用法代码示例。如果您正苦于以下问题:Python ChromeManifest类的具体用法?Python ChromeManifest怎么用?Python ChromeManifest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChromeManifest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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")
示例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'
示例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'))
示例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
示例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)
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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)
示例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,
)