Exemple #1
0
    def test_basic_encode(self):
        self.assertRaises(TypeError, BSON.encode, 100)
        self.assertRaises(TypeError, BSON.encode, "hello")
        self.assertRaises(TypeError, BSON.encode, None)
        self.assertRaises(TypeError, BSON.encode, [])

        self.assertEqual(BSON.encode({}), BSON("\x05\x00\x00\x00\x00"))
        self.assertEqual(
            BSON.encode({"test": u"hello world"}),
            "\x1B\x00\x00\x00\x02\x74\x65\x73\x74\x00\x0C\x00\x00"
            "\x00\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64\x00"
            "\x00")
        '''self.assertEqual(BSON.encode({u"mike": 100}),
Exemple #2
0
def loads(data):
    """
        This differs from the Python implementation, in that it returns
        the request structure in Dict format instead of the method, params.
        It will return a list in the case of a batch request / response.
        """
    if data == '':
        # notification
        return None
    #result = jloads(data)
    result = BSON(data).decode()
    print 'RES', result
    # if the above raises an error, the implementing server code
    # should return something like the following:
    # { 'jsonrpc':'2.0', 'error': fault.error(), id: None }
    #if config.use_jsonclass == True:
    #    from jsonrpclib import jsonclass
    #    result = jsonclass.load(result)
    return result
Exemple #3
0
 def test_basic_decode(self):
     self.assertEqual({"test": u"hello world"},
                      BSON("\x1B\x00\x00\x00\x0E\x74\x65\x73\x74\x00\x0C"
                           "\x00\x00\x00\x68\x65\x6C\x6C\x6F\x20\x77\x6F"
                           "\x72\x6C\x64\x00\x00").decode())