File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 8989
9090from  bson  import  EPOCH_AWARE , RE_TYPE , SON 
9191from  bson .binary  import  Binary 
92+ from  bson .bsonint64  import  BSONInt64 
9293from  bson .code  import  Code 
9394from  bson .dbref  import  DBRef 
9495from  bson .max_key  import  MaxKey 
@@ -193,6 +194,10 @@ def object_hook(dct, compile_re=True):
193194        return  Code (dct ["$code" ], dct .get ("$scope" ))
194195    if  "$uuid"  in  dct :
195196        return  uuid .UUID (dct ["$uuid" ])
197+     if  "$undefined"  in  dct :
198+         return  None 
199+     if  "$numberLong"  in  dct :
200+         return  BSONInt64 (dct ["$numberLong" ])
196201    return  dct 
197202
198203
Original file line number Diff line number Diff line change 2222sys .path [0 :0 ] =  ["" ]
2323
2424from  bson  import  json_util 
25+ from  bson .bsonint64  import  BSONInt64 
2526from  bson .binary  import  Binary , MD5_SUBTYPE , USER_DEFINED_SUBTYPE 
2627from  bson .code  import  Code 
2728from  bson .dbref  import  DBRef 
@@ -202,6 +203,15 @@ def test_code(self):
202203        # Check order. 
203204        self .assertEqual ('{"$code": "return z", "$scope": {"z": 2}}' , res )
204205
206+     def  test_undefined (self ):
207+         json  =  '{"name": {"$undefined": true}}' 
208+         self .assertIsNone (json_util .loads (json )['name' ])
209+ 
210+     def  test_numberlong (self ):
211+         json  =  '{"weight": {"$numberLong": 65535}}' 
212+         self .assertEqual (json_util .loads (json )['weight' ],
213+                          BSONInt64 (65535 ))
214+ 
205215
206216class  TestJsonUtilRoundtrip (IntegrationTest ):
207217
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments