Пример #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}),
Пример #2
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}),
Пример #3
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
Пример #4
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())
Пример #5
0
'''
Created on 08/feb/2012

@author: fede
'''
from restfs.utils.bson import BSON
from restfs.utils.bson import Binary
from restfs.utils.bson import ObjectId
from restfs.utils.bson import Code
from restfs.utils.bson import DBRef
import unittest

BSON.encode({"test": u"hello world"})
print BSON.encode({})


class TestBSON(unittest.TestCase):
    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}),
                             "\x0F\x00\x00\x00\x10\x6D\x69\x6B\x65\x00\x64\x00\x00"
Пример #6
0
'''
Created on 08/feb/2012

@author: fede
'''
from restfs.utils.bson import BSON
from restfs.utils.bson import Binary
from restfs.utils.bson import ObjectId
from restfs.utils.bson import Code
from restfs.utils.bson import DBRef
import unittest


BSON.encode({"test": u"hello world"})
print BSON.encode({})

class TestBSON(unittest.TestCase):
    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}),
                             "\x0F\x00\x00\x00\x10\x6D\x69\x6B\x65\x00\x64\x00\x00"
                             "\x00\x00")
Пример #7
0
def dumps(obj):
      
        #FIX ADD BSON
        print 'ENCODE',obj
        bobj = BSON.encode(obj)
        return bobj
Пример #8
0
def dumps(obj):

    #FIX ADD BSON
    print 'ENCODE', obj
    bobj = BSON.encode(obj)
    return bobj