Commit 435ff9a3 authored by Chris McDonough's avatar Chris McDonough

made keys() method return a *copy* of the cached keys list, preventing...

made keys() method return a *copy* of the cached keys list, preventing mutations of the cached keys list that could cause later problems.  (Collector 2283).
parent 226cf5a2
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
__doc__='''Python implementation of persistent base types __doc__='''Python implementation of persistent base types
$Id: PersistentMapping.py,v 1.8 2000/04/21 20:06:34 jim Exp $''' $Id: PersistentMapping.py,v 1.9 2001/06/05 18:45:33 chrism Exp $'''
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import Persistence import Persistence
import types import types
...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent): ...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent):
return map(lambda k, d=self: (k,d[k]), self.keys()) return map(lambda k, d=self: (k,d[k]), self.keys())
def keys(self): def keys(self):
try: return self._v_keys try: return list(self._v_keys) # return a copy (Collector 2283)
except: pass except: pass
keys=self._v_keys=filter( keys=self._v_keys=filter(
lambda k: not isinstance(k,types.StringType) or k[:1]!='_', lambda k: not isinstance(k,types.StringType) or k[:1]!='_',
...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent): ...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent):
def update(self, b): def update(self, b):
a=self._container a=self._container
for k, v in b.items(): a[k] = v for k, v in b.items(): a[k] = v
try: del self._v_keys
except: pass
self._p_changed=1 self._p_changed=1
def values(self): def values(self):
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
__doc__='''Python implementation of persistent base types __doc__='''Python implementation of persistent base types
$Id: PersistentMapping.py,v 1.8 2000/04/21 20:06:34 jim Exp $''' $Id: PersistentMapping.py,v 1.9 2001/06/05 18:45:33 chrism Exp $'''
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import Persistence import Persistence
import types import types
...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent): ...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent):
return map(lambda k, d=self: (k,d[k]), self.keys()) return map(lambda k, d=self: (k,d[k]), self.keys())
def keys(self): def keys(self):
try: return self._v_keys try: return list(self._v_keys) # return a copy (Collector 2283)
except: pass except: pass
keys=self._v_keys=filter( keys=self._v_keys=filter(
lambda k: not isinstance(k,types.StringType) or k[:1]!='_', lambda k: not isinstance(k,types.StringType) or k[:1]!='_',
...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent): ...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent):
def update(self, b): def update(self, b):
a=self._container a=self._container
for k, v in b.items(): a[k] = v for k, v in b.items(): a[k] = v
try: del self._v_keys
except: pass
self._p_changed=1 self._p_changed=1
def values(self): def values(self):
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
__doc__='''Python implementation of persistent base types __doc__='''Python implementation of persistent base types
$Id: mapping.py,v 1.8 2000/04/21 20:06:34 jim Exp $''' $Id: mapping.py,v 1.9 2001/06/05 18:45:33 chrism Exp $'''
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import Persistence import Persistence
import types import types
...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent): ...@@ -140,7 +140,7 @@ class PersistentMapping(Persistence.Persistent):
return map(lambda k, d=self: (k,d[k]), self.keys()) return map(lambda k, d=self: (k,d[k]), self.keys())
def keys(self): def keys(self):
try: return self._v_keys try: return list(self._v_keys) # return a copy (Collector 2283)
except: pass except: pass
keys=self._v_keys=filter( keys=self._v_keys=filter(
lambda k: not isinstance(k,types.StringType) or k[:1]!='_', lambda k: not isinstance(k,types.StringType) or k[:1]!='_',
...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent): ...@@ -151,6 +151,8 @@ class PersistentMapping(Persistence.Persistent):
def update(self, b): def update(self, b):
a=self._container a=self._container
for k, v in b.items(): a[k] = v for k, v in b.items(): a[k] = v
try: del self._v_keys
except: pass
self._p_changed=1 self._p_changed=1
def values(self): def values(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment