From 545e8d9dc2ef86d937fa65d81edd6156164305cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 12 Aug 2009 12:02:53 +0000
Subject: [PATCH] remove some compatibility code for zope 2.7

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28351 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Accessor/Base.py      | 60 +++++++++++-------------
 product/ERP5Type/tests/testERP5Type.py | 64 +++++++-------------------
 2 files changed, 45 insertions(+), 79 deletions(-)

diff --git a/product/ERP5Type/Accessor/Base.py b/product/ERP5Type/Accessor/Base.py
index afb834c4e0..13c92ddfa8 100644
--- a/product/ERP5Type/Accessor/Base.py
+++ b/product/ERP5Type/Accessor/Base.py
@@ -95,6 +95,20 @@ class Setter(Method):
         modified_object_list.append(instance)
       return modified_object_list
 
+    class __roles__:
+      @staticmethod
+      def rolesForPermissionOn(ob):
+        # we explictly call _aq_dynamic to prevent acquiering the attribute
+        # from container
+        roles = ob.im_self._aq_dynamic('%s__roles__' % ob.__name__)
+        if roles is None:
+            return rolesForPermissionOn(None, ob.im_self, ('Manager',),
+                                        '_Modify_portal_content_Permission')
+        else:
+            # wrap explicitly, because we used _aq_dynamic
+            return roles.__of__(ob.im_self)
+
+
 from Products.CMFCore.Expression import Expression
 def _evaluateTales(instance=None, value=None):
   from Products.ERP5Type.Utils import createExpressionContext
@@ -158,6 +172,20 @@ class Getter(Method):
 
     psyco.bind(__call__)
 
