Log message for revision 115313:
  Final PEP8 fixes
  

Changed:
  U   Zope/trunk/src/Products/ZCatalog/Catalog.py
  U   Zope/trunk/src/Products/ZCatalog/CatalogAwareness.py
  U   Zope/trunk/src/Products/ZCatalog/CatalogPathAwareness.py
  U   Zope/trunk/src/Products/ZCatalog/__init__.py
  U   Zope/trunk/src/Products/ZCatalog/interfaces.py

-=-
Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 10:46:30 UTC (rev 
115312)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 10:56:13 UTC (rev 
115313)
@@ -54,6 +54,7 @@
 class CatalogError(Exception):
     pass
 
+
 class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
     """ An Object Catalog
 
@@ -80,7 +81,7 @@
         # convenient display on result pages.  meta_data attributes
         # are turned into brain objects and returned by
         # searchResults.  The indexing machinery indexes all records
-        # by an integer id (rid).  self.data is a mapping from the
+        # by an integer id (rid). self.data is a mapping from the
         # integer id to the meta_data, self.uids is a mapping of the
         # object unique identifier to the rid, and self.paths is a
         # mapping of the rid to the unique identifier.
@@ -106,8 +107,8 @@
     def clear(self):
         """ clear catalog """
 
-        self.data  = IOBTree()  # mapping of rid to meta_data
-        self.uids  = OIBTree()  # mapping of uid to rid
+        self.data = IOBTree()  # mapping of rid to meta_data
+        self.uids = OIBTree()  # mapping of uid to rid
         self.paths = IOBTree()  # mapping of rid to uid
         self._length = BTrees.Length.Length()
 
@@ -171,25 +172,24 @@
         schema = self.schema
         names = list(self.names)
 
-        if schema.has_key(name):
-            raise CatalogError, 'The column %s already exists' % name
+        if name in schema:
+            raise CatalogError('The column %s already exists' % name)
 
         if name[0] == '_':
-            raise CatalogError, \
-                  'Cannot cache fields beginning with "_"'
+            raise CatalogError('Cannot cache fields beginning with "_"')
 
-        if not schema.has_key(name):
-            if schema.values():
-                schema[name] = max(schema.values())+1
-            else:
-                schema[name] = 0
-            names.append(name)
+        values = schema.values()
+        if values:
+            schema[name] = max(values) + 1
+        else:
+            schema[name] = 0
+        names.append(name)
 
-        if default_value is None or default_value == '':
+        if default_value in (None, ''):
             default_value = MV
 
-        for key in self.data.keys():
-            rec = list(self.data[key])
+        for key, value in self.data.items():
+            rec = list(value)
             rec.append(default_value)
             self.data[key] = tuple(rec)
 
@@ -208,14 +208,16 @@
         names = list(self.names)
         _index = names.index(name)
 
-        if not self.schema.has_key(name):
-            LOG.error('delColumn attempted to delete nonexistent column %s.' % 
str(name))
+        if not name in self.schema:
+            LOG.error('delColumn attempted to delete nonexistent '
+                      'column %s.' % str(name))
             return
 
         del names[_index]
 
         # rebuild the schema
-        i=0; schema = {}
+        i = 0
+        schema = {}
         for name in names:
             schema[name] = i
             i = i + 1
@@ -227,8 +229,8 @@
         self.updateBrains()
 
         # remove the column value from each record
-        for key in self.data.keys():
-            rec = list(self.data[key])
+        for key, value in self.data.items():
+            rec = list(value)
             del rec[_index]
             self.data[key] = tuple(rec)
 
@@ -236,37 +238,36 @@
         """Create a new index, given a name and a index_type.
 
         Old format: index_type was a string, 'FieldIndex' 'TextIndex' or
-        'KeywordIndex' is no longer valid; the actual index must be 
instantiated
-        and passed in to addIndex.
+        'KeywordIndex' is no longer valid; the actual index must be
+        instantiated and passed in to addIndex.
 
         New format: index_type is the actual index object to be stored.
