Skip to content

Commit f812d1b

Browse files
committed
Support copy of UUIDLegacy
1 parent 822c7ee commit f812d1b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

bson/binary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def __new__(cls, obj):
214214
self.__uuid = obj
215215
return self
216216

217+
def __getnewargs__(self):
218+
# Support copy and deepcopy
219+
return (self.__uuid,)
220+
217221
@property
218222
def uuid(self):
219223
"""UUID instance wrapped by this UUIDLegacy instance.

test/test_binary.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Tests for the Binary wrapper."""
1616

1717
import base64
18+
import copy
1819
import pickle
1920
import sys
2021
import unittest
@@ -23,6 +24,7 @@
2324
should_test_uuid = True
2425
except ImportError:
2526
should_test_uuid = False
27+
2628
sys.path[0:0] = [""]
2729

2830
import bson
@@ -292,6 +294,15 @@ def test_pickle(self):
292294
for proto in xrange(pickle.HIGHEST_PROTOCOL + 1):
293295
self.assertEqual(b1, pickle.loads(pickle.dumps(b1, proto)))
294296

297+
if should_test_uuid:
298+
uu = uuid.uuid4()
299+
uul = UUIDLegacy(uu)
300+
301+
self.assertEqual(uul, copy.copy(uul))
302+
self.assertEqual(uul, copy.deepcopy(uul))
303+
304+
for proto in xrange(pickle.HIGHEST_PROTOCOL + 1):
305+
self.assertEqual(uul, pickle.loads(pickle.dumps(uul, proto)))
295306

296307
if __name__ == "__main__":
297308
unittest.main()

0 commit comments

Comments
 (0)