diff options
| author | Adrian Torres <adt@odoo.com> | 2018-11-08 15:03:33 +0000 |
|---|---|---|
| committer | Adrian Torres <adt@odoo.com> | 2018-11-29 09:28:17 +0000 |
| commit | 758382b3a73da024d6e1dc04a474d2868223767a (patch) | |
| tree | e37ea57fb6efabf9a14d30b39a74af664ddd1ed3 /doc/_extensions | |
| parent | 52f5528cfb6d1152ee226e268247dc685a8ba329 (diff) | |
[REM] pycompat: remove python 2 shims and helpers
Odoo no longer supports python 2, thus some of these helpers can and
have been replaced by python 3 built-ins, therefore there is no need for
them to stay defined.
The removed helpers are:
* izip, imap and ifilter
* unichr, text_type
* implements_to_string, implements_iterator
* string_types, integer_types
* to_native
The python 2 shims have also been removed, and only the python 3 helpers
have been kept, because they can still be usable (i.e. accepting
both bytes and str for functions that can only accept one of the two)
[REM] pyjsparser: remove PY3 shims
They're no longer necessary as Odoo doesn't officially support python 2
anymore.
closes odoo/odoo#28519
Diffstat (limited to 'doc/_extensions')
| -rw-r--r-- | doc/_extensions/pyjsparser/parser.py | 38 | ||||
| -rw-r--r-- | doc/_extensions/pyjsparser/pyjsparserdata.py | 24 |
2 files changed, 24 insertions, 38 deletions
diff --git a/doc/_extensions/pyjsparser/parser.py b/doc/_extensions/pyjsparser/parser.py index 28001886a8e..d47a94a8522 100644 --- a/doc/_extensions/pyjsparser/parser.py +++ b/doc/_extensions/pyjsparser/parser.py @@ -27,16 +27,8 @@ __all__ = ['PyJsParser', 'parse', 'ENABLE_JS2PY_ERRORS', 'ENABLE_PYIMPORT', 'JsS REGEXP_SPECIAL_SINGLE = ('\\', '^', '$', '*', '+', '?', '.', '[', ']', '(', ')', '{', '{', '|', '-') ENABLE_PYIMPORT = False ENABLE_JS2PY_ERRORS = False - -PY3 = sys.version_info >= (3,0) - -if PY3: - basestring = str - long = int - xrange = range - unicode = str - ESPRIMA_VERSION = '2.2.0' + DEBUG = False # Small naming convention changes # len -> leng @@ -179,7 +171,7 @@ class PyJsParser: def scanHexEscape(self, prefix): code = 0 leng = 4 if (prefix == 'u') else 2 - for i in xrange(leng): + for i in range(leng): if self.index < self.length and isHexDigit(self.source[self.index]): ch = self.source[self.index] self.index += 1 @@ -442,7 +434,7 @@ class PyJsParser: def isImplicitOctalLiteral(self): # Implicit octal, unless there is a non-octal digit. # (Annex B.1.1 on Numeric Literals) - for i in xrange(self.index + 1, self.length): + for i in range(self.index + 1, self.length): ch = self.source[i]; if (ch == '8' or ch == '9'): return False; @@ -992,20 +984,20 @@ class PyJsParser: except: raise Exception("ENABLE_JS2PY_ERRORS was set to True, but Js2Py was not found!") ENABLE_PYIMPORT = old_pyimport - error = ERRORS['SyntaxError']('Line ' + unicode(line) + ': ' + unicode(description)) + error = ERRORS['SyntaxError']('Line ' + str(line) + ': ' + str(description)) error.put('index', Js(pos)) error.put('lineNumber', Js(line)) error.put('column', Js(pos - (self.lineStart if self.scanning else self.lastLineStart) + 1)) error.put('description', Js(description)) return JsToPyException(error) else: - return JsSyntaxError('Line ' + unicode(line) + ': ' + unicode(description)) + return JsSyntaxError('Line ' + str(line) + ': ' + str(description)) # Throw an exception def throwError(self, messageFormat, *args): - msg = messageFormat % tuple(unicode(e) for e in args) + msg = messageFormat % tuple(str(e) for e in args) raise self.createError(self.lastLineNumber, self.lastIndex, msg); def tolerateError(self, messageFormat, *args): @@ -1038,7 +1030,7 @@ class PyJsParser: value = token['value']['raw'] if (typ == Token.Template) else token.get('value') else: value = 'ILLEGAL' - msg = msg.replace('%s', unicode(value)) + msg = msg.replace('%s', str(value)) return (self.createError(token['lineNumber'], token['start'], msg) if (token and token.get('lineNumber')) else self.createError(self.lineNumber if self.scanning else self.lastLineNumber, @@ -1445,12 +1437,12 @@ class PyJsParser: self.reinterpretExpressionAsPattern(expr.argument) elif typ == Syntax.ArrayExpression: expr['type'] = Syntax.ArrayPattern - for i in xrange(len(expr['elements'])): + for i in range(len(expr['elements'])): if (expr['elements'][i] != null): self.reinterpretExpressionAsPattern(expr['elements'][i]) elif typ == Syntax.ObjectExpression: expr['type'] = Syntax.ObjectPattern - for i in xrange(len(expr['properties'])): + for i in range(len(expr['properties'])): self.reinterpretExpressionAsPattern(expr['properties'][i]['value']); elif Syntax.AssignmentExpression: expr['type'] = Syntax.AssignmentPattern; @@ -1526,7 +1518,7 @@ class PyJsParser: if (not self.match('=>')): self.expect('=>'); self.isBindingElement = false - for i in xrange(len(expressions)): + for i in range(len(expressions)): self.reinterpretExpressionAsPattern(expressions[i]) return { 'type': PlaceHolders.ArrowParameterPlaceHolder, @@ -1539,7 +1531,7 @@ class PyJsParser: if (not self.isBindingElement): self.throwUnexpectedToken(self.lookahead); if (expr['type'] == Syntax.SequenceExpression): - for i in xrange(len(expr.expressions)): + for i in range(len(expr.expressions)): self.reinterpretExpressionAsPattern(expr['expressions'][i]) else: self.reinterpretExpressionAsPattern(expr); @@ -1880,12 +1872,12 @@ class PyJsParser: elif typ == Syntax.AssignmentPattern: self.checkPatternParam(options, param.left) elif typ == Syntax.ArrayPattern: - for i in xrange(len(param.elements)): + for i in range(len(param.elements)): if (param.elements[i] != null): self.checkPatternParam(options, param.elements[i]); else: assert typ == Syntax.ObjectPattern, 'Invalid type' - for i in xrange(len(param.properties)): + for i in range(len(param.properties)): self.checkPatternParam(options, param.properties[i]['value']); def reinterpretAsCoverFormalsList(self, expr): @@ -1902,7 +1894,7 @@ class PyJsParser: options = { 'paramSet': {}} le = len(params) - for i in xrange(le): + for i in range(le): param = params[i] if param.type == Syntax.AssignmentPattern: params[i] = param.left; @@ -2870,7 +2862,7 @@ class PyJsParser: raise NotImplementedError('Options not implemented! You can only use default settings.') self.clean() - self.source = unicode(code) + ' \n ; //END' # I have to add it in order not to check for EOF every time + self.source = str(code) + ' \n ; //END' # I have to add it in order not to check for EOF every time self.index = 0 self.lineNumber = 1 if len(self.source) > 0 else 0 self.lineStart = 0 diff --git a/doc/_extensions/pyjsparser/pyjsparserdata.py b/doc/_extensions/pyjsparser/pyjsparserdata.py index 6ca6dbc47cc..5db295a34b5 100644 --- a/doc/_extensions/pyjsparser/pyjsparserdata.py +++ b/doc/_extensions/pyjsparser/pyjsparserdata.py @@ -23,12 +23,6 @@ import sys import unicodedata from collections import defaultdict -PY3 = sys.version_info >= (3,0) - -if PY3: - unichr = chr - xrange = range - unicode = str token = { 'BooleanLiteral': 1, @@ -221,7 +215,7 @@ LS = u'\u2028' PS = u'\u2029' U_CATEGORIES = defaultdict(list) -for c in map(unichr, range(sys.maxunicode + 1)): +for c in map(chr, range(sys.maxunicode + 1)): U_CATEGORIES[unicodedata.category(c)].append(c) UNICODE_LETTER = set(U_CATEGORIES['Lu']+U_CATEGORIES['Ll']+ U_CATEGORIES['Lt']+U_CATEGORIES['Lm']+ @@ -242,33 +236,33 @@ WHITE_SPACE = set((0x20, 0x09, 0x0B, 0x0C, 0xA0, 0x1680, LINE_TERMINATORS = set((0x0A, 0x0D, 0x2028, 0x2029)) def isIdentifierStart(ch): - return (ch if isinstance(ch, unicode) else unichr(ch)) in IDENTIFIER_START + return (ch if isinstance(ch, str) else chr(ch)) in IDENTIFIER_START def isIdentifierPart(ch): - return (ch if isinstance(ch, unicode) else unichr(ch)) in IDENTIFIER_PART + return (ch if isinstance(ch, str) else chr(ch)) in IDENTIFIER_PART def isWhiteSpace(ch): - return (ord(ch) if isinstance(ch, unicode) else ch) in WHITE_SPACE + return (ord(ch) if isinstance(ch, str) else ch) in WHITE_SPACE def isLineTerminator(ch): - return (ord(ch) if isinstance(ch, unicode) else ch) in LINE_TERMINATORS + return (ord(ch) if isinstance(ch, str) else ch) in LINE_TERMINATORS OCTAL = set(('0', '1', '2', '3', '4', '5', '6', '7')) DEC = set(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) HEX = set('0123456789abcdefABCDEF') -HEX_CONV = dict(('0123456789abcdef'[n],n) for n in xrange(16)) +HEX_CONV = dict(('0123456789abcdef'[n],n) for n in range(16)) for i,e in enumerate('ABCDEF', 10): HEX_CONV[e] = i def isDecimalDigit(ch): - return (ch if isinstance(ch, unicode) else unichr(ch)) in DEC + return (ch if isinstance(ch, str) else chr(ch)) in DEC def isHexDigit(ch): - return (ch if isinstance(ch, unicode) else unichr(ch)) in HEX + return (ch if isinstance(ch, str) else chr(ch)) in HEX def isOctalDigit(ch): - return (ch if isinstance(ch, unicode) else unichr(ch)) in OCTAL + return (ch if isinstance(ch, str) else chr(ch)) in OCTAL def isFutureReservedWord(w): return w in ('enum', 'export', 'import', 'super') |
