Skip to content

Commit

Permalink
Remove Python 2 support for utils/json.py
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Gattis <[email protected]>
  • Loading branch information
BryceGattis committed Mar 3, 2024
1 parent 9c8de33 commit 7607198
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions src/rez/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,7 @@

import json
from json import dumps # noqa (forwarded)
import sys


if sys.version_info.major >= 3:

def loads(data):
return json.loads(data)

# py2
else:

def loads(json_text):
"""Avoids returning unicodes in py2.
https://stackoverflow.com/questions/956867/how-to-get-string-objects-instead-of-unicode-from-json
"""
def _byteify(input, ignore_dicts=False):
if isinstance(input, list):
return [_byteify(x) for x in input]
elif isinstance(input, unicode):
try:
return str(input)
except UnicodeEncodeError:
return input
elif isinstance(input, dict) and not ignore_dicts:
return {
_byteify(k, ignore_dicts=True): _byteify(v, True)
for k, v in input.items()
}
else:
return input

return _byteify(json.loads(json_text, object_hook=_byteify))
def loads(data):
return json.loads(data)

0 comments on commit 7607198

Please sign in to comment.