Skip to content
Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:4e14145e03f9ba62baf3 secret

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
diff --git a/metamagic/json/ b/metamagic/json/
index 5c5c18a..200e954 100644
--- a/metamagic/json/
+++ b/metamagic/json/
@@ -37,6 +37,11 @@ BASE_ESCAPE_DCT.update({
ESCAPE_DCT = {'"': '\\"'}
+ 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
Something went wrong with that request. Please try again.