mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-09-09 08:39:30 +00:00
Do not encode object property in utf8
This commit is contained in:
@@ -9,8 +9,8 @@ class SearpcError(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
class _SearpcObjProps(object):
|
class _SearpcObj(object):
|
||||||
'''A compact class to emulate gobject.GProps
|
'''A compact class to emulate gobject.GObject
|
||||||
'''
|
'''
|
||||||
def __init__(self, dicts):
|
def __init__(self, dicts):
|
||||||
new_dict = {}
|
new_dict = {}
|
||||||
@@ -18,29 +18,20 @@ class _SearpcObjProps(object):
|
|||||||
value = dicts[key]
|
value = dicts[key]
|
||||||
# replace hyphen with with underline
|
# replace hyphen with with underline
|
||||||
new_key = key.replace('-', '_')
|
new_key = key.replace('-', '_')
|
||||||
# encode all strings in UTF-8
|
|
||||||
if isinstance(value, unicode):
|
|
||||||
value = value.encode('utf-8')
|
|
||||||
new_dict[new_key] = value
|
new_dict[new_key] = value
|
||||||
|
# For compatibility with old usage peer.props.name
|
||||||
self._dicts = new_dict
|
self.props = self
|
||||||
|
self._dict = new_dict
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
try:
|
try:
|
||||||
return self._dicts[key]
|
return self._dict[key]
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class _SearpcObj(object):
|
|
||||||
'''A compact class to emulate gobject.GObject
|
|
||||||
'''
|
|
||||||
def __init__(self, dicts):
|
|
||||||
self.props = _SearpcObjProps(dicts)
|
|
||||||
|
|
||||||
|
|
||||||
def _fret_obj(ret_str):
|
def _fret_obj(ret_str):
|
||||||
try:
|
try:
|
||||||
dicts = json.loads(ret_str)
|
dicts = json.loads(ret_str)
|
||||||
except:
|
except:
|
||||||
raise SearpcError('Invalid response format')
|
raise SearpcError('Invalid response format')
|
||||||
|
|
||||||
@@ -51,11 +42,10 @@ def _fret_obj(ret_str):
|
|||||||
return _SearpcObj(dicts['ret'])
|
return _SearpcObj(dicts['ret'])
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _fret_objlist(ret_str):
|
def _fret_objlist(ret_str):
|
||||||
try:
|
try:
|
||||||
dicts = json.loads(ret_str)
|
dicts = json.loads(ret_str)
|
||||||
except:
|
except:
|
||||||
raise SearpcError('Invalid response format')
|
raise SearpcError('Invalid response format')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user