Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3 code migration fixes #563

Open
wants to merge 2 commits into
base: py3-code-migration
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions splunklib/searchcommands/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from collections import deque, namedtuple
from collections import OrderedDict
from itertools import chain
from json import JSONDecoder, JSONEncoder
from json import JSONDecoder, JSONEncoder, dumps
from json.encoder import encode_basestring_ascii as json_encode_string


Expand Down Expand Up @@ -662,32 +662,19 @@ def _write_record(self, record):
if self.pending_record_count >= self._maxresultrows:
self.flush(partial=True)

try:
# noinspection PyUnresolvedReferences
from _json import make_encoder
except ImportError:
# We may be running under PyPy 2.5 which does not include the _json module
_iterencode_json = JSONEncoder(separators=(',', ':')).iterencode
else:
from json.encoder import encode_basestring_ascii

@staticmethod
def _default(o):
raise TypeError(repr(o) + ' is not JSON serializable')

_iterencode_json = make_encoder(
{}, # markers (for detecting circular references)
_default, # object_encoder
encode_basestring_ascii, # string_encoder
None, # indent
':', ',', # separators
False, # sort_keys
False, # skip_keys
True # allow_nan
@staticmethod
def _iterencode_json(obj, indent_level=0):
def _default(serialized_obj):
raise TypeError(repr(serialized_obj) + ' is not JSON serializable')

return dumps(
obj,
separators=(',', ':'),
default=_default,
ensure_ascii=True,
indent=indent_level
)

del make_encoder


class RecordWriterV1(RecordWriter):

Expand Down
Loading