Exemplo n.º 1
0
 def test_func(self):
     lexer = JsLexer()
     result = [
         "%s %s" % (name, tok) for name, tok in lexer.lex(input)
         if name != 'ws'
     ]
     self.assertListEqual(result, toks)
Exemplo n.º 2
0
    def __init__(self, zip_file, data='', certinfo=None):
        self.zip_file = zip_file
        self.certinfo = certinfo

        if not data:
            data = zip_file.read('manifest.json')

        lexer = JsLexer()

        json_string = ''

        # Run through the JSON and remove all comments, then try to read
        # the manifest file.
        # Note that Firefox and the WebExtension spec only allow for
        # line comments (starting with `//`), not block comments (starting with
        # `/*`). We strip out both in AMO because the linter will flag the
        # block-level comments explicitly as an error (so the developer can
        # change them to line-level comments).
        #
        # But block level comments are not allowed. We just flag them elsewhere
        # (in the linter).
        for name, token in lexer.lex(data):
            if name not in ('blockcomment', 'linecomment'):
                json_string += token

        self.data = decode_json(json_string)
Exemplo n.º 3
0
    def __init__(self, path, data=''):
        self.path = path

        if not data:
            with open(path) as fobj:
                data = fobj.read()

        lexer = JsLexer()

        json_string = ''

        # Run through the JSON and remove all comments, then try to read
        # the manifest file.
        # Note that Firefox and the WebExtension spec only allow for
        # line comments (starting with `//`), not block comments (starting with
        # `/*`). We strip out both in AMO because the linter will flag the
        # block-level comments explicitly as an error (so the developer can
        # change them to line-level comments).
        #
        # But block level comments are not allowed. We just flag them elsewhere
        # (in the linter).
        for name, token in lexer.lex(data):
            if name not in ('blockcomment', 'linecomment'):
                json_string += token

        self.data = json.loads(unicodehelper.decode(json_string))
Exemplo n.º 4
0
    def __init__(self, zip_file, data='', certinfo=None):
        self.zip_file = zip_file
        self.certinfo = certinfo

        if not data:
            data = zip_file.read('manifest.json')

        lexer = JsLexer()

        json_string = ''

        # Run through the JSON and remove all comments, then try to read
        # the manifest file.
        # Note that Firefox and the WebExtension spec only allow for
        # line comments (starting with `//`), not block comments (starting with
        # `/*`). We strip out both in AMO because the linter will flag the
        # block-level comments explicitly as an error (so the developer can
        # change them to line-level comments).
        #
        # But block level comments are not allowed. We just flag them elsewhere
        # (in the linter).
        for name, token in lexer.lex(data):
            if name not in ('blockcomment', 'linecomment'):
                json_string += token

        self.data = decode_json(json_string)
Exemplo n.º 5
0
    def __init__(self, zip_file, data='', certinfo=None):
        self.zip_file = zip_file
        self.certinfo = certinfo

        if not data:
            data = zip_file.read('manifest.json')

        # Remove BOM if present.
        data = unicodehelper.decode(data)

        # Run through the JSON and remove all comments, then try to read
        # the manifest file.
        # Note that Firefox and the WebExtension spec only allow for
        # line comments (starting with `//`), not block comments (starting with
        # `/*`). We strip out both in AMO because the linter will flag the
        # block-level comments explicitly as an error (so the developer can
        # change them to line-level comments).
        #
        # But block level comments are not allowed. We just flag them elsewhere
        # (in the linter).
        json_string = ''
        lexer = JsLexer()
        for name, token in lexer.lex(data):
            if name not in ('blockcomment', 'linecomment'):
                json_string += token

        try:
            self.data = json.loads(json_string)
        except Exception:
            raise InvalidManifest(
                gettext('Could not parse the manifest file.'))
Exemplo n.º 6
0
    def __init__(self, path, data=''):
        self.path = path

        if not data:
            with open(self.path) as fobj:
                data = fobj.read()

        lexer = JsLexer()

        json_string = ''

        # Run through the JSON and remove all comments, then try to read
        # the manifest file.
        # Note that Firefox and the WebExtension spec only allow for
        # line comments (starting with `//`), not block comments (starting with
        # `/*`). We strip out both in AMO because the linter will flag the
        # block-level comments explicitly as an error (so the developer can
        # change them to line-level comments).
        #
        # But block level comments are not allowed. We just flag them elsewhere
        # (in the linter).
        for name, token in lexer.lex(data):
            if name not in ('blockcomment', 'linecomment'):
                json_string += token

        self.data = json.loads(unicodehelper.decode(json_string))
Exemplo n.º 7
0
 def test_func(self):
     lexer = JsLexer()
     result = ["%s %s" % (name, tok) for name, tok in lexer.lex(input) if name != "ws"]
     self.assertListEqual(result, toks)