Commit 08be2f8c authored by Aurel's avatar Aurel

apply raiser fixer & absolute import fixer

parent 86985db3
......@@ -44,24 +44,24 @@ class InventoryKey(UserDict):
self.data.update(kw)
def clear(self):
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def pop(self, keys, *args):
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def update(self, dict=None, **kwargs): # pylint: disable=redefined-builtin
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def __delitem__(self, key):
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def __setitem__(self, key, item):
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def setdefault(self, key, failobj=None):
if key in self.data:
return self.data[key]
raise TypeError, 'InventoryKey are immutable'
raise TypeError('InventoryKey are immutable')
def __hash__(self):
return hash(tuple(self.items()))
......@@ -162,7 +162,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByNodeMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
resource_uid = movement.getResourceUid()
stock_list = current_stock.setdefault(
......@@ -188,7 +188,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByMirrorSectionMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
mirror_section_uid = movement.getSourceSectionUid()
resource_uid = movement.getResourceUid()
......@@ -219,7 +219,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByPaymentMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
payment_uid = movement.getDestinationPaymentUid()
resource_uid = movement.getResourceUid()
......@@ -258,7 +258,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByNodeMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
section_uid = movement.getDestinationSectionUid()
stock_list = new_stock.setdefault(
......@@ -280,7 +280,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByMirrorSectionMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
section_uid = movement.getDestinationSectionUid()
mirror_section_uid = movement.getSourceSectionUid()
......@@ -305,7 +305,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for movement in self._getGroupByPaymentMovementList():
node_uid = movement.getDestinationUid()
if not node_uid:
raise ValueError, "No destination uid for %s" % movement
raise ValueError("No destination uid for %s" % movement)
section_uid = movement.getDestinationSectionUid()
payment_uid = movement.getDestinationPaymentUid()
......
......@@ -10,7 +10,7 @@ start_date = closing_period.getStartDate()
stop_date = closing_period.getStopDate()
if start_date > stop_date:
raise ValidationFailed, translateString("Start date is after stop date.")
raise ValidationFailed(translateString("Start date is after stop date."))
period_list = [
x
......@@ -23,9 +23,9 @@ period_list = [
for period in period_list:
if start_date <= period.getStopDate() and not stop_date <= period.getStartDate():
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"${date} is already in an open accounting period.",
mapping={'date': start_date})
mapping={'date': start_date}))
previous_period = next(
iter(
......@@ -39,9 +39,9 @@ previous_period = next(
)
if previous_period is not None:
if (start_date - previous_period.getStopDate()) > 1.9:
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"Last opened period ends on ${last_openned_date},"+
" this period starts on ${this_period_start_date}."+
" Accounting Periods must be consecutive.",
mapping = { 'last_openned_date': previous_period.getStopDate(),
'this_period_start_date': start_date } )
'this_period_start_date': start_date } ))
......@@ -34,7 +34,7 @@ while section.getPortalType() == period.getPortalType():
section_category = section.getGroup(base=True)
if not section_category:
raise ValidationFailed, translateString("This Organisation must be member of a Group")
raise ValidationFailed(translateString("This Organisation must be member of a Group"))
# XXX copy and paste from AccountingPeriod_createBalanceTransaction !
......@@ -81,5 +81,5 @@ movement_list = portal.portal_simulation.getMovementHistoryList(
limit=1)
if movement_list:
raise ValidationFailed, translateString(
"All Accounting Transactions for this organisation during the period have to be closed first.")
raise ValidationFailed(translateString(
"All Accounting Transactions for this organisation during the period have to be closed first."))
......@@ -32,21 +32,21 @@ for line in transaction_lines:
):
if account is not None and account.getValidationState() != 'validated':
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"Account ${account_title} is not validated.",
mapping=dict(account_title=account.Account_getFormattedTitle()))
mapping=dict(account_title=account.Account_getFormattedTitle())))
if third_party is not None and\
third_party.getValidationState() in invalid_state_list:
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"Third party ${third_party_name} is invalid.",
mapping=dict(third_party_name=third_party.getTitle()))
mapping=dict(third_party_name=third_party.getTitle())))
if bank_account is not None:
if bank_account.getValidationState() in invalid_state_list:
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"Bank Account ${bank_account_reference} is invalid.",
mapping=dict(bank_account_reference=bank_account.getReference()))
mapping=dict(bank_account_reference=bank_account.getReference())))
if account is not None and account.isMemberOf('account_type/asset/cash/bank'):
# also check that currencies are consistent if we use this quantity for
......@@ -54,11 +54,11 @@ for line in transaction_lines:
bank_account_currency = bank_account.getProperty('price_currency')
if bank_account_currency is not None and \
bank_account_currency != line.getResource():
raise ValidationFailed, translateString(
raise ValidationFailed(translateString(
"Bank Account ${bank_account_reference} "
"uses ${bank_account_currency} as default currency.",
mapping=dict(bank_account_reference=bank_account.getReference(),
bank_account_currency=bank_account.getPriceCurrencyReference()))
bank_account_currency=bank_account.getPriceCurrencyReference())))
source_currency = None
source_section = line.getSourceSectionValue()
......
......@@ -18,7 +18,7 @@ show_parent_accounts = request.get('show_parent_accounts', False)
# flat_mode is a boolean that indicate wether we should use a report tree
# or a flat list of all accounts.
if request.get('tree_mode', False):
raise 'Tree mode no longer supported'
raise ValueError('Tree mode no longer supported')
result = []
params = {
......
......@@ -2,7 +2,7 @@
the new Invoice.
"""
if related_simulation_movement_path_list is None:
raise RuntimeError, 'related_simulation_movement_path_list is missing. Update ERP5 Product.'
raise RuntimeError('related_simulation_movement_path_list is missing. Update ERP5 Product.')
invoice = context
......
......@@ -327,8 +327,8 @@ class TestProductionOrderApparelMixin(TestOrderMixin):
LOG('object.getQuantity()',0,object.getQuantity())
LOG('object.__dict__',0,object.__dict__)
LOG('object.getDeliveryValue().getQuantity()',0,object.getDeliveryValue().getQuantity())
raise AssertionError, "Attribute: %s, Value: %s, Result: %s" %\
(attribute, value, getattr(object, attribute)())
raise AssertionError("Attribute: %s, Value: %s, Result: %s"
% (attribute, value, getattr(object, attribute)()))
def stepCheckProductionSimulation(self, sequence=None, sequence_list=None,
**kw):
......
......@@ -116,7 +116,7 @@ class ArchiveTool(BaseTool):
"""
# First check parameter for destination catalog
if destination_archive_id == archive_id:
raise ValueError, "Archive and destination archive can't be the same"
raise ValueError("Archive and destination archive can't be the same")
portal_catalog =self.portal_catalog
# Guess connection id from current catalog
source_catalog = portal_catalog.getSQLCatalog()
......@@ -126,7 +126,7 @@ class ArchiveTool(BaseTool):
source_deferred_connection_id = source_catalog.getConnectionId(deferred=True)
if source_connection_id is None or source_deferred_connection_id is None:
raise ValueError, "Unable to determine connection id for the current catalog"
raise ValueError("Unable to determine connection id for the current catalog")
# Get destination property from archive
destination_archive_id = destination_archive_id.split(' - ')[0]
......@@ -144,25 +144,25 @@ class ArchiveTool(BaseTool):
# Check we don't use same connection id for source and destination
if destination_sql_catalog_id == source_catalog_id:
raise ValueError, "Destination and source catalog can't be the same"
raise ValueError("Destination and source catalog can't be the same")
if destination_connection_id == source_connection_id:
raise ValueError, "Destination and source connection can't be the same"
raise ValueError("Destination and source connection can't be the same")
if destination_deferred_connection_id == source_deferred_connection_id:
raise ValueError, "Destination and source deferred connection can't be the same"
raise ValueError("Destination and source deferred connection can't be the same")
# Same for source and archive
if archive_sql_catalog_id == source_catalog_id:
raise ValueError, "Archive and source catalog can't be the same"
raise ValueError("Archive and source catalog can't be the same")
if archive_connection_id == source_connection_id:
raise ValueError, "Archive and source connection can't be the same"
raise ValueError("Archive and source connection can't be the same")
if archive_deferred_connection_id == source_deferred_connection_id:
raise ValueError, "Archive and source deferred connection can't be the same"
raise ValueError("Archive and source deferred connection can't be the same")
# Same for destination and archive
if archive_sql_catalog_id == destination_sql_catalog_id:
raise ValueError, "Archive and destination catalog can't be the same"
raise ValueError("Archive and destination catalog can't be the same")
if archive_connection_id == destination_connection_id:
raise ValueError, "Archive and destination connection can't be the same"
raise ValueError("Archive and destination connection can't be the same")
if archive_deferred_connection_id == destination_deferred_connection_id:
raise ValueError, "Archive and destination deferred connection can't be the same"
raise ValueError("Archive and destination deferred connection can't be the same")
# Update connection id in destination and archive catalog if asked
destination_sql_catalog = getattr(portal_catalog, destination_sql_catalog_id)
......
......@@ -8,17 +8,17 @@ start_date = inventory.getStartDate()
if start_date is None:
text = "Sorry, you must define the inventory date"
message = Message(domain='ui', message=text)
raise ValidationFailed, message
raise ValidationFailed(message)
# Make sure the node is defined
node = inventory.getDestination()
if node is None:
text = "Sorry, you must define the inventory warehouse"
message = Message(domain='ui', message=text)
raise ValidationFailed, message
raise ValidationFailed(message)
# use of the constraint
error_list = inventory.checkConsistency()
if len(error_list) > 0:
raise ValidationFailed, (error_list[0].getTranslatedMessage(),)
raise ValidationFailed(error_list[0].getTranslatedMessage())
......@@ -11,7 +11,7 @@ catalog_id = archive.getCatalogId()
if "deferred" not in archive.getDeferredConnectionId():
msg = Message(domain='ui', message='Deferred connection ID choose is not a deferred connection.')
raise ValidationFailed, (msg,)
raise ValidationFailed(msg)
def sort_max_date(a, b):
return cmp(a.getStopDateRangeMax(), b.getStopDateRangeMax())
......@@ -32,7 +32,7 @@ if archive.getStopDateRangeMax() is not None:
break
if previous_archive.getStopDateRangeMax().Date() != min_stop_date:
msg = Message(domain='ui', message='Archive are not contiguous.')
raise ValidationFailed, (msg,)
raise ValidationFailed(msg)
else:
previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_type="Archive",
validation_state='ready')]
......@@ -47,7 +47,7 @@ else:
break
if previous_archive.getStopDateRangeMax().Date() != min_stop_date:
msg = Message(domain='ui', message='Archive are not contiguous.')
raise ValidationFailed, (msg,)
raise ValidationFailed(msg)
# Check the catalog
......@@ -57,4 +57,4 @@ previous_archive_list = [x.getObject() for x in archive.portal_catalog(portal_ty
for arch in previous_archive_list:
if arch.getCatalogId() == catalog_id and arch is not previous_archive:
msg = Message(domain='ui', message='Use of a former catalog is prohibited.')
raise ValidationFailed, (msg,)
raise ValidationFailed(msg)
......@@ -66,7 +66,7 @@ def printBarcodeSheet(self, sheet_number=1, input_list=[], test=False):
ps2pdf_command = '%s %s %s' % (ps2pdf, ps_file_path, new_pdf_file_path)
ret = os.system(ps2pdf_command)
if ret != 0:
raise RuntimeError, 'PS Conversion Failed'
raise RuntimeError('PS Conversion Failed')
file = open(new_pdf_file_path, 'rb')
result = file.read()
file_size = len(result)
......@@ -93,7 +93,7 @@ def printBarcodeSheet(self, sheet_number=1, input_list=[], test=False):
text_command = 'echo "%s" > %s' % (input_list, new_txt_file_path)
ret = os.system(text_command)
if ret != 0:
raise RuntimeError, 'File Creation Failed'
raise RuntimeError('File Creation Failed')
if horizontal_padding not in ('', None) and vertical_padding not in ('', None):
margin = '%sx%s' % (horizontal_padding, vertical_padding)
......@@ -139,7 +139,7 @@ def printBarcodeSheet(self, sheet_number=1, input_list=[], test=False):
barcode_command += ' -o %s ' %(new_ps_file_path)
ret = os.system(barcode_command)
if ret != 0:
raise RuntimeError, 'Barcode PS File Creation Failed'
raise RuntimeError('Barcode PS File Creation Failed')
if test:
return getPdfOutput(self, new_ps_file_path, file_name='TestReferenceSheet.pdf')
......
......@@ -80,7 +80,7 @@ class Agent(Folder, Image):
% self.absolute_url())
return
else :
raise RuntimeError, 'No file or an empty file was specified'
raise RuntimeError('No file or an empty file was specified')
import_file.seek(0)
self.manage_upload(file=import_file)
......
......@@ -58,7 +58,7 @@ class CausalityMovementGroup(MovementGroup):
movement = movement.getParentValue().getParentValue()
explanation_value = movement.getExplanationValue()
if explanation_value is None:
raise ValueError, 'No explanation for movement %s' % movement.getPath()
raise ValueError('No explanation for movement %s' % movement.getPath())
else:
# This is a temp movement
explanation_value = None
......
......@@ -135,7 +135,7 @@ class Url(Coordinate, UrlMixin):
if to_url is None:
to_url = self.getUrlString(None)
if from_url is None or to_url is None:
raise AttributeError, "No mail defined"
raise AttributeError("No mail defined")
portal_notifications = getToolByName(self, 'portal_notifications')
......
......@@ -29,7 +29,7 @@ def generateBarcodeImage(self, barcode_type, data, REQUEST=None):
fp.seek(0)
output = fp.read()
else:
raise NotImplementedError, 'barcode_type=%s is not supported' % barcode_type
raise NotImplementedError('barcode_type=%s is not supported' % barcode_type)
if REQUEST is not None:
REQUEST.RESPONSE.setHeader('Content-Type', 'image/png')
return output
......@@ -290,8 +290,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
for movement in select_method(**kw):
movement = movement.getObject()
if movement in movement_set:
raise SelectMethodError('%s returned %s twice or more' % \
(method_id, movement.getRelativeUrl()))
raise SelectMethodError('%s returned %s twice or more'
% (method_id, movement.getRelativeUrl()))
movement_set.add(movement)
movement_list.append(movement)
......@@ -493,7 +493,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
if delivery is None:
if not self.isDeliveryCreatable():
raise SelectMethodError('No updatable delivery found with %s for %s' \
raise SelectMethodError('No updatable delivery found with %s for %s'
% (self.getPath(), movement_group_node_list))
delivery = self._createDelivery(delivery_module,
......@@ -661,8 +661,9 @@ class BuilderMixin(XMLObject, Amount, Predicate):
else:
movement_list = movement_group_node.getMovementList()
if len(movement_list) != 1:
raise CollectError, "DeliveryBuilder: %s unable to distinct those\
movements: %s" % (self.getId(), str(movement_list))
raise CollectError(
"DeliveryBuilder: %s unable to distinct those movements: %s"
% (self.getId(), movement_list))
else:
# XXX Hardcoded value
base_id = 'movement'
......@@ -720,8 +721,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
membership_criterion_base_category_list=movement.\
getVariationBaseCategoryList())
else:
raise MatrixError, 'Cell: %s already exists on %s' % \
(str(cell_key), str(delivery_line))
raise MatrixError('Cell: %s already exists on %s'
% (cell_key, delivery_line))
object_to_update = cell
self._setUpdated(object_to_update, 'cell')
self._setDeliveryMovementProperties(
......
......@@ -17,4 +17,4 @@ for career_step in career_step_list :
# for now, we only return the first one.
return career_step.getStartDate()
raise ValueError, 'No Career Step Defined.'
raise ValueError('No Career Step Defined.')
......@@ -21,7 +21,7 @@ user_name = context.getId()
# XXX Note : sometimes, you don't want to update security for users who don't belong to your organisation.
# You can then add code in the assignment_workflow script to skip those (if role != internal for instance)
if user_name not in user_folder.getUserNames():
raise RuntimeError, "Error: Zope user '%s' doesn't exist in the acl_users folder" % (user_name)
raise RuntimeError("Error: Zope user %r doesn't exist in the acl_users folder" % user_name)
category_list = []
security_group_list = []
......
......@@ -23,4 +23,4 @@ for assignment in person_object.contentValues(filter={'portal_type': 'Assignment
# The only case when several assignments can be started at the same time is when they share the same 'site' value.
if len(assignment_site_list) != 1:
raise ValidationFailed, "Error: started assignments must have the same site value."
raise ValidationFailed("Error: started assignments must have the same site value.")
......@@ -116,7 +116,7 @@ class BigFile(File):
file = StringIO(file)
if isinstance(file, FileUpload) and not file:
raise ValueError, 'File not specified'
raise ValueError('File not specified')
seek=file.seek
read=file.read
......
......@@ -42,8 +42,8 @@ for person in person_value_list:
resource = inventory.resource_relative_url
if inventory.resource_uid in presence_resource_uid_list:
raise ValueError, "This report does not work when same resource are"\
" used in presence and leave."
raise ValueError("This report does not work when same resource are"
" used in presence and leave.")
person_time = (person_planned_time - person.getAvailableTime(
from_date=from_date,
......
......@@ -36,6 +36,7 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from zLOG import LOG, INFO
from six import reraise
def popenCommunicate(command_list, input_=None, **kwargs):
kwargs.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
......@@ -220,7 +221,7 @@ class CertificateAuthorityTool(BaseTool):
certificate=open(cert).read(),
id=new_id,
common_name=common_name)
except:
except Exception:
e = sys.exc_info()
try:
for p in key, csr, cert:
......@@ -229,7 +230,7 @@ class CertificateAuthorityTool(BaseTool):
except Exception:
# do not raise during cleanup
pass
raise e[0], e[1], e[2]
reraise(*e)
finally:
self._unlockCertificateAuthority()
......@@ -260,7 +261,7 @@ class CertificateAuthorityTool(BaseTool):
created.append(alias)
os.symlink(os.path.basename(crl), alias)
return dict(crl=open(crl).read())
except:
except Exception:
e = sys.exc_info()
try:
for p in 'index.txt', 'crlnumber':
......@@ -272,7 +273,7 @@ class CertificateAuthorityTool(BaseTool):
except Exception:
# do not raise during cleanup
pass
raise e[0], e[1], e[2]
reraise(*e)
finally:
self._unlockCertificateAuthority()
......