Exemple #1
0
 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')
Exemple #2
0
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 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()
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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')