Skip to content

Commit

Permalink
Fixed ujson support.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Jan 4, 2017
1 parent e8e74b4 commit df80adb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nmrstarlib/nmrstarlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import tarfile
from collections import OrderedDict

UJSON = False

if sys.version_info.major == 3 and sys.version_info.minor == 6:
try:
import ujson as json
Expand Down Expand Up @@ -387,11 +389,15 @@ def _is_json(string):
"""
try:
if isinstance(string, bytes):
# json_str = json.loads(string.decode("utf-8"), object_pairs_hook=OrderedDict)
json_str = json.loads(string.decode("utf-8"))
if UJSON:
json_str = json.loads(string.decode("utf-8"))
else:
json_str = json.loads(string.decode("utf-8"), object_pairs_hook=OrderedDict)
elif isinstance(string, str):
# json_str = json.loads(string, object_pairs_hook=OrderedDict)
json_str = json.loads(string)
if UJSON:
json_str = json.loads(string)
else:
json_str = json.loads(string, object_pairs_hook=OrderedDict)
else:
raise TypeError("Expecting <class 'str'> or <class 'bytes'>, but {} was passed".format(type(string)))
return json_str
Expand Down Expand Up @@ -514,7 +520,7 @@ def _generate_handles(filenames):
def read_files(*sources):
"""Construct a generator that yields :class:`~nmrstarlib.nmrstarlib.StarFile` instances.
:param list sources: List of strings representing path to file(s).
:param str sources: One or more strings representing path to file(s).
:return: :class:`~nmrstarlib.nmrstarlib.StarFile` instance(s).
:rtype: :class:`~nmrstarlib.nmrstarlib.StarFile`
"""
Expand Down

0 comments on commit df80adb

Please sign in to comment.