File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change 51
51
import calendar
52
52
import datetime
53
53
import re
54
+ import uuid
54
55
55
56
from pymongo .dbref import DBRef
56
57
from pymongo .max_key import MaxKey
@@ -89,6 +90,8 @@ def object_hook(dct):
89
90
return MinKey ()
90
91
if "$maxKey" in dct :
91
92
return MaxKey ()
93
+ if "$uuid" in dct :
94
+ return uuid .UUID (dct ["$uuid" ])
92
95
return dct
93
96
94
97
@@ -118,4 +121,6 @@ def default(obj):
118
121
return {"$maxKey" : 1 }
119
122
if isinstance (obj , Timestamp ):
120
123
return {"t" : obj .time , "i" : obj .inc }
124
+ if isinstance (obj , uuid .UUID ):
125
+ return {"$uuid" : obj .hex }
121
126
raise TypeError ("%r is not JSON serializable" % obj )
Original file line number Diff line number Diff line change 18
18
import datetime
19
19
import re
20
20
import sys
21
+ import uuid
21
22
json_lib = True
22
23
try :
23
24
import json
@@ -88,5 +89,8 @@ def test_timestamp(self):
88
89
self .assertEqual (dct ['ts' ]['t' ], 4 )
89
90
self .assertEqual (dct ['ts' ]['i' ], 13 )
90
91
92
+ def test_uuid (self ):
93
+ self .round_trip ({'uuid' : uuid .UUID ('f47ac10b-58cc-4372-a567-0e02b2c3d479' )})
94
+
91
95
if __name__ == "__main__" :
92
96
unittest .main ()
You can’t perform that action at this time.
0 commit comments