Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4e14145e03f9ba62baf3 to your computer and use it in GitHub Desktop.
Save anonymous/4e14145e03f9ba62baf3 to your computer and use it in GitHub Desktop.
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment