Skip to content

Commit b2eadf1

Browse files
author
Mike Dirolf
committed
only try importing uuid once
1 parent ef1807e commit b2eadf1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pymongo/bson.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
except ImportError:
3737
_use_c = False
3838

39+
try:
40+
import uuid
41+
_use_uuid = True
42+
except ImportError:
43+
_use_uuid = False
44+
3945

4046
def _get_int(data):
4147
try:
@@ -256,12 +262,8 @@ def _get_binary(data):
256262
if length2 != length - 4:
257263
raise InvalidBSON("invalid binary (st 2) - lengths don't match!")
258264
length = length2
259-
if subtype == 3:
260-
try:
261-
import uuid
262-
return (uuid.UUID(bytes=data[:length]), data[length:])
263-
except ImportError:
264-
pass
265+
if subtype == 3 and _use_uuid:
266+
return (uuid.UUID(bytes=data[:length]), data[length:])
265267
return (Binary(data[:length], subtype), data[length:])
266268

267269

0 commit comments

Comments
 (0)