def marshal(self, result, error, _id=None, version=VERSION_WITHOUT_CAPABILITIES): if error: assert isinstance(error, PublicError) error = dict( code=error.errno, message=error.strerror, data=error.kw, name=unicode(error.__class__.__name__), ) principal = getattr(context, 'principal', 'UNKNOWN') response = dict( result=result, error=error, id=_id, principal=unicode(principal), version=unicode(VERSION), ) dump = json_encode_binary(response, version, pretty_print=self.api.env.debug) return dump.encode('utf-8')
def to_json(dct, method=None): try: dct = json_encode_binary(dct) if method: dct['method'] = method result = json.dumps(dct, ensure_ascii=False, indent=2, sort_keys=True) return result.replace('\n', '\n ') except TypeError, e: class Bad(object): def __str__(self): raise e return Bad()
def marshal(self, result, error, _id=None): if error: assert isinstance(error, PublicError) error = dict( code=error.errno, message=error.strerror, name=unicode(error.__class__.__name__), ) principal = getattr(context, 'principal', 'UNKNOWN') response = dict( result=result, error=error, id=_id, principal=unicode(principal), version=unicode(VERSION), ) response = json_encode_binary(response) return json.dumps(response, sort_keys=True, indent=4)
def marshal(self, result, error, _id=None, version=VERSION_WITHOUT_CAPABILITIES): if error: assert isinstance(error, PublicError) error = dict( code=error.errno, message=error.strerror, data=error.kw, name=unicode(error.__class__.__name__), ) principal = getattr(context, 'principal', 'UNKNOWN') response = dict( result=result, error=error, id=_id, principal=unicode(principal), version=unicode(VERSION), ) response = json_encode_binary(response, version) return json.dumps(response, sort_keys=True, indent=4)
def marshal(self, result, error, _id=None, version=VERSION_WITHOUT_CAPABILITIES): if error: assert isinstance(error, PublicError) error = dict( code=error.errno, message=error.strerror, data=error.kw, name=unicode(error.__class__.__name__), ) principal = getattr(context, 'principal', 'UNKNOWN') response = dict( result=result, error=error, id=_id, principal=unicode(principal), version=unicode(VERSION), ) dump = json_encode_binary( response, version, pretty_print=self.api.env.debug ) return dump.encode('utf-8')