[Zope-Checkins] SVN: Zope/trunk/src/OFS/ Stop using id() methods and define proper getId methods

Hanno Schlichting hannosch at hannosch.eu
Wed Jul 13 14:32:05 EDT 2011


Log message for revision 122198:
  Stop using id() methods and define proper getId methods
  

Changed:
  U   Zope/trunk/src/OFS/Application.py
  U   Zope/trunk/src/OFS/Image.py
  U   Zope/trunk/src/OFS/SimpleItem.py
  U   Zope/trunk/src/OFS/tests/testApplication.py

-=-
Modified: Zope/trunk/src/OFS/Application.py
===================================================================
--- Zope/trunk/src/OFS/Application.py	2011-07-13 18:28:45 UTC (rev 122197)
+++ Zope/trunk/src/OFS/Application.py	2011-07-13 18:32:05 UTC (rev 122198)
@@ -82,7 +82,7 @@
         self.__allow_groups__ = uf
         self._setObject('acl_users', uf)
 
-    def id(self):
+    def getId(self):
         try:
             return self.REQUEST['SCRIPT_NAME'][1:]
         except (KeyError, TypeError):

Modified: Zope/trunk/src/OFS/Image.py
===================================================================
--- Zope/trunk/src/OFS/Image.py	2011-07-13 18:28:45 UTC (rev 122197)
+++ Zope/trunk/src/OFS/Image.py	2011-07-13 18:32:05 UTC (rev 122198)
@@ -141,9 +141,6 @@
         content_type=self._get_content_type(file, data, id, content_type)
         self.update_data(data, content_type, size)
 
-    def id(self):
-        return self.__name__
-
     def _if_modified_since_request_handler(self, REQUEST, RESPONSE):
         # HTTP If-Modified-Since header handling: return True if
         # we can handle this request by returning a 304 response

Modified: Zope/trunk/src/OFS/SimpleItem.py
===================================================================
--- Zope/trunk/src/OFS/SimpleItem.py	2011-07-13 18:28:45 UTC (rev 122197)
+++ Zope/trunk/src/OFS/SimpleItem.py	2011-07-13 18:32:05 UTC (rev 122198)
@@ -91,7 +91,7 @@
     manage_afterClone.__five_method__ = True
 
     # Direct use of the 'id' attribute is deprecated - use getId()
-    id=''
+    id = ''
 
     security.declarePublic('getId')
     def getId(self):
@@ -100,17 +100,13 @@
         This method should be used in preference to accessing an id attribute
         of an object directly. The getId method is public.
         """
-        name=getattr(self, 'id', None)
-        if callable(name):
-            return name()
+        name = self.id
         if name is not None:
             return name
-        if hasattr(self, '__name__'):
-            return self.__name__
-        raise AttributeError, 'This object has no id'
+        return self.__name__
 
     # Alias id to __name__, which will make tracebacks a good bit nicer:
-    __name__=ComputedAttribute(lambda self: self.getId())
+    __name__ = ComputedAttribute(lambda self: self.id)
 
     # Meta type used for selecting all objects of a given type.
     meta_type='simple item'
@@ -377,7 +373,6 @@
 
 
 class Item_w__name__(Item):
-
     """Mixin class to support common name/id functions"""
 
     implements(IItemWithName)
@@ -411,12 +406,10 @@
         getPhysicalRoot() and getPhysicalPath() are designed to operate
         together.
         """
-        path = (self.__name__,)
-
+        path = (self.__name__, )
         p = aq_parent(aq_inner(self))
         if p is not None:
             path = p.getPhysicalPath() + path
-
         return path
 
 

Modified: Zope/trunk/src/OFS/tests/testApplication.py
===================================================================
--- Zope/trunk/src/OFS/tests/testApplication.py	2011-07-13 18:28:45 UTC (rev 122197)
+++ Zope/trunk/src/OFS/tests/testApplication.py	2011-07-13 18:32:05 UTC (rev 122198)
@@ -29,17 +29,17 @@
 
     def test_id_no_request(self):
         app = self._makeOne()
-        self.assertEqual(app.id(), 'Zope')
+        self.assertEqual(app.getId(), 'Zope')
 
     def test_id_w_request_no_SCRIPT_NAME(self):
         app = self._makeOne()
         app.REQUEST = {}
-        self.assertEqual(app.id(), 'Zope')
+        self.assertEqual(app.getId(), 'Zope')
 
     def test_id_w_request_w_SCRIPT_NAME(self):
         app = self._makeOne()
         app.REQUEST = {'SCRIPT_NAME': '/Dummy'}
-        self.assertEqual(app.id(), 'Dummy')
+        self.assertEqual(app.getId(), 'Dummy')
 
     def test_title_and_id_plus_title_or_id(self):
         app = self._makeOne()



More information about the Zope-Checkins mailing list