--- ansible_mitogen/compat/simplejson/decoder.py.orig 2019-11-02 17:59:13 UTC +++ ansible_mitogen/compat/simplejson/decoder.py @@ -56,8 +56,8 @@ _CONSTANTS = { STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS) BACKSLASH = { - '"': u'"', '\\': u'\\', '/': u'/', - 'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t', + '"': '"', '\\': '\\', '/': '/', + 'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t', } DEFAULT_ENCODING = "utf-8" @@ -85,8 +85,8 @@ def py_scanstring(s, end, encoding=None, strict=True, content, terminator = chunk.groups() # Content is contains zero or more unescaped string characters if content: - if not isinstance(content, unicode): - content = unicode(content, encoding) + if not isinstance(content, str): + content = str(content, encoding) _append(content) # Terminator is the end of string, a literal control character, # or a backslash denoting that an escape sequence follows @@ -132,11 +132,11 @@ def py_scanstring(s, end, encoding=None, strict=True, uni2 = int(esc2, 16) uni = 0x10000 + (((uni - 0xd800) << 10) | (uni2 - 0xdc00)) next_end += 6 - char = unichr(uni) + char = chr(uni) end = next_end # Append the unescaped character _append(char) - return u''.join(chunks), end + return ''.join(chunks), end # Use speedup if available @@ -145,7 +145,8 @@ scanstring = c_scanstring or py_scanstring WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS) WHITESPACE_STR = ' \t\n\r' -def JSONObject((s, end), encoding, strict, scan_once, object_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR): +def JSONObject(xxx_todo_changeme, encoding, strict, scan_once, object_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR): + (s, end) = xxx_todo_changeme pairs = {} # Use a slice to prevent IndexError from being raised, the following # check will raise a more specific ValueError if the string is empty @@ -220,7 +221,8 @@ def JSONObject((s, end), encoding, strict, scan_once, pairs = object_hook(pairs) return pairs, end -def JSONArray((s, end), scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR): +def JSONArray(xxx_todo_changeme1, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR): + (s, end) = xxx_todo_changeme1 values = [] nextchar = s[end:end + 1] if nextchar in _ws: --- ansible_mitogen/compat/simplejson/encoder.py.orig 2019-11-02 17:59:13 UTC +++ ansible_mitogen/compat/simplejson/encoder.py @@ -184,7 +184,7 @@ class JSONEncoder(object): """ # This is for extremely simple cases and benchmarks. - if isinstance(o, basestring): + if isinstance(o, str): if isinstance(o, str): _encoding = self.encoding if (_encoding is not None @@ -261,18 +261,15 @@ class JSONEncoder(object): def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot, ## HACK: hand-optimized bytecode; turn globals into locals - False=False, - True=True, ValueError=ValueError, - basestring=basestring, + str=str, dict=dict, float=float, id=id, int=int, isinstance=isinstance, list=list, - long=long, - str=str, + long=int, tuple=tuple, ): @@ -300,7 +297,7 @@ def _make_iterencode(markers, _default, _encoder, _ind first = False else: buf = separator - if isinstance(value, basestring): + if isinstance(value, str): yield buf + _encoder(value) elif value is None: yield buf + 'null' @@ -308,7 +305,7 @@ def _make_iterencode(markers, _default, _encoder, _ind yield buf + 'true' elif value is False: yield buf + 'false' - elif isinstance(value, (int, long)): + elif isinstance(value, int): yield buf + str(value) elif isinstance(value, float): yield buf + _floatstr(value) @@ -349,12 +346,12 @@ def _make_iterencode(markers, _default, _encoder, _ind item_separator = _item_separator first = True if _sort_keys: - items = dct.items() + items = list(dct.items()) items.sort(key=lambda kv: kv[0]) else: - items = dct.iteritems() + items = iter(dct.items()) for key, value in items: - if isinstance(key, basestring): + if isinstance(key, str): pass # JavaScript is weakly typed for these, so it makes sense to # also allow them. Many encoders seem to do something like this. @@ -366,7 +363,7 @@ def _make_iterencode(markers, _default, _encoder, _ind key = 'false' elif key is None: key = 'null' - elif isinstance(key, (int, long)): + elif isinstance(key, int): key = str(key) elif _skipkeys: continue @@ -378,7 +375,7 @@ def _make_iterencode(markers, _default, _encoder, _ind yield item_separator yield _encoder(key) yield _key_separator - if isinstance(value, basestring): + if isinstance(value, str): yield _encoder(value) elif value is None: yield 'null' @@ -386,7 +383,7 @@ def _make_iterencode(markers, _default, _encoder, _ind yield 'true' elif value is False: yield 'false' - elif isinstance(value, (int, long)): + elif isinstance(value, int): yield str(value) elif isinstance(value, float): yield _floatstr(value) @@ -407,7 +404,7 @@ def _make_iterencode(markers, _default, _encoder, _ind del markers[markerid] def _iterencode(o, _current_indent_level): - if isinstance(o, basestring): + if isinstance(o, str): yield _encoder(o) elif o is None: yield 'null' @@ -415,7 +412,7 @@ def _make_iterencode(markers, _default, _encoder, _ind yield 'true' elif o is False: yield 'false' - elif isinstance(o, (int, long)): + elif isinstance(o, int): yield str(o) elif isinstance(o, float): yield _floatstr(o)