Commit 72f02da8 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

fixup! py2/py3: stop using deprecated string functions, that are removed in python 3.

parent 160a9085
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
############################################################################## ##############################################################################
import os import os
from string import zfill
from urllib import urlencode from urllib import urlencode
import tempfile import tempfile
from DateTime import DateTime from DateTime import DateTime
...@@ -82,14 +81,14 @@ def printBarcodeSheet(self, sheet_number=1, input_list=[], test=False): ...@@ -82,14 +81,14 @@ def printBarcodeSheet(self, sheet_number=1, input_list=[], test=False):
tempfile.tempdir = tempdir tempfile.tempdir = tempdir
if test: if test:
#Fake list #Fake list
input_list = os.linesep.join(['TEST%s' % zfill(b, 8) for b in range(1111111, 1111111 + ( row_number * column_number * sheet_number ))]) input_list = os.linesep.join(['TEST%s' % str(b).zfill(8) for b in range(1111111, 1111111 + ( row_number * column_number * sheet_number ))])
elif input_list not in ('', None): elif input_list not in ('', None):
if not isinstance(input_list, list): if not isinstance(input_list, list):
input_list = os.linesep.join(map(escapeString, input_list.split(os.linesep))) input_list = os.linesep.join(map(escapeString, input_list.split(os.linesep)))
else: else:
input_list = os.linesep.join(input_list) input_list = os.linesep.join(input_list)
else: else:
input_list = os.linesep.join(['%s' % zfill(self.portal_ids.generateNewId(id_group='barcode'), 12) for b in range( row_number * column_number * sheet_number )]) input_list = os.linesep.join(['%s' % str(self.portal_ids.generateNewId(id_group='barcode')).zfill(12) for b in range( row_number * column_number * sheet_number )])
text_command = 'echo "%s" > %s' % (input_list, new_txt_file_path) text_command = 'echo "%s" > %s' % (input_list, new_txt_file_path)
ret = os.system(text_command) ret = os.system(text_command)
if ret != 0: if ret != 0:
......
from string import zfill return str(context.portal_ids.getLastGeneratedId(id_group='barcode')).zfill(12)
return zfill(context.portal_ids.getLastGeneratedId(id_group='barcode'),12)
...@@ -35,8 +35,8 @@ for item in item_list: ...@@ -35,8 +35,8 @@ for item in item_list:
item_value = item[int(not is_right_display)] item_value = item[int(not is_right_display)]
# Hash key from item_value # Hash key from item_value
item_split = string.split(item_value, '/') item_split = item_value.split('/')
item_key = string.join(item_split[:split_depth] , '/' ) item_key = '/'.join(item_split[:split_depth])
base_category = item_split[0] base_category = item_split[0]
multi = True multi = True
......
...@@ -30,8 +30,8 @@ for item in item_list: ...@@ -30,8 +30,8 @@ for item in item_list:
item_value = item[int(not is_right_display)] item_value = item[int(not is_right_display)]
# Hash key from item_value # Hash key from item_value
item_split = string.split(item_value, '/') item_split = item_value.split('/')
item_key = string.join(item_split[:split_depth] , '/' ) item_key = '/'.join(item_split[:split_depth])
base_category = item_split[0] base_category = item_split[0]
multi = False # XXX or now budget level are only single value. multi = False # XXX or now budget level are only single value.
......
from string import zfill
################################################## ##################################################
#### About the transformation_rules structure #### #### About the transformation_rules structure ####
# a key indicate that input of that level having the same value must be grouped together # a key indicate that input of that level having the same value must be grouped together
......
from string import zfill
################################################## ##################################################
#### About the transformation_rules structure #### #### About the transformation_rules structure ####
# a key indicate that input of that level having the same value must be grouped together # a key indicate that input of that level having the same value must be grouped together
...@@ -92,7 +90,7 @@ for upper_level_key in structured_input_data: ...@@ -92,7 +90,7 @@ for upper_level_key in structured_input_data:
for second_level in structured_input_data[upper_level_key][1]: for second_level in structured_input_data[upper_level_key][1]:
second_level_id += 10 second_level_id += 10
new_2nd_level_obj = new_1st_level_obj.newContent( portal_type = level_portal_types[1] new_2nd_level_obj = new_1st_level_obj.newContent( portal_type = level_portal_types[1]
, id = zfill(second_level_id, 4) , id = str(second_level_id).zfill(4)
) )
for property_title in second_level.keys(): for property_title in second_level.keys():
new_2nd_level_obj.setProperty(property_title, second_level[property_title]) new_2nd_level_obj.setProperty(property_title, second_level[property_title])
......
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
global portal_object, new_id, l global portal_object, new_id, l
...@@ -14,7 +13,7 @@ def createInputLine(): ...@@ -14,7 +13,7 @@ def createInputLine():
int_len = 3 int_len = 3
o = newTempBase( portal_object o = newTempBase( portal_object
, str(new_id) , str(new_id)
, uid ='new_%s' % zfill(new_id, int_len) , uid ='new_%s' % str(new_id).zfill(int_len)
) )
l.append(o) l.append(o)
......
from string import zfill
destination_obj = context.getObject() destination_obj = context.getObject()
first_level_type = 'Use Case Scenario' first_level_type = 'Use Case Scenario'
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from DateTime import DateTime from DateTime import DateTime
from string import capitalize
from erp5.component.module.DateUtils import centis, getClosestDate, addToDate from erp5.component.module.DateUtils import centis, getClosestDate, addToDate
from erp5.component.module.DateUtils import getDecimalNumberOfYearsBetween from erp5.component.module.DateUtils import getDecimalNumberOfYearsBetween
...@@ -99,7 +98,7 @@ class AmortisationRule(RuleMixin): ...@@ -99,7 +98,7 @@ class AmortisationRule(RuleMixin):
modified_properties = [] modified_properties = []
for (key, value) in calculated_movement.items(): for (key, value) in calculated_movement.items():
if key not in ('name','status','id','divergent'): if key not in ('name','status','id','divergent'):
getter_name = 'get%s' % ''.join([capitalize(o) for o in key.split('_')]) getter_name = 'get%s' % ''.join([o.capitalize() for o in key.split('_')])
getter = getattr(simulation_movement, getter_name) getter = getattr(simulation_movement, getter_name)
previous_value = getter() previous_value = getter()
# Check if this property changes # Check if this property changes
...@@ -109,7 +108,7 @@ class AmortisationRule(RuleMixin): ...@@ -109,7 +108,7 @@ class AmortisationRule(RuleMixin):
if value is None and key.split('_')[-1] == 'value': if value is None and key.split('_')[-1] == 'value':
key = '_'.join(key.split('_')[:-1]) key = '_'.join(key.split('_')[:-1])
setter_name = 'set%s' % ''.join([capitalize(o) for o in key.split('_')]) setter_name = 'set%s' % ''.join([o.capitalize() for o in key.split('_')])
setter = getattr(simulation_movement, setter_name) setter = getattr(simulation_movement, setter_name)
setter(value) setter(value)
simulation_movement.edit(start_date=simulation_movement.getStopDate()) simulation_movement.edit(start_date=simulation_movement.getStopDate())
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
# This script adds the needed actions in the Immobilisation portal_type, and # This script adds the needed actions in the Immobilisation portal_type, and
# each amortisable portal_type # each amortisable portal_type
from string import capitalize
def addAction(portal_type, portal_type_type, country, amortisation_method): def addAction(portal_type, portal_type_type, country, amortisation_method):
print 'Adding UI tab "Amortisation Details" for method %s on portal_type %s... ' % (amortisation_method,portal_type), print 'Adding UI tab "Amortisation Details" for method %s on portal_type %s... ' % (amortisation_method,portal_type),
id = "%s_%s_amortisation_details_view" % (country, amortisation_method) id = "%s_%s_amortisation_details_view" % (country, amortisation_method)
...@@ -22,8 +19,8 @@ def addAction(portal_type, portal_type_type, country, amortisation_method): ...@@ -22,8 +19,8 @@ def addAction(portal_type, portal_type_type, country, amortisation_method):
name = "Amortisation Details", name = "Amortisation Details",
action = action, action = action,
condition = "object/IsUsing%s%sAmortisationMethod" % ( condition = "object/IsUsing%s%sAmortisationMethod" % (
capitalize(country), country.capitalize(),
"".join([capitalize(x) for x in amortisation_method.split('_')]) ), "".join([x.capitalize() for x in amortisation_method.split('_')]) ),
permission = ('View',), permission = ('View',),
category = "object_view", category = "object_view",
visible = 1) visible = 1)
......
from string import capitalize
view_id_basis = "%s_%s_amortisation_method_view_details" view_id_basis = "%s_%s_amortisation_method_view_details"
view_action_basis = "Immobilisation_%s%sAmortisationMethodViewDetails" view_action_basis = "Immobilisation_%s%sAmortisationMethodViewDetails"
view_condition_basis = "object/Immobilisation_isUsing%s%sAmortisationMethod" view_condition_basis = "object/Immobilisation_isUsing%s%sAmortisationMethod"
...@@ -27,9 +25,9 @@ for method in amortisation_method_list: ...@@ -27,9 +25,9 @@ for method in amortisation_method_list:
exists = 1 exists = 1
if not exists: if not exists:
capitalized_id = "".join([capitalize(o) for o in id.split("_")]) capitalized_id = "".join([o.capitalize() for o in id.split("_")])
action_action = view_action_basis % (region, capitalized_id) action_action = view_action_basis % (region, capitalized_id)
action_condition = view_condition_basis % (capitalize(region),capitalized_id) action_condition = view_condition_basis % (region.capitalize(), capitalized_id)
context.addAction(id = action_id, context.addAction(id = action_id,
name = "Amortisation Details", name = "Amortisation Details",
action = action_action, action = action_action,
......
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
portal_object = context.getPortalObject() portal_object = context.getPortalObject()
num = 0 num = 0
...@@ -20,8 +19,8 @@ for [method_id, result] in result_list: ...@@ -20,8 +19,8 @@ for [method_id, result] in result_list:
int_len = 7 int_len = 7
if not result['success']: if not result['success']:
o = newTempBase(portal_object, safe_id) o = newTempBase(portal_object, safe_id)
o.setUid( 'new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.setUid( 'new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit(uid='new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.edit(uid='new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit(**result['object']) o.edit(**result['object'])
result_listbox.append(o) result_listbox.append(o)
......
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
portal_object = context.getPortalObject() portal_object = context.getPortalObject()
num = 0 num = 0
...@@ -25,8 +24,8 @@ for [method_id, result] in result_list: ...@@ -25,8 +24,8 @@ for [method_id, result] in result_list:
num += 1 num += 1
int_len = 3 int_len = 3
o = newTempBase(portal_object, safe_id) o = newTempBase(portal_object, safe_id)
o.setUid( 'new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.setUid( 'new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit(uid='new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.edit(uid='new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit( method_id = method_id o.edit( method_id = method_id
, result = result['message'] , result = result['message']
, object_url = result['object_url'] , object_url = result['object_url']
......
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
num = 0 num = 0
listbox_lines = [] listbox_lines = []
...@@ -23,8 +22,8 @@ for spreadsheet in spreadsheets.keys(): ...@@ -23,8 +22,8 @@ for spreadsheet in spreadsheets.keys():
# int_len is used to fill the uid of the created object like 0000001 # int_len is used to fill the uid of the created object like 0000001
int_len = 7 int_len = 7
o = newTempBase(context, safe_id) o = newTempBase(context, safe_id)
o.setUid('new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.setUid('new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit(uid='new_%s' % zfill(num, int_len)) # XXX There is a security issue here o.edit(uid='new_%s' % str(num).zfill(int_len)) # XXX There is a security issue here
o.edit( o.edit(
id=safe_id, id=safe_id,
spreadsheet_name=spreadsheet, spreadsheet_name=spreadsheet,
......
...@@ -11,8 +11,8 @@ for item in item_list: ...@@ -11,8 +11,8 @@ for item in item_list:
item_value = item[int(not is_right_display)] item_value = item[int(not is_right_display)]
# Hash key from item_value # Hash key from item_value
item_split = string.split(item_value, '/') item_split = item_value.split('/')
item_key = string.join(item_split[:split_depth] , '/' ) item_key = '/'.join(item_split[:split_depth])
base_category = item_split[0] base_category = item_split[0]
if item_key not in sub_field_dict: if item_key not in sub_field_dict:
# Create property dict # Create property dict
......
...@@ -11,8 +11,8 @@ for item in item_list: ...@@ -11,8 +11,8 @@ for item in item_list:
item_value = item[int(not is_right_display)] item_value = item[int(not is_right_display)]
# Hash key from item_value # Hash key from item_value
item_split = string.split(item_value, '/') item_split = item_value.split('/')
item_key = string.join(item_split[:split_depth] , '/' ) item_key = '/'.join(item_split[:split_depth])
if item_key not in sub_field_dict: if item_key not in sub_field_dict:
# Create property dict # Create property dict
......
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
portal_object = context.getPortalObject() portal_object = context.getPortalObject()
...@@ -15,7 +14,7 @@ def createInputLine(new_id): ...@@ -15,7 +14,7 @@ def createInputLine(new_id):
int_len = 3 int_len = 3
o = newTempBase( portal_object, o = newTempBase( portal_object,
str(new_id), str(new_id),
uid ='new_%s' % zfill(new_id, int_len) uid ='new_%s' % str(new_id).zfill(int_len)
) )
l.append(o) l.append(o)
......
...@@ -5,7 +5,6 @@ information is correct. ...@@ -5,7 +5,6 @@ information is correct.
portal = context.getPortalObject() portal = context.getPortalObject()
line_portal_type = "Sale Order Line" line_portal_type = "Sale Order Line"
request = context.REQUEST request = context.REQUEST
from string import zfill
from Products.PythonScripts.standard import Object from Products.PythonScripts.standard import Object
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
...@@ -31,7 +30,7 @@ i = 1 ...@@ -31,7 +30,7 @@ i = 1
project_search_dict = {} project_search_dict = {}
for line in line_list: for line in line_list:
line_dict = {} line_dict = {}
key = zfill(i,3) key = str(i).zfill(3)
for property_name in ('title', 'quantity_unit_title', 'quantity', for property_name in ('title', 'quantity_unit_title', 'quantity',
'resource_title', 'total_price', 'price', 'resource_title', 'total_price', 'price',
'reference', 'relative_url'): 'reference', 'relative_url'):
......
...@@ -17,8 +17,8 @@ for item in item_list: ...@@ -17,8 +17,8 @@ for item in item_list:
# Get value of the item # Get value of the item
item_value = item[int(not is_right_display)] item_value = item[int(not is_right_display)]
# Hash key from item_value # Hash key from item_value
item_split = string.split(item_value, '/') item_split = item_value.split('/')
item_key = string.join(item_split[:split_depth] , '/' ) item_key = '/'.join(item_split[:split_depth])
base_category = item_split[0] base_category = item_split[0]
sub_field_property_dict = sub_field_dict.setdefault(item_key, default_sub_field_property_dict.copy()) sub_field_property_dict = sub_field_dict.setdefault(item_key, default_sub_field_property_dict.copy())
......
divergence_messages_list = context.getDivergenceList() divergence_messages_list = context.getDivergenceList()
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from string import zfill
portal_object = context.getPortalObject() portal_object = context.getPortalObject()
l = [] l = []
...@@ -13,7 +11,7 @@ def createInputLine(d_message, new_id): ...@@ -13,7 +11,7 @@ def createInputLine(d_message, new_id):
o = newTempBase( portal_object o = newTempBase( portal_object
, str(new_id) , str(new_id)
, uid ='new_%s' % zfill(new_id, int_len) , uid ='new_%s' % str(new_id).zfill(int_len)
, message = str(d_message.getTranslatedMessage()) , message = str(d_message.getTranslatedMessage())
, tested_property_id = d_message.getProperty('tested_property') , tested_property_id = d_message.getProperty('tested_property')
, object_title = d_message.getObject().getTranslatedTitle() , object_title = d_message.getObject().getTranslatedTitle()
......
...@@ -32,7 +32,6 @@ import zope.interface ...@@ -32,7 +32,6 @@ import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from DateTime import DateTime from DateTime import DateTime
from string import capitalize
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.interface.IImmobilisationItem import IImmobilisationItem from erp5.component.interface.IImmobilisationItem import IImmobilisationItem
...@@ -469,7 +468,7 @@ class ImmobilisableItem(Item, Amount): ...@@ -469,7 +468,7 @@ class ImmobilisableItem(Item, Amount):
property_list.extend(movement.getUncontinuousNeededSpecificParameterListForItem(self)) property_list.extend(movement.getUncontinuousNeededSpecificParameterListForItem(self))
property_list.extend(movement.getFacultativeSpecificParameterListForItem(self)) property_list.extend(movement.getFacultativeSpecificParameterListForItem(self))
for key,value,_ in property_list: for key,value,_ in property_list:
value = 'get' + ''.join(map(capitalize, value.split('_'))) value = 'get' + ''.join(e.capitalize() for e in value.split('_'))
value = getattr(movement, value, None) value = getattr(movement, value, None)
if value is not None: if value is not None:
value = value() value = value()
......
...@@ -33,8 +33,6 @@ from Products.ERP5Type import Permissions, PropertySheet ...@@ -33,8 +33,6 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from erp5.component.document.Movement import Movement from erp5.component.document.Movement import Movement
from string import capitalize
UNIMMOBILISING_METHOD = "unimmobilise" UNIMMOBILISING_METHOD = "unimmobilise"
NO_CHANGE_METHOD = "no_change" NO_CHANGE_METHOD = "no_change"
AMORTISATION_METHOD_PREFIX = "portal_skins/erp5_accounting_" AMORTISATION_METHOD_PREFIX = "portal_skins/erp5_accounting_"
...@@ -103,7 +101,7 @@ class ImmobilisationMovement(Movement, XMLObject): ...@@ -103,7 +101,7 @@ class ImmobilisationMovement(Movement, XMLObject):
def checkValuesAreNotNone(property_list): def checkValuesAreNotNone(property_list):
errors = [] errors = []
for key, value, name in property_list: for key, value, name in property_list:
value = 'get' + ''.join(map(capitalize, value.split('_'))) value = 'get' + ''.join(capitalize(e) for e in value.split('_'))
value = getattr(self, value, None) value = getattr(self, value, None)
if value is not None: if value is not None:
value = value() value = value()
......
...@@ -339,7 +339,6 @@ class DB(TM): ...@@ -339,7 +339,6 @@ class DB(TM):
c = self._query('SHOW COLUMNS FROM %s' % table_name) c = self._query('SHOW COLUMNS FROM %s' % table_name)
except Exception: except Exception:
return () return ()
from string import join
r=[] r=[]
for Field, Type, Null, Key, Default, Extra in c.fetch_row(0): for Field, Type, Null, Key, Default, Extra in c.fetch_row(0):
info = {} info = {}
...@@ -363,7 +362,7 @@ class DB(TM): ...@@ -363,7 +362,7 @@ class DB(TM):
info['Name'] = Field info['Name'] = Field
info['Type'] = type_xlate.get(short_type,'string') info['Type'] = type_xlate.get(short_type,'string')
info['Extra'] = Extra, info['Extra'] = Extra,
info['Description'] = join([Type, field_default, Extra or '', info['Description'] = ' '.join([Type, field_default, Extra or '',
key_types.get(Key, Key or ''), key_types.get(Key, Key or ''),
Null != 'YES' and 'NOT NULL' or '']), Null != 'YES' and 'NOT NULL' or '']),
info['Nullable'] = Null == 'YES' info['Nullable'] = Null == 'YES'
......
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