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
34 lines (24 loc) · 1022 Bytes
/
copy_mode.py
File metadata and controls
34 lines (24 loc) · 1022 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
29
30
31
32
33
34
# Copyright 2009-2015 Ram Rachum.
# This program is distributed under the MIT license.
'''
This module defines the `CopyMode` class.
See its documentation for more information.
'''
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(object):
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__