-
         """
 
-        if self.indexes.has_key(name):
-            raise CatalogError, 'The index %s already exists' % name
+        if name in self.indexes:
+            raise CatalogError('The index %s already exists' % name)
 
         if name.startswith('_'):
-            raise CatalogError, 'Cannot index fields beginning with "_"'
+            raise CatalogError('Cannot index fields beginning with "_"')
 
         if not name:
-            raise CatalogError, 'Name of index is empty'
+            raise CatalogError('Name of index is empty')
 
         indexes = self.indexes
 
         if isinstance(index_type, str):
-            raise TypeError,"""Catalog addIndex now requires the index type to
-            be resolved prior to adding; create the proper index in the 
caller."""
+            raise TypeError("Catalog addIndex now requires the index type to"
+                            "be resolved prior to adding; create the proper "
+                            "index in the caller.")
 
-        indexes[name] = index_type;
-
+        indexes[name] = index_type
         self.indexes = indexes
 
     def delIndex(self, name):
         """ deletes an index """
 
-        if not self.indexes.has_key(name):
-            raise CatalogError, 'The index %s does not exist' % name
+        if not name in self.indexes:
+            raise CatalogError('The index %s does not exist' % name)
 
         indexes = self.indexes
         del indexes[name]
@@ -354,11 +355,12 @@
             self.updateMetadata(object, uid)
 
         # do indexing
-
         total = 0
 
-        if idxs==[]: use_indexes = self.indexes.keys()
-        else:        use_indexes = idxs
+        if idxs == []:
+            use_indexes = self.indexes.keys()
+        else:
+            use_indexes = idxs
 
         for name in use_indexes:
             x = self.getIndex(name)
@@ -366,7 +368,8 @@
                 blah = x.index_object(index, object, threshold)
                 total = total + blah
             else:
-                LOG.error('catalogObject was passed bad index object %s.' % 
str(x))
+                LOG.error('catalogObject was passed bad index '
+                          'object %s.' % str(x))
 
         return total
 
@@ -417,19 +420,19 @@
     def recordify(self, object):
         """ turns an object into a record tuple """
         record = []
-        # the unique id is allways the first element
+        # the unique id is always the first element
         for x in self.names:
-            attr=getattr(object, x, MV)
-            if(attr is not MV and safe_callable(attr)): attr=attr()
+            attr = getattr(object, x, MV)
+            if (attr is not MV and safe_callable(attr)):
+                attr = attr()
             record.append(attr)
         return tuple(record)
 
     def instantiate(self, record):
-        r=self._v_result_class(record[1])
+        r = self._v_result_class(record[1])
         r.data_record_id_ = record[0]
         return r.__of__(self)
 
-
     def getMetadataForRID(self, rid):
         record = self.data[rid]
         result = {}
@@ -559,7 +562,7 @@
                 return LazyMap(self.instantiate, self.data.items(), len(self))
             else:
                 return self.sortResults(
-                    self.data, sort_index, reverse,  limit, merge)
+                    self.data, sort_index, reverse, limit, merge)
         elif rs:
             # We got some results from the indexes.
             # Sort and convert to sequences.
@@ -777,13 +780,13 @@
             # self.indexes is always a dict, so get() w/ 1 arg works
             sort_index = self.indexes.get(sort_index_name)
             if sort_index is None:
-                raise CatalogError, 'Unknown sort_on index (%s)' % 
sort_index_name
+                raise CatalogError('Unknown sort_on index (%s)' %
+                                   sort_index_name)
             else:
                 if not hasattr(sort_index, 'documentToKeyMap'):
                     raise CatalogError(
                         'The index chosen for sort_on (%s) is not capable of '
-                        'being used as a sort index.' % sort_index_name
-                        )
+                        'being used as a sort index.' % sort_index_name)
             return sort_index
         else:
             return None

Modified: Zope/trunk/src/Products/ZCatalog/CatalogAwareness.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/CatalogAwareness.py        2010-08-01 
10:46:30 UTC (rev 115312)
+++ Zope/trunk/src/Products/ZCatalog/CatalogAwareness.py        2010-08-01 
10:56:13 UTC (rev 115313)
@@ -22,6 +22,7 @@
 from Acquisition import aq_base
 from App.special_dtml import DTMLFile
 
+
 class CatalogAware:
     """ This is a Mix-In class to make objects automaticly catalog and
     uncatalog themselves in Zope, and to provide some other basic
@@ -58,7 +59,8 @@
             except Exception:
                 s = 0
             object.manage_afterAdd(item, container)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def manage_afterClone(self, item):
         self.index_object()
@@ -68,7 +70,8 @@
             except Exception:
                 s = 0
             object.manage_afterClone(item)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def manage_beforeDelete(self, item, container):
         self.unindex_object()
