secret
Created

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/metamagic/json/encoder.py b/metamagic/json/encoder.py
index 5c5c18a..200e954 100644
--- a/metamagic/json/encoder.py
+++ b/metamagic/json/encoder.py
@@ -37,6 +37,11 @@ BASE_ESCAPE_DCT.update({
ESCAPE_DCT = {'"': '\\"'}
ESCAPE_DCT.update(BASE_ESCAPE_DCT)
+try:
+ basestring = basestring
+except NameError:
+ basestring = str
+
class Encoder:
"""A Python implementation of a JSON encoder for Python objects designed
@@ -349,7 +354,7 @@ class Encoder:
if isinstance(obj, UUID):
return '"' + str(obj) + '"'
- if isinstance(obj, str):
+ if isinstance(obj, basestring):
return self._encode_str(obj)
if isinstance(obj, (list, tuple, set, frozenset, Set)):
@@ -370,7 +375,7 @@ class Encoder:
return self._encode(self.default(obj))
- def dumps(self, obj, *, max_nested_level=100):
+ def dumps(self, obj, max_nested_level=100):
"""Returns a string representing a JSON-encoding of ``obj``.
The second optional ``max_nested_level`` argument controls the maximum
@@ -381,7 +386,7 @@ class Encoder:
self._max_nested_level = max_nested_level
return self._encode(obj)
- def dumpb(self, obj, *, max_nested_level=100):
+ def dumpb(self, obj, max_nested_level=100):
"""Similar to ``dumps()``, but returns ``bytes`` instead of a ``string``"""
self._max_nested_level = max_nested_level
return self._encode(obj).encode('utf-8')

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.