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