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,
"""
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
......
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