Example #1
0
 def json(self, data):
     if isinstance(data, GeneratorType):
         out = ''.join([r for r in self.genstreamer(data)])
         return out
     thunker = JSONThunker()
     data = thunker.thunk(data)
     return json.dumps(data)
Example #2
0
 def encode(self, data):
     """
     encode data as json
     """
     encoder = JSONEncoder()
     thunker = JSONThunker()
     thunked = thunker.thunk(data)
     return encoder.encode(thunked)
Example #3
0
 def wrapper(self, data, expires, contentType="application/json+thunk"):
     data = func(self, data)
     try:
         thunker = JSONThunker()
         data = thunker.thunk(data)
         jsondata = json.dumps(data)
         _setCherryPyHeaders(jsondata, contentType, expires)
         return jsondata
     except Exception:
         raise
Example #4
0
 def decode(self, data):
     """
     decode the data to python from json
     """
     if data:
         decoder = JSONDecoder()
         thunker = JSONThunker()
         data = decoder.decode(data)
         unthunked = thunker.unthunk(data)
         return unthunked
     return {}
Example #5
0
 def decode(self, data):
     """
     decode the data to python from json
     """
     if data:
         decoder = JSONDecoder()
         thunker = JSONThunker()
         if sys.version_info[0] == 3:
             data = decodeBytesToUnicode(data)
         data = decoder.decode(data)
         unthunked = thunker.unthunk(data)
         return unthunked
     return {}
Example #6
0
    def jsonThunkerHandler(self, args, kwargs):

        args, kwargs = self.jsonHandler(args, kwargs)
        kwargs = JSONThunker().unthunk(kwargs)
        return args, kwargs
Example #7
0
 def setUp(self):
     self.thunker = JSONThunker()
Example #8
0
 def json(self, data):
     thunker = JSONThunker()
     data = thunker.thunk(data)
     return JsonWrapper.dumps(data)
Example #9
0
 def jsonThunkerDecoder(self, data):
     if data:
         thunker = JSONThunker()
         return thunker.unthunk(JsonWrapper.loads(data))
     else:
         return {}