[CMF-checkins] CVS: CMF/CMFTopic - AbstractCriterion.py:1.7
DateCriteria.py:1.8 ListCriterion.py:1.13
SimpleIntCriterion.py:1.11 Topic.py:1.35
Yvo Schubbe
cvs-admin at zope.org
Mon Dec 1 08:56:16 EST 2003
Update of /cvs-repository/CMF/CMFTopic
In directory cvs.zope.org:/tmp/cvs-serv16302/CMFTopic
Modified Files:
AbstractCriterion.py DateCriteria.py ListCriterion.py
SimpleIntCriterion.py Topic.py
Log Message:
some code modernization:
- death to string module
- death to apply
- import and whitespace cleanup
=== CMF/CMFTopic/AbstractCriterion.py 1.6 => 1.7 ===
--- CMF/CMFTopic/AbstractCriterion.py:1.6 Thu Aug 1 15:05:13 2002
+++ CMF/CMFTopic/AbstractCriterion.py Mon Dec 1 08:55:45 2003
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
""" Home of the abstract Criterion base class.
@@ -25,7 +25,6 @@
from Globals import InitializeClass
from OFS.SimpleItem import Item
-import string, operator
class AbstractCriterion( Persistent, Item, Implicit ):
"""
@@ -40,7 +39,7 @@
Apply 'command', which is expected to be a dictionary,
to 'self.edit' (makes using Python Scripts easier).
"""
- apply( self.edit, (), command )
+ self.edit(**command)
security.declareProtected( ChangeTopics, 'editableAttributes' )
def editableAttributes( self ):
@@ -66,7 +65,7 @@
attribute.
"""
return self.meta_type
-
+
security.declareProtected( AccessContentsInformation, 'Field' )
def Field( self ):
"""
@@ -82,15 +81,7 @@
Return a brief but helpful description of the Criterion type,
preferably based on the classes __doc__ string.
"""
- strip = string.strip
- split = string.split
-
- return string.join( # Sew a string together after we:
- filter(operator.truth, # Filter out empty lines
- map(strip, # strip whitespace off each line
- split(self.__doc__, '\n') # from the classes doc string
- )
- )
- )
+ lines = [ line.strip() for line in self.__doc__.splitlines() ]
+ return ' '.join( [ line for line in lines if line ] )
InitializeClass( AbstractCriterion )
=== CMF/CMFTopic/DateCriteria.py 1.7 => 1.8 ===
--- CMF/CMFTopic/DateCriteria.py:1.7 Sat Aug 3 22:31:31 2002
+++ CMF/CMFTopic/DateCriteria.py Mon Dec 1 08:55:45 2003
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
""" Various date criteria
@@ -26,7 +26,6 @@
from DateTime.DateTime import DateTime
import Globals
-import string, operator
class FriendlyDateCriterion( AbstractCriterion ):
"""
=== CMF/CMFTopic/ListCriterion.py 1.12 => 1.13 ===
--- CMF/CMFTopic/ListCriterion.py:1.12 Sat Aug 3 22:31:31 2002
+++ CMF/CMFTopic/ListCriterion.py Mon Dec 1 08:55:45 2003
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
""" List Criterion: A criterion that is a list
@@ -25,7 +25,6 @@
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
-import string
class ListCriterion( AbstractCriterion ):
"""
@@ -72,7 +71,7 @@
self._clear()
else:
if type( value ) == type( '' ):
- value = string.split( value, '\n' )
+ value = value.split('\n')
self.value = tuple( value )
if not operator:
@@ -89,7 +88,7 @@
# filter out empty strings
result = []
- value = tuple( filter( None, self.value ) )
+ value = tuple( filter( None, self.value ) )
if not value:
return ()
result.append( ( self.field, self.value ), )
=== CMF/CMFTopic/SimpleIntCriterion.py 1.10 => 1.11 ===
--- CMF/CMFTopic/SimpleIntCriterion.py:1.10 Sat Aug 3 22:31:31 2002
+++ CMF/CMFTopic/SimpleIntCriterion.py Mon Dec 1 08:55:45 2003
@@ -1,14 +1,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
""" Simple int-matching criterion
@@ -25,10 +25,11 @@
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
+
class SimpleIntCriterion( AbstractCriterion ):
"""
Represent a simple field-match for an integer value, including
- catalog range searches.
+ catalog range searches.
"""
__implements__ = ( Criterion, )
@@ -79,10 +80,9 @@
"""
Update the value to be filtered, and the "direction" qualifier.
"""
- from string import strip, split # XXX: WAAAA! 2.3 compatibility
if type( value ) == type( '' ):
- value = strip( value )
+ value = value.strip()
if not value:
# An empty string was passed in, which evals to None
@@ -93,7 +93,7 @@
if direction == self.MINMAX:
if type( value ) == type( '' ):
- minimum, maximum = split( value, ' ' )
+ minimum, maximum = value.split(' ')
else:
minimum, maximum = value
@@ -126,9 +126,8 @@
return tuple( result )
-
-
InitializeClass( SimpleIntCriterion )
+
# Register as a criteria type with the Topic class
Topic._criteriaTypes.append( SimpleIntCriterion )
=== CMF/CMFTopic/Topic.py 1.34 => 1.35 ===
--- CMF/CMFTopic/Topic.py:1.34 Sat Jun 28 12:31:22 2003
+++ CMF/CMFTopic/Topic.py Mon Dec 1 08:55:45 2003
@@ -119,7 +119,7 @@
"""
view = _getViewFor( self )
if getattr( aq_base( view ), 'isDocTemp', 0 ):
- return apply( view, ( self, self.REQUEST ) )
+ return view(self, self.REQUEST)
else:
return view()
@@ -138,7 +138,7 @@
for mt in self._criteriaTypes:
result.append( mt.meta_type )
return tuple( result )
-
+
security.declareProtected(ChangeTopics, 'listCriteria')
def listCriteria( self ):
"""
@@ -155,7 +155,7 @@
'name': ct.meta_type,
} )
return out
-
+
security.declareProtected(ChangeTopics, 'listAvailableFields')
def listAvailableFields( self ):
"""
@@ -186,7 +186,7 @@
if title is not None:
self.title = title
self.description = description
-
+
security.declareProtected(View, 'buildQuery')
def buildQuery( self ):
"""
@@ -206,9 +206,9 @@
for criterion in self.listCriteria():
for key, value in criterion.getCriteriaItems():
result[ key ] = value
-
+
return result
-
+
security.declareProtected(View, 'queryCatalog')
def queryCatalog( self, REQUEST=None, **kw ):
"""
@@ -217,8 +217,7 @@
"""
kw.update( self.buildQuery() )
portal_catalog = getToolByName( self, 'portal_catalog' )
- return apply( portal_catalog.searchResults, ( REQUEST, ), kw )
-
+ return portal_catalog.searchResults(REQUEST, **kw)
### Criteria adding/editing/deleting
security.declareProtected(ChangeTopics, 'addCriterion')
@@ -235,7 +234,7 @@
if crit is None:
# No criteria type matched passed in value
raise NameError, 'Unknown Criterion Type: %s' % criterion_type
-
+
self._setObject( newid, crit )
# Backwards compatibility (deprecated)
More information about the CMF-checkins
mailing list