summaryrefslogtreecommitdiffstats
path: root/pyload/remote/json_converter.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-09-13 16:23:54 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-09-13 16:23:54 +0200
commit5854aca376058c4b98ee205ee44ac956ebe50e23 (patch)
tree9cf89cb8457c390f7fdf8140dff6910bfdfabeda /pyload/remote/json_converter.py
parentgzip files on build, disabled gzip middleware (diff)
downloadpyload-5854aca376058c4b98ee205ee44ac956ebe50e23.tar.xz
some fixes for py 2.5
Diffstat (limited to 'pyload/remote/json_converter.py')
-rw-r--r--pyload/remote/json_converter.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/pyload/remote/json_converter.py b/pyload/remote/json_converter.py
index df397e8ba..a7a0645ce 100644
--- a/pyload/remote/json_converter.py
+++ b/pyload/remote/json_converter.py
@@ -6,7 +6,6 @@ try:
except ImportError:
import json
-
import apitypes
from apitypes import BaseObject
from apitypes import ExceptionObject
@@ -16,10 +15,9 @@ separators = (',', ':')
# json encoder that accepts api objects
class BaseEncoder(json.JSONEncoder):
-
def default(self, o):
if isinstance(o, BaseObject) or isinstance(o, ExceptionObject):
- ret = {"@class" : o.__class__.__name__}
+ ret = {"@class": o.__class__.__name__}
for att in o.__slots__:
ret[att] = getattr(o, att)
return ret
@@ -28,26 +26,28 @@ class BaseEncoder(json.JSONEncoder):
# more compact representation, only clients with information of the classes can handle it
class BaseEncoderCompact(json.JSONEncoder):
-
def default(self, o):
if isinstance(o, BaseObject) or isinstance(o, ExceptionObject):
- ret = {"@compact" : [o.__class__.__name__]}
+ ret = {"@compact": [o.__class__.__name__]}
ret["@compact"].extend(getattr(o, attr) for attr in o.__slots__)
return ret
return json.JSONEncoder.default(self, o)
+
def convert_obj(dct):
if '@class' in dct:
cls = getattr(apitypes, dct['@class'])
del dct['@class']
- return cls(**dct)
+ # convert keywords to str, <=2.6 does not accept unicode
+ return cls(**dict((str(x) if type(x) == unicode else x, y) for x, y in dct.iteritems()))
elif '@compact' in dct:
cls = getattr(apitypes, dct['@compact'][0])
return cls(*dct['@compact'][1:])
return dct
+
def dumps(*args, **kwargs):
if 'compact' in kwargs and kwargs['compact']:
kwargs['cls'] = BaseEncoderCompact