Skip to content

Commit f6ce79c

Browse files
committed
get \$type working
1 parent 632f277 commit f6ce79c

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/unified_format.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import traceback
2626
import types
2727

28-
from bson import json_util, SON, Int64
28+
from bson import json_util, Code, Decimal128, DBRef, SON, Int64, MaxKey, MinKey
2929
from bson.binary import Binary
3030
from bson.objectid import ObjectId
31-
from bson.py3compat import abc, integer_types, iteritems, text_type
31+
from bson.py3compat import abc, integer_types, iteritems, text_type, PY3
3232
from bson.regex import Regex, RE_TYPE
3333

3434
from gridfs import GridFSBucket
@@ -286,22 +286,39 @@ def get_lsid_for_session(self, session_name):
286286
return self._session_lsids[session_name]
287287

288288

289+
if not PY3:
290+
binary_types = (Binary,)
291+
long_types = (Int64, long)
292+
unicode_types = (unicode,)
293+
else:
294+
binary_types = (Binary, bytes)
295+
long_types = (Int64,)
296+
unicode_types = (str,)
297+
298+
289299
BSON_TYPE_ALIAS_MAP = {
290300
# https://docs.mongodb.com/manual/reference/operator/query/type/
291301
# https://pymongo.readthedocs.io/en/stable/api/bson/index.html
292302
'double': (float,),
293303
'string': (text_type,),
294304
'object': (abc.Mapping,),
295305
'array': (abc.MutableSequence,),
296-
'binData': (Binary, bytes),
306+
'binData': binary_types,
307+
'undefined': (type(None),),
297308
'objectId': (ObjectId,),
298309
'bool': (bool,),
299310
'date': (datetime.datetime,),
300311
'null': (type(None),),
301312
'regex': (Regex, RE_TYPE),
313+
'dbPointer': (DBRef,),
314+
'javascript': (*unicode_types, Code),
315+
'symbol': unicode_types,
316+
'javascriptWithScope': (*unicode_types, Code),
302317
'int': (int,),
303-
'long': (Int64,)
304-
# TODO: add all supported types
318+
'long': (Int64,),
319+
'decimal': (Decimal128,),
320+
'maxKey': (MaxKey,),
321+
'minKey': (MinKey,),
305322
}
306323

307324

0 commit comments

Comments
 (0)