forked from cool-RR/python_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_mode.py
More file actions
28 lines (20 loc) · 870 Bytes
/
copy_mode.py
File metadata and controls
28 lines (20 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright 2009-2017 Ram Rachum.
# This program is distributed under the MIT license.
class CopyMode(dict):
'''
Passed as a memo to `deepcopy` to specify how objects should be copied.
This type is meant to be subclassed. `__deepcopy__` methods may check which
class the memo is to know what kind of deepcopying they should do.
Typical usage:
class NetworkStyleCopying(CopyMode): pass
class Something:
def __deepcopy__(self, memo):
if isinstance(memo, NetworkStlyeCopying):
# Do network-style copying, whatever that means.
else:
# Do normal copying.
s = Something()
new_copy = copy.deepcopy(s, NetworkStyleCopying())
# Now the new copy will be created using network style copying
'''
__repr__ = object.__repr__