[Checkins] SVN: zope.location/trunk/ More tweaks for pure-Python edge cases.

Tres Seaver cvs-admin at zope.org
Thu Jun 7 02:31:35 UTC 2012


Log message for revision 126656:
  More tweaks for pure-Python edge cases.

Changed:
  _U  zope.location/trunk/
  U   zope.location/trunk/src/zope/location/location.py
  U   zope.location/trunk/src/zope/location/tests/test_location.py

-=-
Modified: zope.location/trunk/src/zope/location/location.py
===================================================================
--- zope.location/trunk/src/zope/location/location.py	2012-06-07 02:31:26 UTC (rev 126655)
+++ zope.location/trunk/src/zope/location/location.py	2012-06-07 02:31:31 UTC (rev 126656)
@@ -110,15 +110,16 @@
     def __getattribute__(self, name):
         if name in LocationProxy.__dict__:
             return object.__getattribute__(self, name)
-        return super(ProxyBase, self).__getattribute__(name)
+        return ProxyBase.__getattribute__(self, name)
 
     def __setattr__(self, name, value):
-        if name in ('_wrapped', '__parent__', '__name__'):
+        if name in self.__slots__ + getattr(ProxyBase, '__slots__', ()):
+            #('_wrapped', '__parent__', '__name__'):
             try:
                 return ProxyBase.__setattr__(self, name, value)
-            except AttributeError:
+            except AttributeError: #pragma NO COVER PyPy
                 return object.__setattr__(self, name, value)
-        setattr(self._wrapped, name, value)
+        return ProxyBase.__setattr__(self, name, value)
 
     @non_overridable
     def __reduce__(self, proto=None):

Modified: zope.location/trunk/src/zope/location/tests/test_location.py
===================================================================
--- zope.location/trunk/src/zope/location/tests/test_location.py	2012-06-07 02:31:26 UTC (rev 126655)
+++ zope.location/trunk/src/zope/location/tests/test_location.py	2012-06-07 02:31:31 UTC (rev 126656)
@@ -264,6 +264,21 @@
         self.assertTrue(proxy.__parent__ is parent)
         self.assertEqual(proxy.__name__, 'name')
 
+    def test___getattribute___wrapped(self):
+        class Context(object):
+            attr = 'ATTR'
+        context = Context()
+        proxy = self._makeOne(context)
+        self.assertEqual(proxy.attr, 'ATTR')
+
+    def test___setattr___wrapped(self):
+        class Context(object):
+            attr = 'BEFORE'
+        context = Context()
+        proxy = self._makeOne(context)
+        proxy.attr = 'AFTER'
+        self.assertEqual(context.attr, 'AFTER')
+
     def test___doc___from_derived_class(self):
         klass = self._getTargetClass()
         class Derived(klass):
@@ -298,6 +313,17 @@
         proxy = self._makeOne()
         self.assertRaises(TypeError, proxy.__reduce_ex__, 1)
 
+    def test___reduce___via_pickling(self):
+        import pickle
+        class Context(object):
+            def __reduce__(self):
+                return {'a': 1}
+        proxy = self._makeOne(Context())
+        # XXX: this TypeError is not due to LocationProxy.__reduce__:
+        #      it's descriptor (under pure Python) isn't begin triggered
+        #      properly
+        self.assertRaises(TypeError, pickle.dumps, proxy)
+
     def test__providedBy___class(self):
         from zope.interface import Interface
         from zope.interface import implementer



More information about the checkins mailing list