Example #1
0
 def test_convert_dict_nested_dict_to_str(self):
     f1 = r(10)
     f2 = r(10)
     foo = {"foo": f1, "data": {"f2": f2}}
     expected1 = "\"foo\": \""+f1+"\""
     expected2 = "\"data\": {\"f2\": \""+f2+"\"}"
     target = cloud.convert_obj_to_str(foo)
     self.assertTrue(expected1 in target)
     self.assertTrue(expected2 in target)
Example #2
0
 def test_convert_obj_to_str(self):
     foo1 = r(10)
     foo2 = r(10)
     f1 = Foo(foo1)
     f2 = Foo(foo2)
     ret = '{"foo": "'+foo1+'"}'
     ret1 = '{"foo": "'+foo2+'"}'
     target = cloud.convert_obj_to_str([f1, f2])
     self.assertIn(ret, target)
     self.assertIn(ret1, target)
Example #3
0
 def test_convert_iter_obj_to_str(self):
     foo1 = r(10)
     foo2 = r(10)
     foo = r(5)
     f = Foo(foo1)
     f2 = Foo(foo2)
     d = dict()
     d[r(5)] = f
     d[r(5)] = f2
     ret = '"foo": "'+foo+'"'
     ret1 = '"foo": "'+foo1+'"'
     data = {"foo": foo, "data": d.values()}
     target = cloud.convert_obj_to_str(data)
     self.assertIn(ret, target)
     self.assertIn(ret1, target)
Example #4
0
    def get_formated_data(self, data):
        if type(data) != str:
            data = convert_obj_to_str(data)

        length = len(data)
        newFrame = []
        newFrame.append(0x81)
        newFrame = bytearray(newFrame)
        if length <= 125:
            newFrame.append(length)
        elif length > 125 and length < 65536:
            newFrame.append(126)
            newFrame += struct.pack('!H', length)
        elif length >= 65536:
            newFrame.append(127)
            newFrame += struct.pack('!Q', length)

        newFrame += data.encode()
        return newFrame
Example #5
0
 def __test_convert_dict_to_str(self):
     foo = r(10)
     f = Foo(foo)
     ret = '{"foo": "'+foo+'"}'
     self.assertIn(ret, cloud.convert_obj_to_str(f))
Example #6
0
 def parse_response(self, data):
     if not data:
         return ""
     if type(data) == str:
         return data
     return convert_obj_to_str(data)