예제 #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 JsonWrapper.dumps(data)
예제 #2
0
class testThunking(unittest.TestCase):
    """
    Direct tests of thunking standard python type
    """
    def setUp(self):
        self.thunker = JSONThunker()

    def roundTrip(self, data):
        encoded = self.thunker.thunk(data)
        decoded = self.thunker.unthunk(encoded)
        self.assertEqual( data, decoded )

    @runboth
    def testStr(self):
        self.roundTrip('hello')

    @runboth
    def testList(self):
        self.roundTrip([123, 456])

    @runboth
    def testDict(self):
        self.roundTrip({'abc':123, 'def':456})
        self.roundTrip({'abc':123, 456:'def'})

    @runboth
    def testSet(self):
        self.roundTrip(set([]))
        self.roundTrip(set([123, 'abc']))
예제 #3
0
class testJSONThunker(unittest.TestCase):
    """
    Direct tests of thunking standard python type
    """
    def setUp(self):
        self.thunker = JSONThunker()

    def roundTrip(self, data):
        encoded = self.thunker.thunk(data)
        decoded = self.thunker.unthunk(encoded)
        self.assertEqual(data, decoded)

    def testStr(self):
        self.roundTrip('hello')

    def testList(self):
        self.roundTrip([123, 456])

    def testDict(self):
        self.roundTrip({'abc': 123, 'def': 456})
        self.roundTrip({'abc': 123, 456: 'def'})

    def testSet(self):
        self.roundTrip(set([]))
        self.roundTrip(set([123, 'abc']))
예제 #4
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)
예제 #5
0
 def encode(self, data):
     """
     encode data as json
     """
     encoder = JSONEncoder()
     thunker = JSONThunker()
     thunked = thunker.thunk(data)
     return encoder.encode(thunked)
예제 #6
0
 def encode(self, data):
     """
     encode data as json
     """
     encoder = JSONEncoder()
     thunker = JSONThunker()
     thunked = thunker.thunk(data)
     return encoder.encode(thunked)
예제 #7
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
예제 #8
0
파일: Page.py 프로젝트: amaltaro/WMCore
 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
예제 #9
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 {}
예제 #10
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
     else:
         return {}
예제 #11
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 {}
예제 #12
0
 def jsonThunkerDecoder(self, data):
     if data:
         thunker = JSONThunker()
         return thunker.unthunk(JsonWrapper.loads(data))
     else:
         return {}
예제 #13
0
    def jsonThunkerHandler(self, args, kwargs):

        args, kwargs = self.jsonHandler(args, kwargs)
        kwargs = JSONThunker().unthunk(kwargs)
        return args, kwargs
예제 #14
0
 def json(self, data):
     thunker = JSONThunker()
     data = thunker.thunk(data)
     return JsonWrapper.dumps(data)
예제 #15
0
 def setUp(self):
     self.thunker = JSONThunker()
예제 #16
0
 def setUp(self):
     self.thunker = JSONThunker()
예제 #17
0
 def jsonThunkerDecoder(self, data):
     if data:
         thunker = JSONThunker()
         return thunker.unthunk(JsonWrapper.loads(data))
     else:
         return {}
예제 #18
0
 def json(self, data):
     thunker = JSONThunker()
     data = thunker.thunk(data)
     return JsonWrapper.dumps(data)