PYTHON-708 Support $undefined and $numberLong extended JSON types.
This commit is contained in:
parent
5136bb723c
commit
35c7445a67
@ -89,6 +89,7 @@ except ImportError:
|
||||
|
||||
from bson import EPOCH_AWARE, RE_TYPE, SON
|
||||
from bson.binary import Binary
|
||||
from bson.bsonint64 import BSONInt64
|
||||
from bson.code import Code
|
||||
from bson.dbref import DBRef
|
||||
from bson.max_key import MaxKey
|
||||
@ -193,6 +194,10 @@ def object_hook(dct, compile_re=True):
|
||||
return Code(dct["$code"], dct.get("$scope"))
|
||||
if "$uuid" in dct:
|
||||
return uuid.UUID(dct["$uuid"])
|
||||
if "$undefined" in dct:
|
||||
return None
|
||||
if "$numberLong" in dct:
|
||||
return BSONInt64(dct["$numberLong"])
|
||||
return dct
|
||||
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import uuid
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
from bson import json_util
|
||||
from bson.bsonint64 import BSONInt64
|
||||
from bson.binary import Binary, MD5_SUBTYPE, USER_DEFINED_SUBTYPE
|
||||
from bson.code import Code
|
||||
from bson.dbref import DBRef
|
||||
@ -202,6 +203,15 @@ class TestJsonUtil(unittest.TestCase):
|
||||
# Check order.
|
||||
self.assertEqual('{"$code": "return z", "$scope": {"z": 2}}', res)
|
||||
|
||||
def test_undefined(self):
|
||||
json = '{"name": {"$undefined": true}}'
|
||||
self.assertIsNone(json_util.loads(json)['name'])
|
||||
|
||||
def test_numberlong(self):
|
||||
json = '{"weight": {"$numberLong": 65535}}'
|
||||
self.assertEqual(json_util.loads(json)['weight'],
|
||||
BSONInt64(65535))
|
||||
|
||||
|
||||
class TestJsonUtilRoundtrip(IntegrationTest):
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user