##// END OF EJS Templates
define deepcopy for memoryview...
Min RK -
Show More
@@ -1,10 +1,6 b''
1 1 """A Task logger that presents our DB interface,
2 2 but exists entirely in memory and implemented with dicts.
3 3
4 Authors:
5
6 * Min RK
7
8 4
9 5 TaskRecords are dicts of the form::
10 6
@@ -36,14 +32,17 b' DictDB supports a subset of mongodb operators::'
36 32
37 33 $lt,$gt,$lte,$gte,$ne,$in,$nin,$all,$mod,$exists
38 34 """
39 #-----------------------------------------------------------------------------
40 # Copyright (C) 2010-2011 The IPython Development Team
41 #
42 # Distributed under the terms of the BSD License. The full license is in
43 # the file COPYING, distributed as part of this software.
44 #-----------------------------------------------------------------------------
45
46 from copy import deepcopy as copy
35
36 # Copyright (c) IPython Development Team.
37 # Distributed under the terms of the Modified BSD License.
38
39 import copy
40 from copy import deepcopy
41
42 # Python can't copy memoryviews, but creating another memoryview works for us
43 copy._deepcopy_dispatch[memoryview] = lambda x, memo: memoryview(x)
44
45
47 46 from datetime import datetime
48 47
49 48 from IPython.config.configurable import LoggingConfigurable
@@ -146,7 +145,7 b' class DictDB(BaseDB):'
146 145
147 146 for rec in itervalues(self._records):
148 147 if self._match_one(rec, tests):
149 matches.append(copy(rec))
148 matches.append(deepcopy(rec))
150 149 return matches
151 150
152 151 def _extract_subdict(self, rec, keys):
@@ -155,7 +154,7 b' class DictDB(BaseDB):'
155 154 d['msg_id'] = rec['msg_id']
156 155 for key in keys:
157 156 d[key] = rec[key]
158 return copy(d)
157 return deepcopy(d)
159 158
160 159 # methods for monitoring size / culling history
161 160
@@ -225,7 +224,7 b' class DictDB(BaseDB):'
225 224 raise KeyError("Record %r has been culled for size" % msg_id)
226 225 if not msg_id in self._records:
227 226 raise KeyError("No such msg_id %r"%(msg_id))
228 return copy(self._records[msg_id])
227 return deepcopy(self._records[msg_id])
229 228
230 229 def update_record(self, msg_id, rec):
231 230 """Update the data in an existing record."""
General Comments 0
You need to be logged in to leave comments. Login now