[Erp5-report] r17110 - /erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 23 11:16:31 CEST 2007


Author: jerome
Date: Tue Oct 23 11:16:31 2007
New Revision: 17110

URL: http://svn.erp5.org?rev=17110&view=rev
Log:
micro-optimisation: use "try except KeyError" syntax instead of "if has_key"

Modified:
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=17110&r1=17109&r2=17110&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py Tue Oct 23 11:16:31 2007
@@ -2492,46 +2492,52 @@
     """
     if withCMF:
       # Reset Filtet dict
-      # self.filter_dict= PersistentMapping()
-      if not hasattr(self,'filter_dict'):
+      if getattr(aq_base(self), 'filter_dict', None) is None:
         self.filter_dict = PersistentMapping()
         return 0
-      if self.filter_dict.has_key(method_name):
+      try:
         return self.filter_dict[method_name]['filtered']
+      except KeyError:
+        return 0
     return 0
 
   def getExpression(self, method_name):
     """ Get the filter expression text for this method.
     """
     if withCMF:
-      if not hasattr(self,'filter_dict'):
+      if getattr(aq_base(self), 'filter_dict', None) is None:
         self.filter_dict = PersistentMapping()
         return ""
-      if self.filter_dict.has_key(method_name):
+      try:
         return self.filter_dict[method_name]['expression']
+      except KeyError:
+        return ""
     return ""
 
   def getExpressionInstance(self, method_name):
     """ Get the filter expression instance for this method.
     """
     if withCMF:
-      if not hasattr(self,'filter_dict'):
+      if getattr(aq_base(self), 'filter_dict', None) is None:
         self.filter_dict = PersistentMapping()
         return None
-      if self.filter_dict.has_key(method_name):
+      try:
         return self.filter_dict[method_name]['expression_instance']
+      except KeyError:
+        return None
     return None
 
   def isPortalTypeSelected(self, method_name, portal_type):
     """ Returns true if the portal type is selected for this method.
     """
     if withCMF:
-      if not hasattr(self,'filter_dict'):
+      if getattr(aq_base(self), 'filter_dict', None) is None:
         self.filter_dict = PersistentMapping()
         return 0
-      if self.filter_dict.has_key(method_name):
-        result = portal_type in (self.filter_dict[method_name]['type'])
-        return result
+      try:
+        return portal_type in (self.filter_dict[method_name]['type'])
+      except KeyError:
+        return 0
     return 0
 
 




More information about the Erp5-report mailing list