@@ -78,7 +81,8 @@
             except Exception:
                 s = 0
             object.manage_beforeDelete(item, container)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def creator(self):
         """Return a sequence of user names who have the local
@@ -100,13 +104,13 @@
         if hasattr(self, 'DestinationURL') and \
            callable(self.DestinationURL):
             url='%s/%s' % (self.DestinationURL(), self.id)
-        else: url=self.absolute_url()
-        type, uri=ftype(url)
-        host, uri=fhost(uri)
-        script_name=self.REQUEST['SCRIPT_NAME']
-        __traceback_info__=(`uri`, `script_name`)
+        else:
+            url = self.absolute_url()
+        type, uri = ftype(url)
+        host, uri = fhost(uri)
+        script_name = self.REQUEST['SCRIPT_NAME']
         if script_name:
-            uri=filter(None, uri.split(script_name))[0]
+            uri = filter(None, uri.split(script_name))[0]
         if not uri:
             uri = '/'
         if uri[0] != '/':
@@ -117,24 +121,27 @@
         """Return a summary of the text content of the object."""
         if not hasattr(self, 'text_content'):
             return ''
-        attr=getattr(self, 'text_content')
+        attr = getattr(self, 'text_content')
         if callable(attr):
-            text=attr()
-        else: text=attr
-        n=min(num, len(text))
+            text = attr()
+        else:
+            text = attr
+        n = min(num, len(text))
         return text[:n]
 
     def index_object(self):
         """A common method to allow Findables to index themselves."""
         self._warn_deprecated()
-        if hasattr(self, self.default_catalog):
-            getattr(self, self.default_catalog).catalog_object(self, 
self.url())
+        catalog = getattr(self, self.default_catalog, None)
+        if catalog is not None:
+            catalog.catalog_object(self, self.url())
 
     def unindex_object(self):
         """A common method to allow Findables to unindex themselves."""
         self._warn_deprecated()
-        if hasattr(self, self.default_catalog):
-            getattr(self, self.default_catalog).uncatalog_object(self.url())
+        catalog = getattr(self, self.default_catalog, None)
+        if catalog is not None:
+            catalog.uncatalog_object(self.url())
 
     def reindex_object(self):
         """ Suprisingly useful """
@@ -143,7 +150,8 @@
 
     def reindex_all(self, obj=None):
         """ """
-        if obj is None: obj=self
+        if obj is None:
+            obj = self
         if hasattr(aq_base(obj), 'index_object'):
             obj.index_object()
         if hasattr(aq_base(obj), 'objectValues'):

Modified: Zope/trunk/src/Products/ZCatalog/CatalogPathAwareness.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/CatalogPathAwareness.py    2010-08-01 
10:46:30 UTC (rev 115312)
+++ Zope/trunk/src/Products/ZCatalog/CatalogPathAwareness.py    2010-08-01 
10:56:13 UTC (rev 115313)
@@ -18,6 +18,7 @@
 from Acquisition import aq_base
 from App.special_dtml import DTMLFile
 
+
 class CatalogAware:
     """ This is a Mix-In class to make objects automaticly catalog and
     uncatalog themselves in Zope, and to provide some other basic
@@ -54,7 +55,8 @@
             except Exception:
                 s = 0
             object.manage_afterAdd(item, container)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def manage_afterClone(self, item):
         self.index_object()
@@ -64,7 +66,8 @@
             except Exception:
                 s = 0
             object.manage_afterClone(item)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def manage_beforeDelete(self, item, container):
         self.unindex_object()
@@ -74,7 +77,8 @@
             except Exception:
                 s = 0
             object.manage_beforeDelete(item, container)
-            if s is None: object._p_deactivate()
+            if s is None:
+                object._p_deactivate()
 
     def creator(self):
         """Return a sequence of user names who have the local
@@ -102,8 +106,9 @@
         attr=getattr(self, 'text_content')
         if callable(attr):
             text=attr()
-        else: text=attr
-        n=min(num, len(text))
+        else:
+            text=attr
+        n = min(num, len(text))
         return text[:n]
 
     def index_object(self):
@@ -127,7 +132,8 @@
 
     def reindex_all(self, obj=None):
         """ """
-        if obj is None: obj=self
+        if obj is None:
+            obj = self
         if hasattr(aq_base(obj), 'index_object'):
             obj.index_object()
         if hasattr(aq_base(obj), 'objectValues'):

Modified: Zope/trunk/src/Products/ZCatalog/__init__.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/__init__.py        2010-08-01 10:46:30 UTC 
(rev 115312)
+++ Zope/trunk/src/Products/ZCatalog/__init__.py        2010-08-01 10:56:13 UTC 
(rev 115313)
@@ -15,6 +15,7 @@
 
 import ZCatalog
 
+
 def initialize(context):
     context.registerClass(
         ZCatalog.ZCatalog,

Modified: Zope/trunk/src/Products/ZCatalog/interfaces.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/interfaces.py      2010-08-01 10:46:30 UTC 
(rev 115312)
+++ Zope/trunk/src/Products/ZCatalog/interfaces.py      2010-08-01 10:56:13 UTC 
(rev 115313)
@@ -246,6 +246,7 @@
         """
 
 # This should inherit from an IRecord interface, if there ever is one.
+
 class ICatalogBrain(Interface):
     """Catalog brain that handles looking up attributes as
     required, and provides just enough smarts to let us get the URL, path,

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to