示例#1
0
文件: views.py 项目: lissyx/zamboni
def app_view_manifest(request, addon):
    manifest = {}
    success = False
    headers = ''
    if addon.is_packaged:
        manifest = _get_manifest_json(addon)
        content = json.dumps(manifest, indent=4)
        success = True

    else:  # Show the hosted manifest_url.
        content, headers = u'', {}
        if addon.manifest_url:
            try:
                req = requests.get(addon.manifest_url, verify=False)
                content, headers = req.content, req.headers
                success = True
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))
            else:
                success = True

            try:
                # Reindent the JSON.
                manifest = json.loads(content)
                content = json.dumps(manifest, indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass

    return escape_all({'content': smart_decode(content),
                       'headers': dict(headers),
                       'success': success,
                       'permissions': _get_permissions(manifest)})
示例#2
0
def app_view_manifest(request, addon):
    if addon.is_packaged:
        version = addon.versions.latest()
        content = json.dumps(json.loads(_mini_manifest(addon, version.id)),
                             indent=4)
        return escape_all({'content': content, 'headers': ''})

    else:  # Show the hosted manifest_url.
        content, headers = u'', {}
        if addon.manifest_url:
            try:
                req = requests.get(addon.manifest_url, verify=False)
                content, headers = req.content, req.headers
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))

            try:
                # Reindent the JSON.
                content = json.dumps(json.loads(content), indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass
        return escape_all({
            'content': smart_decode(content),
            'headers': headers
        })
示例#3
0
def app_view_manifest(request, addon):
    manifest = {}
    success = False
    headers = ''
    if addon.is_packaged:
        manifest = _get_manifest_json(addon)
        content = json.dumps(manifest, indent=4)
        success = True

    else:  # Show the hosted manifest_url.
        content, headers = u'', {}
        if addon.manifest_url:
            try:
                req = requests.get(addon.manifest_url, verify=False)
                content, headers = req.content, req.headers
                success = True
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))
            else:
                success = True

            try:
                # Reindent the JSON.
                manifest = json.loads(content)
                content = json.dumps(manifest, indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass

    return escape_all({
        'content': smart_decode(content),
        'headers': dict(headers),
        'success': success,
        'permissions': _get_permissions(manifest)
    })
示例#4
0
def app_view_manifest(request, addon):
    if addon.is_packaged:
        version = addon.versions.latest()
        content = json.dumps(json.loads(_mini_manifest(addon, version.id)),
                             indent=4)
        return escape_all({'content': content, 'headers': '', 'success': True})

    else:  # Show the hosted manifest_url.
        content, headers, success = u'', {}, False
        if addon.manifest_url:
            try:
                req = requests.get(addon.manifest_url, verify=False)
                content, headers = req.content, req.headers
                success = True
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))

            try:
                # Reindent the JSON.
                content = json.dumps(json.loads(content), indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass
        return escape_all({'content': smart_decode(content),
                           'headers': headers,
                           'success': success})
示例#5
0
文件: views.py 项目: Sancus/zamboni
def app_view_manifest(request, addon):
    content, headers = u'', {}
    if addon.manifest_url:
        try:
            req = requests.get(addon.manifest_url, verify=False)
            content, headers = req.content, req.headers
        except Exception:
            content = u''.join(traceback.format_exception(*sys.exc_info()))

        try:
            # Reindent the JSON.
            content = json.dumps(json.loads(content), indent=4)
        except:
            # If it's not valid JSON, just return the content as is.
            pass
    return escape_all({'content': smart_decode(content), 'headers': headers})
示例#6
0
def app_view_manifest(request, addon):
    content, headers = u'', {}
    if addon.manifest_url:
        try:
            req = requests.get(addon.manifest_url, verify=False)
            content, headers = req.content, req.headers
        except Exception:
            content = u''.join(traceback.format_exception(*sys.exc_info()))

        try:
            # Reindent the JSON.
            content = json.dumps(json.loads(content), indent=4)
        except:
            # If it's not valid JSON, just return the content as is.
            pass
    return escape_all({'content': smart_decode(content), 'headers': headers})
示例#7
0
文件: views.py 项目: j-barron/zamboni
def app_view_manifest(request, addon):
    headers = {}
    manifest = {}
    success = False

    if addon.is_packaged:
        manifest = _get_manifest_json(addon)
        content = json.dumps(manifest, indent=4)
        success = True

    else:  # Show the hosted manifest_url.
        content, headers = u'', {}
        if addon.manifest_url:
            try:
                req = requests.get(
                    addon.manifest_url,
                    verify=False,
                    headers={'User-Agent': settings.MARKETPLACE_USER_AGENT})
                content, headers = req.content, req.headers
                success = True
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))
            else:
                success = True

            try:
                # Reindent the JSON.
                manifest = json.loads(content)
                content = json.dumps(manifest, indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass

    return {
        'content':
        jinja2.escape(smart_decode(content)),
        'headers':
        dict((jinja2.escape(k), jinja2.escape(v)) for k, v in headers.items()),
        'success':
        success,
        # Note: We're using `escape_all` on the values here since we know the
        # keys of the nested dict don't come from user input (manifest) and are
        # known safe.
        'permissions':
        dict((jinja2.escape(k), escape_all(v))
             for k, v in _get_permissions(manifest).items())
    }
示例#8
0
def app_view_manifest(request, addon):
    headers = {}
    manifest = {}
    success = False

    if addon.is_packaged:
        manifest = _get_manifest_json(addon)
        content = json.dumps(manifest, indent=4)
        success = True

    else:  # Show the hosted manifest_url.
        content, headers = u'', {}
        if addon.manifest_url:
            try:
                req = requests.get(
                    addon.manifest_url, verify=False,
                    headers={'User-Agent': settings.MARKETPLACE_USER_AGENT})
                content, headers = req.content, req.headers
                success = True
            except Exception:
                content = u''.join(traceback.format_exception(*sys.exc_info()))
            else:
                success = True

            try:
                # Reindent the JSON.
                manifest = json.loads(content)
                content = json.dumps(manifest, indent=4)
            except:
                # If it's not valid JSON, just return the content as is.
                pass

    return {
        'content': jinja2.escape(smart_decode(content)),
        'headers': dict((jinja2.escape(k), jinja2.escape(v))
                        for k, v in headers.items()),
        'success': success,
        # Note: We're using `escape_all` on the values here since we know the
        # keys of the nested dict don't come from user input (manifest) and are
        # known safe.
        'permissions': dict((jinja2.escape(k), escape_all(v))
                            for k, v in _get_permissions(manifest).items())
    }