From bac66c420dbe43fd5695a14f74be800bbff3019b Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Fri, 28 Oct 2005 07:49:42 +0000 Subject: [PATCH] Fix except with no name. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4150 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFActivity/ActiveProcess.py | 2 +- product/CMFActivity/Activity/Queue.py | 3 ++ product/CMFCategory/Renderer.py | 4 ++- product/ERP5/Document/AmortisationRule.py | 4 +-- product/ERP5/Document/AssortedResource.py | 18 +++++------ product/ERP5/Document/BusinessTemplate.py | 7 +---- product/ERP5/Document/DeliveryCell.py | 6 ++-- product/ERP5/Document/DeliveryLine.py | 2 +- product/ERP5/Document/Entity.py | 22 +++++++------- product/ERP5/Document/Item.py | 6 ++-- product/ERP5/Document/MappedValue.py | 2 +- product/ERP5/Document/Movement.py | 12 ++++---- product/ERP5/Document/Resource.py | 14 ++++----- product/ERP5/ERP5Site.py | 2 +- product/ERP5/Extensions/InventoryBrain.py | 6 ++-- product/ERP5/Tool/CategoryTool.py | 2 +- product/ERP5/Tool/SimulationTool.py | 2 +- product/ERP5/Variated.py | 8 ++--- product/ERP5Form/Form.py | 9 ++++-- product/ERP5Form/ListBox.py | 33 ++++++++++++++------- product/ERP5Form/PDFTemplate.py | 7 ++++- product/ERP5Form/PlanningBox.py | 2 +- product/ERP5Form/Report.py | 2 +- product/ERP5Form/Selection.py | 4 +-- product/ERP5Form/SelectionTool.py | 6 ++-- product/ERP5SyncML/Conduit/BaobabConduit.py | 11 ++++--- product/ERP5Type/Accessor/Base.py | 2 +- product/ERP5Type/Accessor/TypeDefinition.py | 10 +++---- product/ERP5Type/Base.py | 13 ++++---- product/ERP5Type/CMFCorePatch.py | 6 ++-- product/ERP5Type/CopySupport.py | 5 ++-- product/ERP5Type/Document/Folder.py | 4 +-- product/ERP5Type/Utils.py | 4 +-- product/ZSQLCatalog/ZSQLCatalog.py | 20 +++++++++---- product/ZSQLCatalog/zsqlbrain.py | 11 +++++-- 35 files changed, 155 insertions(+), 116 deletions(-) diff --git a/product/CMFActivity/ActiveProcess.py b/product/CMFActivity/ActiveProcess.py index f907ac3c7d..9c1801dbf6 100755 --- a/product/CMFActivity/ActiveProcess.py +++ b/product/CMFActivity/ActiveProcess.py @@ -88,7 +88,7 @@ class ActiveProcess(Base): """ try: my_id = int(self.getLastId()) - except: + except TypeError: my_id = 1 while self.result_list.has_key(my_id): my_id = my_id + 1 diff --git a/product/CMFActivity/Activity/Queue.py b/product/CMFActivity/Activity/Queue.py index 7480ba970c..0228e6bdee 100755 --- a/product/CMFActivity/Activity/Queue.py +++ b/product/CMFActivity/Activity/Queue.py @@ -31,6 +31,7 @@ from Acquisition import aq_base from DateTime import DateTime from Products.CMFActivity.ActivityTool import Message from zLOG import LOG +from ZODB.POSException import ConflictError # Error values for message validation EXCEPTION = -1 @@ -151,6 +152,8 @@ class Queue: for k, v in kw.items(): if activity_tool.validateOrder(message, k, v): return INVALID_ORDER + except ConflictError: + raise except: LOG('WARNING ActivityTool', 0, 'Validation of Object %s raised exception' % '/'.join(message.object_path), diff --git a/product/CMFCategory/Renderer.py b/product/CMFCategory/Renderer.py index ee9313e126..04fa90e7de 100755 --- a/product/CMFCategory/Renderer.py +++ b/product/CMFCategory/Renderer.py @@ -28,7 +28,7 @@ from Products.CMFCategory.Filter import Filter - +from ZODB.POSException import ConflictError from zLOG import LOG class Renderer(Filter): @@ -184,6 +184,8 @@ class Renderer(Filter): elif self.display_id is not None: try: label = value.getProperty(self.display_id) + except ConflictError: + raise except: LOG('WARNING: Renderer', 0, 'Unable to call %s on %s' % (self.display_id, value.getRelativeUrl())) diff --git a/product/ERP5/Document/AmortisationRule.py b/product/ERP5/Document/AmortisationRule.py index 48fc412ea6..c08bc413ca 100755 --- a/product/ERP5/Document/AmortisationRule.py +++ b/product/ERP5/Document/AmortisationRule.py @@ -440,7 +440,7 @@ An ERP5 Rule...""" # We can now apply the calculated movements on the applied rule try: new_period = max(aggregated_period_dict.keys()) + 1 - except: + except TypeError: new_period = 0 for (c_period_number, calculated_dict) in calculated_period_dict.items(): # First, look for a potential found match @@ -555,7 +555,7 @@ An ERP5 Rule...""" # the types which have not been matched later try: del aggregated_movement_dict[type] - except: + except KeyError: pass movements_created = setRemainingAggregatedMovementsToZero(aggregated_movement_dict = aggregated_movement_dict, diff --git a/product/ERP5/Document/AssortedResource.py b/product/ERP5/Document/AssortedResource.py index af79571736..417eef45e3 100755 --- a/product/ERP5/Document/AssortedResource.py +++ b/product/ERP5/Document/AssortedResource.py @@ -594,7 +594,7 @@ identify a bank account.""" try: priced_quantity = float(priced_quantity) if priced_quantity == 0.0: priced_quantity = 1.0 - except: + except TypeError: priced_quantity = 1.0 error_list += ["Priced Quantity could not be converted for resource %s" % resource_id] # source_base_price is the default base price. @@ -608,14 +608,14 @@ identify a bank account.""" base_price = resource.getBasePrice() try: base_price = float(base_price) - except: + except TypeError: base_price = 0.0 error_list += ["Default base price could not be converted for resource %s" % resource_id] if resource.hasSourceBasePrice(): source_base_price = resource.getSourceBasePrice() try: source_base_price = float(source_base_price) - except: + except TypeError: source_base_price = 0.0 error_list += ["Source base price could not be converted for resource %s" % resource_id] resource_quantity_unit = resource.getDefaultQuantityUnit() @@ -644,7 +644,7 @@ identify a bank account.""" new_base_price = resource_variation.getBasePrice() try: new_base_price = float(new_base_price) - except: + except TypeError: new_base_price = 0.0 error_list += ["Default base price could not be converted for resource variation %s" % resource_variation.id] @@ -655,7 +655,7 @@ identify a bank account.""" if resource_variation.hasSourceBasePrice(): try: new_source_base_price = float(new_source_base_price) - except: + except TypeError: new_source_base_price = 0.0 error_list += ["Source base price could not be converted for resource variation %s" % resource_variation.id] @@ -703,7 +703,7 @@ identify a bank account.""" quantity = float(mapped_value.quantity) is_variated_quantity = 1 # The variated quantity is 1 # when the quantity is defined by a variation matrix - except: + except TypeError: error_list += ["Quantity defined by %s is not a float" % mapped_value.id] # Update categories defined by the mapped value base_category_list = mapped_value.getMappedValueBaseCategoryList() @@ -717,7 +717,7 @@ identify a bank account.""" new_base_price = resource_variation.getBasePrice() try: new_base_price = float(new_base_price) - except: + except TypeError: new_base_price = 0.0 error_list += \ ["Default base price could not be converted for resource variation %s" @@ -729,7 +729,7 @@ identify a bank account.""" new_source_base_price = resource_variation.getSourceBasePrice() try: new_source_base_price = float(new_source_base_price) - except: + except TypeError: new_source_base_price = 0.0 error_list += \ ["Source base price could not be converted for resource variation %s" @@ -742,7 +742,7 @@ identify a bank account.""" resource_quantity_unit) try: converted_quantity = float(converted_quantity) - except: + except TypeError: converted_quantity = 0.0 error_list += ["Quantity could not be converted for resource %s" % resource.id] # Convert price to unit price diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index f6e334d0e9..b47717cf61 100755 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -1373,12 +1373,7 @@ class ModuleTemplateItem(BaseTemplateItem): module.setTitle(str(mapping['title'])) for name,role_list in list(mapping['permission_list']): acquire = (type(role_list) == type([])) - try: - module.manage_permission(name, roles=role_list, acquire=acquire) - except: - # Normally, an exception is raised when you don't install any Product which - # has been in use when this business template is created. - pass + module.manage_permission(name, roles=role_list, acquire=acquire) def _importFile(self, file_name, file): dict = {} diff --git a/product/ERP5/Document/DeliveryCell.py b/product/ERP5/Document/DeliveryCell.py index 2241a2010c..b07d46dfb2 100755 --- a/product/ERP5/Document/DeliveryCell.py +++ b/product/ERP5/Document/DeliveryCell.py @@ -120,7 +120,7 @@ class DeliveryCell(MappedValue, Movement): # Standard accessor try: result = Movement.getProperty(self, key, d=d) - except: + except AttributeError: result = None return result @@ -140,7 +140,7 @@ class DeliveryCell(MappedValue, Movement): try: price = float(price) quantity = float(quantity) - except: + except TypeError: price = 0.0 quantity = 0.0 total_quantity += quantity @@ -194,7 +194,7 @@ class DeliveryCell(MappedValue, Movement): if len(item_result_list) == 1 : try : object = item_result_list[0].getObject() - except : + except AttributeError: object = None else : object = None diff --git a/product/ERP5/Document/DeliveryLine.py b/product/ERP5/Document/DeliveryLine.py index 23aa66e258..9c5e2341fd 100755 --- a/product/ERP5/Document/DeliveryLine.py +++ b/product/ERP5/Document/DeliveryLine.py @@ -265,7 +265,7 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated): if len(item_result_list) == 1 : try : object = item_result_list[0].getObject() - except : + except AttributeError: object = None else : object = None diff --git a/product/ERP5/Document/Entity.py b/product/ERP5/Document/Entity.py index e97f9fd352..12f16a09cc 100755 --- a/product/ERP5/Document/Entity.py +++ b/product/ERP5/Document/Entity.py @@ -58,7 +58,7 @@ class Entity: """ try: return self.getDefaultAddressValue().asText() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultAddressStreetAddress') @@ -68,7 +68,7 @@ class Entity: """ try: return self.getDefaultAddressValue().getStreetAddress() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultAddressCity') @@ -78,7 +78,7 @@ class Entity: """ try: return self.getDefaultAddressValue().getCity() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultAddressRegion') @@ -88,7 +88,7 @@ class Entity: """ try: return self.getDefaultAddressValue().getRegion() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultAddressZipCode') @@ -98,7 +98,7 @@ class Entity: """ try: return self.getDefaultAddressValue().getZipCode() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultTelephoneText') @@ -108,7 +108,7 @@ class Entity: """ try: return self.getDefaultTelephone().asText() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultTelephoneNumber') @@ -118,7 +118,7 @@ class Entity: """ try: return self.getDefaultTelephone().getTelephoneNumber() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultFaxText') @@ -128,7 +128,7 @@ class Entity: """ try: return self.getDefaultFax().asText() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultFaxNumber') @@ -138,7 +138,7 @@ class Entity: """ try: return self.getDefaultFax().getTelephoneNumber() - except: + except AttributeError: return '' security.declareProtected(Permissions.View, 'getDefaultEmailText') @@ -148,7 +148,7 @@ class Entity: """ try: return self.getDefaultEmail().asText() - except: + except AttributeError: return '' security.declareProtected(Permissions.ModifyPortalContent, 'setDefaultAddress') @@ -366,4 +366,4 @@ class Entity: """ portal_workflow = getToolByName(self, 'portal_workflow') wf = portal_workflow.getWorkflowById('validation_workflow') - return wf._getWorkflowStateOf(self, id_only=id_only) \ No newline at end of file + return wf._getWorkflowStateOf(self, id_only=id_only) diff --git a/product/ERP5/Document/Item.py b/product/ERP5/Document/Item.py index 53d166655a..d2ade51bc4 100755 --- a/product/ERP5/Document/Item.py +++ b/product/ERP5/Document/Item.py @@ -826,7 +826,7 @@ class Item(XMLObject, Amount): if date is None: try: date = movement.getParent().getStopDate() - except: + except AttributeError: pass if date is not None and (at_date is None or date - at_date <= 0): current_owner = movement.getDestinationSectionValue() @@ -834,12 +834,12 @@ class Item(XMLObject, Amount): if current_owner is None: try: current_owner = movement.getParent().getDestinationSectionValue() - except: + except AttributeError: pass if previous_owner is None: try: previous_owner = movement.getParent().getSourceSectionValue() - except: + except AttributeError: pass if current_owner is not None and previous_owner != current_owner: delivery_list.append(movement) diff --git a/product/ERP5/Document/MappedValue.py b/product/ERP5/Document/MappedValue.py index 61d9dfe36a..7252758fac 100755 --- a/product/ERP5/Document/MappedValue.py +++ b/product/ERP5/Document/MappedValue.py @@ -152,7 +152,7 @@ identify a bank account.""" # Standard accessor try: result = Predicate.getProperty(self, key, d=d) - except: + except AttributeError: result = None return result diff --git a/product/ERP5/Document/Movement.py b/product/ERP5/Document/Movement.py index 85577bc7c9..3e48773d13 100755 --- a/product/ERP5/Document/Movement.py +++ b/product/ERP5/Document/Movement.py @@ -303,7 +303,7 @@ class Movement(XMLObject, Amount): if quantity is None: return None return quantity * price - except: + except TypeError: return None security.declareProtected(Permissions.AccessContentsInformation, 'getDestinationTotalAssetPrice') @@ -319,7 +319,7 @@ class Movement(XMLObject, Amount): if quantity is None: return None return quantity * price - except: + except TypeError: return None # Causality computation @@ -528,7 +528,7 @@ class Movement(XMLObject, Amount): quantity = self.getQuantity() try: quantity = float(quantity) - except: + except TypeError: quantity = 0.0 if quantity < 0: return - quantity @@ -543,7 +543,7 @@ class Movement(XMLObject, Amount): quantity = self.getQuantity() try: quantity = float(quantity) - except: + except TypeError: quantity = 0.0 if quantity < 0: return 0.0 @@ -565,7 +565,7 @@ class Movement(XMLObject, Amount): return 0.0 try: source_debit = float(source_debit) - except: + except TypeError: source_debit = 0.0 self.setQuantity(- source_debit) @@ -578,7 +578,7 @@ class Movement(XMLObject, Amount): return 0.0 try: source_credit = float(source_credit) - except: + except TypeError: source_credit = 0.0 self.setQuantity(source_credit) diff --git a/product/ERP5/Document/Resource.py b/product/ERP5/Document/Resource.py index ef6ab404f6..266bf1ffcc 100755 --- a/product/ERP5/Document/Resource.py +++ b/product/ERP5/Document/Resource.py @@ -95,15 +95,11 @@ class Resource(XMLMatrix, CoreResource, Variated): base_category_list = (base_category_list,) other_base_category_dict = dict([(i,1) for i in base_category_list]) - try: - other_variations = self.searchFolder( \ + other_variations = self.searchFolder( \ portal_type=self.getPortalVariationTypeList(), sort_on=[('title','ascending')]) - except: - other_variations = [] - - other_variations = map(lambda x: x.getObject(), other_variations) - other_variations = filter(lambda x: x is not None, other_variations) + other_variations = [x.getObject() for x in other_variations] + other_variations = [x for x in other_variations if x is not None] for object in other_variations: for base_category in object.getVariationBaseCategoryList(): @@ -263,7 +259,7 @@ class Resource(XMLMatrix, CoreResource, Variated): def getDefaultDestinationAmountBis(self, unit=None, variation=None, REQUEST=None): try: return self.getDestinationReference() - except: + except AttributeError: return None # This patch is temporary and allows to circumvent name conflict in ZSQLCatalog process for Coramy @@ -272,7 +268,7 @@ class Resource(XMLMatrix, CoreResource, Variated): def getDefaultSourceAmountBis(self, unit=None, variation=None, REQUEST=None): try: return self.getSourceReference() - except: + except AttributeError: return None diff --git a/product/ERP5/ERP5Site.py b/product/ERP5/ERP5Site.py index 06629b6356..e431c33fcf 100755 --- a/product/ERP5/ERP5Site.py +++ b/product/ERP5/ERP5Site.py @@ -832,7 +832,7 @@ class ERP5Generator(PortalGenerator): try: # Use NuxUserGroups instead of the standard acl_users. p.manage_addProduct['NuxUserGroups'].addUserFolderWithGroups() - except: + except KeyError: # No way. PortalGenerator.setupUserFolder(self, p) diff --git a/product/ERP5/Extensions/InventoryBrain.py b/product/ERP5/Extensions/InventoryBrain.py index 6881de19a0..996b83ca4d 100755 --- a/product/ERP5/Extensions/InventoryBrain.py +++ b/product/ERP5/Extensions/InventoryBrain.py @@ -78,7 +78,7 @@ class InventoryBrain(ZSQLBrain): try: resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) return resource.getQuantityUnit() - except: + except AttributeError: return '' @@ -136,7 +136,7 @@ class InventoryListBrain(ZSQLBrain): try: resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) return resource.getQuantityUnit() - except: + except AttributeError: return '' def getListItemUrl(self, cname_id, selection_index, selection_name): @@ -189,7 +189,7 @@ class InventoryListBrain(ZSQLBrain): resource = self.portal_categories.unrestrictedTraverse(self.resource_relative_url) return '%s/Resource_movementHistoryView?%s&reset=1' % (resource.absolute_url(), make_query(variation_text=self.variation_text, selection_name=selection_name, selection_index=selection_index)) - except: + except (AttributeError, KeyError): return '' def getAggregateListText(self): diff --git a/product/ERP5/Tool/CategoryTool.py b/product/ERP5/Tool/CategoryTool.py index 0587cd49fc..7cb849f5e5 100755 --- a/product/ERP5/Tool/CategoryTool.py +++ b/product/ERP5/Tool/CategoryTool.py @@ -114,7 +114,7 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool): while o.meta_type == 'ERP5 Category' or o.meta_type == 'CMF Category': o = o.aq_parent uid_dict[(int(o.uid), bo_uid, 0)] = 1 # Non strict - except: + except (TypeError, KeyError): LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path) return uid_dict.keys() diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index e177977a19..721ed77a12 100755 --- a/product/ERP5/Tool/SimulationTool.py +++ b/product/ERP5/Tool/SimulationTool.py @@ -1358,7 +1358,7 @@ class SimulationTool (BaseTool): # XXX WARNING - ADD PRICED QUANTITY cell_price = movement.getPrice() cell_total_price += movement.getNetConvertedTargetQuantity() * cell_price - except: + except TypeError: cell_total_price = None for category in movement.getCategoryList(): if category not in cell_category_list: diff --git a/product/ERP5/Variated.py b/product/ERP5/Variated.py index 6623350e15..c33223cc1d 100755 --- a/product/ERP5/Variated.py +++ b/product/ERP5/Variated.py @@ -154,7 +154,7 @@ class Variated(Base): """ try: resource = self.getDefaultResourceValue() - except: + except AttributeError: resource = None if resource is not None: result = resource.getVariationBaseCategoryList() @@ -200,7 +200,7 @@ class Variated(Base): """ try: resource = self.getDefaultResourceValue() - except: + except AttributeError: resource = None if resource is not None: clist = resource.getVariationRangeCategoryItemList(base_category_list = @@ -217,7 +217,7 @@ class Variated(Base): """ try: resource = self.getDefaultResourceValue() - except: + except AttributeError: resource = None if resource is not None: clist = resource.getVariationRangeCategoryItemList(base_category_list = @@ -234,7 +234,7 @@ class Variated(Base): """ try: resource = self.getDefaultResourceValue() - except: + except AttributeError: resource = None if resource is not None: clist = resource.getVariationRangeCategoryItemList(base_category_list = diff --git a/product/ERP5Form/Form.py b/product/ERP5Form/Form.py index f49dfa38a0..28bafcbccf 100755 --- a/product/ERP5Form/Form.py +++ b/product/ERP5Form/Form.py @@ -37,6 +37,7 @@ from Products.ERP5Type import PropertySheet from urllib import quote from Globals import InitializeClass, PersistentMapping, DTMLFile from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo +from ZODB.POSException import ConflictError from Products.ERP5Type.Utils import UpperCase @@ -85,6 +86,8 @@ def get_value(self, id, **kw): kw['cell'] = kw['REQUEST'] try: value = tales_expr.__of__(self)(**kw) + except ConflictError: + pass except: # We add this safety exception to make sure we always get # something reasonable rather than generate plenty of errors @@ -117,7 +120,7 @@ def get_value(self, id, **kw): key = self.id key = key[3:] value = object.getProperty(key, d=value) - except: + except KeyError: value = None # if normal value is a callable itself, wrap it @@ -194,7 +197,7 @@ def add_and_edit(self, id, REQUEST): return try: u = self.DestinationURL() - except: + except AttributeError: u = REQUEST['URL1'] if REQUEST['submit'] == " Add and Edit ": u = "%s/%s" % (u, quote(id)) @@ -419,7 +422,7 @@ class ERP5Form(ZMIForm, ZopePageTemplate): for k in self.get_field_ids(): try: self._delObject(k) - except: + except AttributeError: pass self.groups = {} self.group_list = [] diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py index fac5452250..d80ce543b9 100755 --- a/product/ERP5Form/ListBox.py +++ b/product/ERP5Form/ListBox.py @@ -44,6 +44,7 @@ from Products.ZSQLCatalog.zsqlbrain import ZSQLBrain from Acquisition import aq_base, aq_inner, aq_parent, aq_self from zLOG import LOG +from ZODB.POSException import ConflictError from Globals import InitializeClass, Persistent, Acquisition, get_request from Products.PythonScripts.Utility import allow_class @@ -792,7 +793,7 @@ class ListBoxWidget(Widget.Widget): # Try to get the method through acquisition try: list_method = getattr(here, list_method.method_name) - except: + except (AttributeError, KeyError): pass elif list_method in (None, ''): # Use current selection # Use previously used list method @@ -808,7 +809,7 @@ class ListBoxWidget(Widget.Widget): # Try to get the method through acquisition try: count_method = getattr(here, count_method.method_name) - except: + except (AttributeError, KeyError): count_method = None else: # No count method defined means that all objects must be retrieved. @@ -829,7 +830,7 @@ class ListBoxWidget(Widget.Widget): try: stat_method = getattr(here, stat_method.method_name) show_stat = 1 - except: + except (AttributeError, KeyError): show_stat = 0 pass else: @@ -889,7 +890,7 @@ class ListBoxWidget(Widget.Widget): select_expression += stats[index] + '(' + sql + ') AS ' + alias + ',' else: select_expression += '\' \' AS ' + alias + ',' - except: + except KeyError: select_expression += '\' \' AS ' + alias + ',' index = index + 1 @@ -906,7 +907,7 @@ class ListBoxWidget(Widget.Widget): try: start = REQUEST.get('list_start') start = int(start) - except: + except (TypeError, KeyError): start = params.get('list_start',0) start = int(start) start = max(start, 0) @@ -1124,7 +1125,7 @@ class ListBoxWidget(Widget.Widget): try: method_path = getPath(here) + '/' + list_method.method_name #LOG('ListBox', 0, 'method_path = %s, getPath = %s, list_method.method_name = %s' % (repr(method_path), repr(getPath(here)), repr(list_method.method_name))) - except: + except AttributeError: method_path = getPath(here) + '/' + list_method.__name__ #LOG('ListBox', 0, 'method_path = %s, getPath = %s, list_method.__name__ = %s' % (repr(method_path), repr(getPath(here)), repr(list_method.__name__))) # Sometimes the seltion name is a list ??? Why ???? @@ -1628,6 +1629,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> del kw['closed_summary'] params = dict(kw) selection.edit(params=params) + except ConflictError: + raise except: LOG('ListBox', 0, 'WARNING: Could not call %s with %s: ' % (repr(attribute_value), repr(params)), error=sys.exc_info()) pass @@ -1637,7 +1640,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> if real_o is None: try: real_o = o.getObject() - except: + except AttributeError: pass if real_o is not None: try: @@ -1651,11 +1654,11 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> attribute_original_value = attribute_value #LOG('Look up accessor %s' % cname_id,0,str(attribute_value)) - except: + except AttributeError: attribute_value = getattr(real_o,property_id) attribute_original_value = attribute_value #LOG('Fallback to attribute %s' % cname_id,0,str(attribute_value)) - except: + except AttributeError: attribute_value = 'Can not evaluate attribute: %s' % sql attribute_original_value = None else: @@ -1669,6 +1672,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> except TypeError: attribute_value = attribute_value() attribute_original_value = attribute_value + except ConflictError: + raise except: LOG('ListBox', 0, 'Could not evaluate', error=sys.exc_info()) attribute_value = "Could not evaluate" @@ -1759,6 +1764,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> list_body = list_body + \ ("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % (td_css, td_align, object_url, attribute_value)) + except ConflictError: + raise except: LOG('ListBox', 0, 'Could not evaluate url_method %s' % column[1], error=sys.exc_info()) list_body = list_body + \ @@ -1773,7 +1780,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> list_body = list_body + \ ("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % (td_css, td_align, object_url, attribute_value)) - except: + except AttributeError: list_body = list_body + \ ("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) ) else: @@ -1782,6 +1789,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> list_body = list_body + \ ("<td class=\"%s\" align=\"%s\"><a href=\"%s\">%s</a></td>" % (td_css, td_align, object_url, attribute_value)) + except ConflictError: + raise except: list_body = list_body + \ ("<td class=\"%s\" align=\"%s\">%s</td>" % (td_css, td_align, attribute_value) ) @@ -1854,6 +1863,8 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> #params['operator'] = stats[n] #value=value(**params) value=value(selection=selection) + except ConflictError: + raise except: LOG('ListBox', 0, 'WARNING: Could not call %s with %s: ' % (repr(value), repr(params)), error=sys.exc_info()) pass @@ -1883,7 +1894,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> #if render_format == 'list': current_listboxline.addColumn( column[1] , None) if render_format == 'list': current_listboxline.addColumn( column[0] , None) - except: + except KeyError: list_body += '<td class="Data"> </td>' #if render_format == 'list': current_listboxline.addColumn( column[1] , None) if render_format == 'list': current_listboxline.addColumn( extended_columns[n][0] , None) diff --git a/product/ERP5Form/PDFTemplate.py b/product/ERP5Form/PDFTemplate.py index 614c9537fa..2c0549c022 100755 --- a/product/ERP5Form/PDFTemplate.py +++ b/product/ERP5Form/PDFTemplate.py @@ -39,6 +39,7 @@ from urllib import quote from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo import urllib2 +from ZODB.POSException import ConflictError from Products.ERP5Type.Utils import UpperCase @@ -75,7 +76,7 @@ def add_and_edit(self, id, REQUEST): return try: u = self.DestinationURL() - except: + except AttributeError: u = REQUEST['URL1'] if REQUEST['submit'] == " Add and Edit ": u = "%s/%s" % (u, quote(id)) @@ -230,6 +231,8 @@ if HAS_ZODB_RESOURCE_HANDLER: if callable(obj): try: obj = obj() + except ConflictError: + raise except: pass @@ -259,6 +262,8 @@ else: if callable(obj): try: obj = obj() + except ConflictError: + raise except: pass diff --git a/product/ERP5Form/PlanningBox.py b/product/ERP5Form/PlanningBox.py index 02f4bf2c6d..a551704d05 100755 --- a/product/ERP5Form/PlanningBox.py +++ b/product/ERP5Form/PlanningBox.py @@ -370,7 +370,7 @@ def createLineObject(meta_types,selection,selection_name,field,REQUEST,list_meth # Try to get the method through acquisition try: list_method = getattr(here, list_method.method_name) - except: + except AttributeError: pass elif list_method in (None, ''): # Use current selection list_method = None diff --git a/product/ERP5Form/Report.py b/product/ERP5Form/Report.py index 9c5e3e3c75..636972e515 100755 --- a/product/ERP5Form/Report.py +++ b/product/ERP5Form/Report.py @@ -156,7 +156,7 @@ def add_and_edit(self, id, REQUEST): return try: u = self.DestinationURL() - except: + except AttributeError: u = REQUEST['URL1'] if REQUEST['submit'] == " Add and Edit ": u = "%s/%s" % (u, quote(id)) diff --git a/product/ERP5Form/Selection.py b/product/ERP5Form/Selection.py index d0cb914b41..ad7f9aef1b 100755 --- a/product/ERP5Form/Selection.py +++ b/product/ERP5Form/Selection.py @@ -308,10 +308,10 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): try: current_zoom=self.params['zoom'] if current_zoom != None: - return self.params['zoom'] + return current_zoom else: return 1 - except: + except KeyError: return 1 security.declarePublic('getReportList') diff --git a/product/ERP5Form/SelectionTool.py b/product/ERP5Form/SelectionTool.py index 557d7d58fa..803778c33d 100755 --- a/product/ERP5Form/SelectionTool.py +++ b/product/ERP5Form/SelectionTool.py @@ -399,7 +399,7 @@ class SelectionTool( UniqueObject, SimpleItem ): if selection is not None: try: return selection.stats - except: + except AttributeError: return stats # That is really bad programming XXX else: return stats @@ -1095,7 +1095,7 @@ class SelectionTool( UniqueObject, SimpleItem ): # be sure that method name is correct try: method_count = string.atoi(method_count_string) - except: + except TypeError: return aq_base_name else: @@ -1103,7 +1103,7 @@ class SelectionTool( UniqueObject, SimpleItem ): # be sure that method name is correct try: sub_index = string.atoi(method_count_string_list[1]) - except: + except TypeError: return aq_base_name else: sub_index = None diff --git a/product/ERP5SyncML/Conduit/BaobabConduit.py b/product/ERP5SyncML/Conduit/BaobabConduit.py index f47ddfac19..9b51cb20d3 100755 --- a/product/ERP5SyncML/Conduit/BaobabConduit.py +++ b/product/ERP5SyncML/Conduit/BaobabConduit.py @@ -32,6 +32,7 @@ from Products.ERP5Type import Permissions from Products.ERP5Type.Utils import convertToUpperCase from Products.CMFCore.utils import getToolByName from Acquisition import aq_base, aq_inner, aq_chain, aq_acquire +from ZODB.POSException import ConflictError import datetime @@ -170,11 +171,11 @@ class BaobabConduit(ERP5Conduit): # Modules below are not always required # (it depends of the nature of objects you want to synchronize) try: cash_inventory_module = object.cash_inventory_module - except: cash_inventory_module = None + except KeyError: cash_inventory_module = None try: bank_account_inventory_module = object.bank_account_inventory_module - except: bank_account_inventory_module = None + except KeyError: bank_account_inventory_module = None try: currency_cash_module = object.currency_cash_module - except: currency_cash_module = None + except KeyError: currency_cash_module = None subobject = None @@ -190,6 +191,8 @@ class BaobabConduit(ERP5Conduit): parent_object_path = erp5_site_path + path try: parent_object = object.restrictedTraverse(parent_object_path) + except ConflictError: + raise except: LOG( 'BaobabConduit:' , 100 @@ -849,4 +852,4 @@ class BaobabConduit(ERP5Conduit): month = date_items[1] year = date_items[2] date = '/'.join([year, month, day]) - document.setStopDate(date) \ No newline at end of file + document.setStopDate(date) diff --git a/product/ERP5Type/Accessor/Base.py b/product/ERP5Type/Accessor/Base.py index 20b1159078..40d26b0b23 100755 --- a/product/ERP5Type/Accessor/Base.py +++ b/product/ERP5Type/Accessor/Base.py @@ -78,7 +78,7 @@ class Setter(Method): if file_upload: try: o = getattr(instance, self._storage_id) - except: + except AttributeError: # We create a default type o = instance.PUT_factory(self._storage_id, file_upload.headers.get('content-type', None), file_upload ) diff --git a/product/ERP5Type/Accessor/TypeDefinition.py b/product/ERP5Type/Accessor/TypeDefinition.py index f7c75b4ba0..798ecabe0a 100755 --- a/product/ERP5Type/Accessor/TypeDefinition.py +++ b/product/ERP5Type/Accessor/TypeDefinition.py @@ -39,7 +39,7 @@ def identity(value): def asFloat(value): try: result = float(value) - except: + except TypeError: result = type_definition['float']['default'] return result @@ -49,21 +49,21 @@ def asDate(value): result = value else: result = DateTime(value) - except: + except TypeError: result = type_definition['date']['default'] return result def asInt(value): try: result = int(value) - except: + except TypeError: result = type_definition['int']['default'] return result def asLong(value): try: result = long(value) - except: + except TypeError: result = type_definition['long']['default'] return result @@ -73,7 +73,7 @@ def asString(value): result = '' else: result = str(value) - except: + except TypeError: result = type_definition['string']['default'] return result diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index 06a3a5f1db..1ac918cda5 100755 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -813,6 +813,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): #LOG("Changing attr: ",0, key) try: ERP5PropertyManager._setProperty(self, key, value, type=type) + except ConflictError: + raise except: # This should be removed if we want strict property checking setattr(self, key, value) @@ -861,6 +863,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): #LOG("Changing attr: ",0, key) try: ERP5PropertyManager._setPropValue(self, key, value) + except ConflictError: + raise except: # This should be removed if we want strict property checking setattr(self, key, value) @@ -878,6 +882,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): method = getattr(self, accessor_name) try: return method() + except ConflictError: + raise except: return 0 else: @@ -916,10 +922,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): Each time attributes of an object are updated, they should be updated through this generic edit method """ - try: - categoryIds = self._getCategoryTool().getBaseCategoryIds() - except: - categoryIds = [] + categoryIds = self._getCategoryTool().getBaseCategoryIds() id_changed = 0 self._v_modified_property_dict = {} for key in kw.keys(): @@ -1520,7 +1523,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): def getIntId(self): try: return int(self.getId()) - except: + except TypeError: return None # Default views diff --git a/product/ERP5Type/CMFCorePatch.py b/product/ERP5Type/CMFCorePatch.py index ecc0f580be..e5aee82be8 100755 --- a/product/ERP5Type/CMFCorePatch.py +++ b/product/ERP5Type/CMFCorePatch.py @@ -300,13 +300,13 @@ def ActionProviderBase_extractAction( self, properties, index ): if type( visible ) is not type( 0 ): try: visible = int( visible ) - except: + except TypeError: visible = 0 if type( optional ) is not type( 0 ): try: optional = int( optional ) - except: + except TypeError: optional = 0 if type( permissions ) is type( '' ): @@ -348,4 +348,4 @@ class PatchedCookieCrumbler(CookieCrumbler): return url return None -CookieCrumbler.getLoginURL=PatchedCookieCrumbler.getLoginURL \ No newline at end of file +CookieCrumbler.getLoginURL=PatchedCookieCrumbler.getLoginURL diff --git a/product/ERP5Type/CopySupport.py b/product/ERP5Type/CopySupport.py index e7109778e8..0888e04524 100755 --- a/product/ERP5Type/CopySupport.py +++ b/product/ERP5Type/CopySupport.py @@ -26,6 +26,7 @@ from Acquisition import aq_base from Products.CMFCore.utils import getToolByName from Globals import PersistentMapping, MessageDialog from Products.ERP5Type.Utils import get_request +from Products.CMFCore.WorkflowCore import WorkflowException from zLOG import LOG import re @@ -206,12 +207,12 @@ class CopyContainer: source_item = '/'.join(copied_item_list[0]) try : pw.doActionFor(self_base, 'edit_action', wf_id='edit_workflow', comment='Object copied from %s' % source_item) - except : + except WorkflowException: pass else : try : pw.doActionFor(self_base, 'edit_action', wf_id='edit_workflow', comment='Object copied as %s' % item.getId()) - except : + except WorkflowException: pass diff --git a/product/ERP5Type/Document/Folder.py b/product/ERP5Type/Document/Folder.py index 28e1fc578d..c11cd5b015 100755 --- a/product/ERP5Type/Document/Folder.py +++ b/product/ERP5Type/Document/Folder.py @@ -116,7 +116,7 @@ class FolderMixIn(ExtensionClass.Base): if id_group is None or id_group=='None': try: my_id = int(self.getLastId()) - except: + except TypeError: my_id = 1 while self.hasContent(str(my_id)): my_id = my_id + 1 @@ -455,7 +455,7 @@ be a problem).""" try: newob = to_class(obase.id) newob.id = obase.id # This line activates obase. - except: + except AttributeError: newob = to_class(id) newob.id = id keys = obase.__dict__.keys() diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 7cebb57904..e6da6b7ff0 100755 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -1393,7 +1393,7 @@ def createDefaultAccessors(property_holder, id, prop = None, default = prop.get('default') try: default = default[0] - except: + except TypeError: default = None accessor_name = 'get' + UpperCase(id) base_accessor = List.Getter(accessor_name, id, prop['type'], default = default, @@ -2568,7 +2568,7 @@ def assertAttributePortalType(o, attribute_name, portal_type): if type(portal_type) is type('a'): portal_type = [portal_type] if getattr(o, attribute_name).portal_type not in portal_type: o._delObject(attribute_name) - except: + except (KeyError, AttributeError): LOG("ERPType Warning: assertAttributePortalType",100,str(o.absolute_url())) ##################################################### diff --git a/product/ZSQLCatalog/ZSQLCatalog.py b/product/ZSQLCatalog/ZSQLCatalog.py index 18bfbc057b..ef8fd087c9 100755 --- a/product/ZSQLCatalog/ZSQLCatalog.py +++ b/product/ZSQLCatalog/ZSQLCatalog.py @@ -706,6 +706,8 @@ class ZCatalog(Folder, Persistent, Implicit): try: obj = self.aq_parent.unrestrictedTraverse(self.getpath(uid, sql_catalog_id=sql_catalog_id)) + except ConflictError: + raise except: LOG('WARNING: ZSQLCatalog',0,'Could not find object for uid %s' % uid) obj = None @@ -903,7 +905,7 @@ class ZCatalog(Folder, Persistent, Implicit): except: return result try: add_result=result.append - except: + except AttributeError: raise AttributeError, `result` for id, ob in items: @@ -966,8 +968,12 @@ class ZCatalog(Folder, Persistent, Implicit): script=REQUEST.script if string.find(path, script) != 0: path='%s/%s' % (script, path) - try: return REQUEST.resolve_url(path) - except: pass + try: + return REQUEST.resolve_url(path) + except ConflictError: + raise + except: + pass def resolve_path(self, path): """ @@ -976,8 +982,12 @@ class ZCatalog(Folder, Persistent, Implicit): style url. If no object is found, None is returned. No exceptions are raised. """ - try: return self.unrestrictedTraverse(path) - except: pass + try: + return self.unrestrictedTraverse(path) + except ConflictError: + raise + except: + pass def manage_normalize_paths(self, REQUEST, sql_catalog_id=None): """Ensure that all catalog paths are full physical paths diff --git a/product/ZSQLCatalog/zsqlbrain.py b/product/ZSQLCatalog/zsqlbrain.py index a8afc83b8b..b058fdc672 100755 --- a/product/ZSQLCatalog/zsqlbrain.py +++ b/product/ZSQLCatalog/zsqlbrain.py @@ -15,6 +15,7 @@ import string import Acquisition import sys +from ZODB.POSException import ConflictError from zLOG import LOG @@ -64,6 +65,8 @@ class ZSQLBrain(Acquisition.Implicit): REQUEST = self.REQUEST obj = self.aq_parent.portal_catalog.resolve_url(self.getPath(), REQUEST) return obj + except ConflictError: + raise except: LOG("ZCatalog WARNING",0,"Could not access object path %s" % self.getPath(), error=sys.exc_info() ) return None @@ -86,6 +89,10 @@ class ZSQLBrain(Acquisition.Implicit): script=REQUEST.script if string.find(path, script) != 0: path='%s/%s' % (script, path) - try: return REQUEST.resolve_url(path) - except: pass + try: + return REQUEST.resolve_url(path) + except ConflictError: + raise + except: + pass -- 2.30.9