[Zodb-checkins] SVN: ZODB/branches/3.6/ merging revision 40330 from trunk:

Thomas Lotze tl at gocept.com
Tue Nov 22 16:15:26 EST 2005


Log message for revision 40332:
  merging revision 40330 from trunk:
  - fixed the API of the pop() method on PersistentDict and PersistentMapping
  - no longer try to find pop and popitem on UserDict as all supported
    Python versions have them
  - added a test for the default argument of pop()
  - added a NEWS.txt entry about pop()
  

Changed:
  U   ZODB/branches/3.6/NEWS.txt
  U   ZODB/branches/3.6/src/persistent/dict.py
  U   ZODB/branches/3.6/src/persistent/mapping.py
  U   ZODB/branches/3.6/src/persistent/tests/test_mapping.py

-=-
Modified: ZODB/branches/3.6/NEWS.txt
===================================================================
--- ZODB/branches/3.6/NEWS.txt	2005-11-22 21:07:44 UTC (rev 40331)
+++ ZODB/branches/3.6/NEWS.txt	2005-11-22 21:15:25 UTC (rev 40332)
@@ -109,6 +109,9 @@
 PersistentMapping
 -----------------
 
+- (3.6b3) The ``PersistentMapping`` makes changes by a ``pop()`` method call
+  persistent now.
+
 - (3.6a1) The ``PersistentMapping`` class has an ``__iter__()`` method
   now, so that objects of this type work well with Python's iteration
   protocol.  For example, if ``x`` is a ``PersistentMapping`` (or

Modified: ZODB/branches/3.6/src/persistent/dict.py
===================================================================
--- ZODB/branches/3.6/src/persistent/dict.py	2005-11-22 21:07:44 UTC (rev 40331)
+++ ZODB/branches/3.6/src/persistent/dict.py	2005-11-22 21:15:25 UTC (rev 40332)
@@ -73,9 +73,9 @@
             self._p_changed = True
         return self.__super_setdefault(key, failobj)
 
-    def pop(self, i):
+    def pop(self, key, *args):
         self._p_changed = True
-        return self.__super_pop(i)
+        return self.__super_pop(key, *args)
 
     def popitem(self):
         self._p_changed = True

Modified: ZODB/branches/3.6/src/persistent/mapping.py
===================================================================
--- ZODB/branches/3.6/src/persistent/mapping.py	2005-11-22 21:07:44 UTC (rev 40331)
+++ ZODB/branches/3.6/src/persistent/mapping.py	2005-11-22 21:15:25 UTC (rev 40332)
@@ -41,6 +41,8 @@
     __super_clear = UserDict.clear
     __super_update = UserDict.update
     __super_setdefault = UserDict.setdefault
+    __super_pop = UserDict.pop
+    __super_popitem = UserDict.popitem
 
     def __delitem__(self, key):
         self.__super_delitem(key)
@@ -66,23 +68,13 @@
             self._p_changed = 1
         return self.__super_setdefault(key, failobj)
 
-    try:
-        __super_pop = UserDict.pop
-    except AttributeError:
-        pass
-    else:
-        def pop(self, i):
-            self._p_changed = 1
-            return self.__super_pop(i)
+    def pop(self, key, *args):
+        self._p_changed = 1
+        return self.__super_pop(key, *args)
 
-    try:
-        __super_popitem = UserDict.popitem
-    except AttributeError:
-        pass
-    else:
-        def popitem(self):
-            self._p_changed = 1
-            return self.__super_popitem()
+    def popitem(self):
+        self._p_changed = 1
+        return self.__super_popitem()
 
     # __iter__ was added in ZODB 3.4.2, but should have been added long
     # before.  We could inherit from Python's IterableUserDict instead

Modified: ZODB/branches/3.6/src/persistent/tests/test_mapping.py
===================================================================
--- ZODB/branches/3.6/src/persistent/tests/test_mapping.py	2005-11-22 21:07:44 UTC (rev 40331)
+++ ZODB/branches/3.6/src/persistent/tests/test_mapping.py	2005-11-22 21:15:25 UTC (rev 40332)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -136,6 +136,9 @@
         else:
             raise TestFailed("1 should not be poppable from u2")
 
+        x = u2.pop(1, 7)
+        eq(x, 7, "u2.pop(1, 7) == 7")
+
         # Test popitem
 
         items = u2.items()



More information about the Zodb-checkins mailing list