+    class __roles__:
+      @staticmethod
+      def rolesForPermissionOn(ob):
+        # we explictly call _aq_dynamic to prevent acquiering the attribute
+        # from container
+        roles = ob.im_self._aq_dynamic('%s__roles__' % ob.__name__)
+        if roles is None:
+            return rolesForPermissionOn(None, ob.im_self, ('Manager',),
+                                        '_Access_contents_information_Permission')
+        else:
+            # wrap explicitly, because we used _aq_dynamic
+            return roles.__of__(ob.im_self)
+
+
 class Tester(Method):
     """
       Tests if an attribute value exists
@@ -184,35 +212,3 @@ class Tester(Method):
     def __call__(self, instance, *args, **kw):
       return getattr(aq_base(instance), self._storage_id, None) not in self._null
 
-try:
-    from ZODB.Transaction import Transaction
-    # Zope 2.7 do not patch
-except ImportError:
-    # Zope 2.8, patch
-    class __roles__:
-      @staticmethod
-      def rolesForPermissionOn(ob):
-        # we explictly call _aq_dynamic to prevent acquiering the attribute
-        # from container
-        roles = ob.im_self._aq_dynamic('%s__roles__' % ob.__name__)
-        if roles is None:
-            return rolesForPermissionOn(None, ob.im_self, ('Manager',),
-                                        '_Modify_portal_content_Permission')
-        else:
-            # wrap explicitly, because we used _aq_dynamic
-            return roles.__of__(ob.im_self)
-    Setter.__roles__ = __roles__
-
-    class __roles__:
-      @staticmethod
-      def rolesForPermissionOn(ob):
-        # we explictly call _aq_dynamic to prevent acquiering the attribute
-        # from container
-        roles = ob.im_self._aq_dynamic('%s__roles__' % ob.__name__)
-        if roles is None:
-            return rolesForPermissionOn(None, ob.im_self, ('Manager',),
-                                        '_Access_contents_information_Permission')
-        else:
-            # wrap explicitly, because we used _aq_dynamic
-            return roles.__of__(ob.im_self)
-    Getter.__roles__ = __roles__
diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py
index 56c8fa9d5b..267e1f9b91 100644
--- a/product/ERP5Type/tests/testERP5Type.py
+++ b/product/ERP5Type/tests/testERP5Type.py
@@ -2304,13 +2304,6 @@ class TestPropertySheet:
 
     def test_DefaultSecurityOnAccessors(self):
       # Test accessors are protected correctly
-      try:
-        from ZODB.Transaction import Transaction
-        return
-        # Zope 2.7 do not test
-      except ImportError:
-        pass
-
       self._addProperty('Person',
                   ''' { 'id':         'foo_bar',
                         'type':       'string',
@@ -2332,13 +2325,6 @@ class TestPropertySheet:
       self.assertFalse(guarded_hasattr(obj, 'getFooBar'))
 
     def test_DefaultSecurityOnListAccessors(self):
-      try:
-        from ZODB.Transaction import Transaction
-        return
-        # Zope 2.7 do not test
-      except ImportError:
-        pass
-
       # Test list accessors are protected correctly
       self._addProperty('Person',
                   ''' { 'id':         'foo_bar',
@@ -2360,12 +2346,6 @@ class TestPropertySheet:
       self.assertFalse(guarded_hasattr(obj, 'getFooBarList'))
 
     def test_DefaultSecurityOnCategoryAccessors(self):
-      try:
-        from ZODB.Transaction import Transaction
-        return
-        # Zope 2.7 do not test
-      except ImportError:
-        pass
       # Test category accessors are protected correctly
       obj = self.getPersonModule().newContent(portal_type='Person')
       self.assertTrue(guarded_hasattr(obj, 'setRegion'))
@@ -2402,13 +2382,6 @@ class TestPropertySheet:
       self.assertFalse(guarded_hasattr(obj, 'getRegionRelatedValueList'))
 
     def test_PropertySheetSecurityOnAccessors(self):
-      try:
-        from ZODB.Transaction import Transaction
-        return
-        # Zope 2.7 do not test
-      except ImportError:
-        pass
-
       # Test accessors are protected correctly when you specify the permission
       # in the property sheet.
       self._addProperty('Person',
@@ -2431,26 +2404,22 @@ class TestPropertySheet:
       self.assertFalse(guarded_hasattr(obj, 'getFooBar'))
 
     def test_edit(self):
-      # not working in 2.7 as accessor not patched
-      try:
-        from ZODB.Transaction import Transaction
-      except ImportError:
-        self._addProperty('Person',
-                          ''' { 'id':         'foo_bar',
-                          'write_permission' : 'Set own password',
-                          'read_permission'  : 'Manage users',
-                          'type':       'string',
-                          'mode':       'w', }''')
-        obj = self.getPersonModule().newContent(portal_type='Person')
-        obj.edit(foo_bar="v1")
-        self.assertEqual(obj.getFooBar(), "v1")
-
-        obj.manage_permission('Set own password', [], 0)
-        self.assertRaises(Unauthorized, obj.edit, foo_bar="v2")
-        self.assertEqual(obj.getFooBar(), "v1")
-
-        obj._edit(foo_bar="v3")
-        self.assertEqual(obj.getFooBar(), "v3")
+      self._addProperty('Person',
+                        ''' { 'id':         'foo_bar',
+                        'write_permission' : 'Set own password',
+                        'read_permission'  : 'Manage users',
+                        'type':       'string',
+                        'mode':       'w', }''')
+      obj = self.getPersonModule().newContent(portal_type='Person')
+      obj.edit(foo_bar="v1")
+      self.assertEqual(obj.getFooBar(), "v1")
+
+      obj.manage_permission('Set own password', [], 0)
+      self.assertRaises(Unauthorized, obj.edit, foo_bar="v2")
+      self.assertEqual(obj.getFooBar(), "v1")
+
+      obj._edit(foo_bar="v3")
+      self.assertEqual(obj.getFooBar(), "v3")
 
     def test_accessor_security_and_getTitle_acquisition(self):
       obj = self.getOrganisationModule().newContent(portal_type='Organisation')
@@ -2623,6 +2592,7 @@ class TestPropertySheet:
       person.validate()
       self.assertRaises(WorkflowException, person.validate)
 
+
 class TestAccessControl(ERP5TypeTestCase):
   # Isolate test in a dedicaced class in order not to break other tests
   # when this one fails.
-- 
2.30.9