Commit 6e8d1d1c authored by Jérome Perrin's avatar Jérome Perrin

micro-optimisation: use "try except KeyError" syntax instead of "if has_key"


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17110 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent befa5314
...@@ -2492,46 +2492,52 @@ class Catalog( Folder, ...@@ -2492,46 +2492,52 @@ class Catalog( Folder,
""" """
if withCMF: if withCMF:
# Reset Filtet dict # Reset Filtet dict
# self.filter_dict= PersistentMapping() if getattr(aq_base(self), 'filter_dict', None) is None:
if not hasattr(self,'filter_dict'):
self.filter_dict = PersistentMapping() self.filter_dict = PersistentMapping()
return 0 return 0
if self.filter_dict.has_key(method_name): try:
return self.filter_dict[method_name]['filtered'] return self.filter_dict[method_name]['filtered']
except KeyError:
return 0
return 0 return 0
def getExpression(self, method_name): def getExpression(self, method_name):
""" Get the filter expression text for this method. """ Get the filter expression text for this method.
""" """
if withCMF: if withCMF:
if not hasattr(self,'filter_dict'): if getattr(aq_base(self), 'filter_dict', None) is None:
self.filter_dict = PersistentMapping() self.filter_dict = PersistentMapping()
return "" return ""
if self.filter_dict.has_key(method_name): try:
return self.filter_dict[method_name]['expression'] return self.filter_dict[method_name]['expression']
except KeyError:
return ""
return "" return ""
def getExpressionInstance(self, method_name): def getExpressionInstance(self, method_name):
""" Get the filter expression instance for this method. """ Get the filter expression instance for this method.
""" """
if withCMF: if withCMF:
if not hasattr(self,'filter_dict'): if getattr(aq_base(self), 'filter_dict', None) is None:
self.filter_dict = PersistentMapping() self.filter_dict = PersistentMapping()
return None return None
if self.filter_dict.has_key(method_name): try:
return self.filter_dict[method_name]['expression_instance'] return self.filter_dict[method_name]['expression_instance']
except KeyError:
return None
return None return None
def isPortalTypeSelected(self, method_name, portal_type): def isPortalTypeSelected(self, method_name, portal_type):
""" Returns true if the portal type is selected for this method. """ Returns true if the portal type is selected for this method.
""" """
if withCMF: if withCMF:
if not hasattr(self,'filter_dict'): if getattr(aq_base(self), 'filter_dict', None) is None:
self.filter_dict = PersistentMapping() self.filter_dict = PersistentMapping()
return 0 return 0
if self.filter_dict.has_key(method_name): try:
result = portal_type in (self.filter_dict[method_name]['type']) return portal_type in (self.filter_dict[method_name]['type'])
return result except KeyError:
return 0
return 0 return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment