Commit 59c338b3 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

py2/py3: explicitly cast dict keys to list.

parent 892e14ec
...@@ -32,6 +32,7 @@ from DateTime import DateTime ...@@ -32,6 +32,7 @@ from DateTime import DateTime
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
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Utils import ensure_list
from erp5.component.mixin.RuleMixin import RuleMixin from erp5.component.mixin.RuleMixin import RuleMixin
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from erp5.component.document.ImmobilisationMovement import NO_CHANGE_METHOD from erp5.component.document.ImmobilisationMovement import NO_CHANGE_METHOD
...@@ -659,8 +660,8 @@ class AmortisationRule(RuleMixin): ...@@ -659,8 +660,8 @@ class AmortisationRule(RuleMixin):
# according to these ratio : the highest ratio gets the priority, then the next # according to these ratio : the highest ratio gets the priority, then the next
# highest is taken into account if corresponding resources are free, and so on # highest is taken into account if corresponding resources are free, and so on
matching_ratio_list.sort(key=lambda x: x['ratio'], reverse=True) matching_ratio_list.sort(key=lambda x: x['ratio'], reverse=True)
calculated_to_match = calculated_period_dict.keys() calculated_to_match = ensure_list(calculated_period_dict.keys())
aggregated_to_match = aggregated_period_dict.keys() aggregated_to_match = ensure_list(aggregated_period_dict.keys())
match_dict = {} match_dict = {}
for matching_ratio in matching_ratio_list: for matching_ratio in matching_ratio_list:
calculated = matching_ratio['calculated_period'] calculated = matching_ratio['calculated_period']
......
...@@ -2947,7 +2947,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -2947,7 +2947,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
e_line = e_line_list[e_line_cursor] e_line = e_line_list[e_line_cursor]
wrong_line = 0 wrong_line = 0
key_cursor = 0 key_cursor = 0
key_list = e_line.keys() key_list = list(e_line.keys())
while key_cursor < len(key_list) and not wrong_line: while key_cursor < len(key_list) and not wrong_line:
key = key_list[key_cursor] key = key_list[key_cursor]
e_value = e_line[key] e_value = e_line[key]
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Utils import ensure_list
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.CMFActivity.ActiveProcess import ActiveProcess from Products.CMFActivity.ActiveProcess import ActiveProcess
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
...@@ -100,8 +101,7 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -100,8 +101,7 @@ class SolverProcess(XMLObject, ActiveProcess):
if solver is None: if solver is None:
continue continue
solver_conviguration_dict = decision.getConfigurationPropertyDict() solver_conviguration_dict = decision.getConfigurationPropertyDict()
configuration_mapping = solver_conviguration_dict.items() configuration_mapping = sorted(solver_conviguration_dict.items()) # Make sure the list is sorted in canonical way
configuration_mapping.sort() # Make sure the list is sorted in canonical way
configuration_mapping = tuple(configuration_mapping) configuration_mapping = tuple(configuration_mapping)
for movement in decision.getDeliveryValueList(): for movement in decision.getDeliveryValueList():
# Detect incompatibilities # Detect incompatibilities
...@@ -164,8 +164,8 @@ class SolverProcess(XMLObject, ActiveProcess): ...@@ -164,8 +164,8 @@ class SolverProcess(XMLObject, ActiveProcess):
for solver, solver_key_dict in grouped_solver_dict.items(): for solver, solver_key_dict in grouped_solver_dict.items():
for solver_key, solver_movement_dict in solver_key_dict.items(): for solver_key, solver_movement_dict in solver_key_dict.items():
solver_instance = self.newContent(portal_type=solver.getId()) solver_instance = self.newContent(portal_type=solver.getId())
solver_instance._setDeliveryValueList(solver_movement_dict.keys()) solver_instance._setDeliveryValueList(ensure_list(solver_movement_dict.keys()))
for movement, configuration_list in solver_movement_dict.iteritems(): for movement, configuration_list in six.iteritems(solver_movement_dict):
for configuration_mapping in configuration_list: for configuration_mapping in configuration_list:
if len(configuration_mapping): if len(configuration_mapping):
solver_instance.updateConfiguration(**dict(configuration_mapping)) solver_instance.updateConfiguration(**dict(configuration_mapping))
......
...@@ -34,6 +34,7 @@ from AccessControl import ClassSecurityInfo ...@@ -34,6 +34,7 @@ from AccessControl import ClassSecurityInfo
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Utils import ensure_list
from erp5.component.interface.IImmobilisationItem import IImmobilisationItem from erp5.component.interface.IImmobilisationItem import IImmobilisationItem
from erp5.component.module.DateUtils import addToDate, getClosestDate, roundDate from erp5.component.module.DateUtils import addToDate, getClosestDate, roundDate
from erp5.component.module.DateUtils import getRoundedMonthBetween, millis from erp5.component.module.DateUtils import getRoundedMonthBetween, millis
...@@ -569,7 +570,7 @@ class ImmobilisableItem(Item, Amount): ...@@ -569,7 +570,7 @@ class ImmobilisableItem(Item, Amount):
extra_cost_price = current_immo_period.get('start_extra_cost_price') extra_cost_price = current_immo_period.get('start_extra_cost_price')
main_price = current_immo_period.get('start_main_price') main_price = current_immo_period.get('start_main_price')
current_immo_period['start_price'] = (main_price or 0.) + (extra_cost_price or 0.) current_immo_period['start_price'] = (main_price or 0.) + (extra_cost_price or 0.)
key_list = current_immo_period.keys() key_list = ensure_list(current_immo_period.keys())
for key in key_list: for key in key_list:
value = current_immo_period[key] value = current_immo_period[key]
if key.find('_') != -1: if key.find('_') != -1:
...@@ -578,7 +579,7 @@ class ImmobilisableItem(Item, Amount): ...@@ -578,7 +579,7 @@ class ImmobilisableItem(Item, Amount):
else: else:
# A period wich is alone only copies start values to initial ones # A period wich is alone only copies start values to initial ones
# So it may be invalid later # So it may be invalid later
key_list = current_immo_period.keys() key_list = ensure_list(current_immo_period.keys())
for key in key_list: for key in key_list:
value = current_immo_period[key] value = current_immo_period[key]
if key.find('_') != -1: if key.find('_') != -1:
......
...@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo ...@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.Utils import ensure_list
from erp5.component.document.Movement import Movement from erp5.component.document.Movement import Movement
from erp5.component.module.ExpandPolicy import policy_dict, TREE_DELIVERED_CACHE_KEY from erp5.component.module.ExpandPolicy import policy_dict, TREE_DELIVERED_CACHE_KEY
...@@ -287,7 +288,7 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin): ...@@ -287,7 +288,7 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
# applicable rule per reference. It indicates a configuration error. # applicable rule per reference. It indicates a configuration error.
applicable_rule_dict.setdefault(reference, rule) applicable_rule_dict.setdefault(reference, rule)
applicable_rule_list = applicable_rule_dict.values() applicable_rule_list = ensure_list(applicable_rule_dict.values())
for applied_rule in list(self.objectValues()): for applied_rule in list(self.objectValues()):
rule = applied_rule.getSpecialiseValue() rule = applied_rule.getSpecialiseValue()
try: try:
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
from warnings import warn from warnings import warn
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from Products.ERP5Type.Utils import ensure_list
class FakeMovementError(Exception) : pass class FakeMovementError(Exception) : pass
class MovementGroupError(Exception) : pass class MovementGroupError(Exception) : pass
...@@ -110,7 +111,7 @@ class MovementGroupNode: ...@@ -110,7 +111,7 @@ class MovementGroupNode:
Get property dict for the futur created object Get property dict for the futur created object
""" """
property_dict = getattr(self, '_property_dict', {}).copy() property_dict = getattr(self, '_property_dict', {}).copy()
for key in property_dict.keys(): for key in ensure_list(property_dict.keys()):
if key.startswith('_'): if key.startswith('_'):
del(property_dict[key]) del(property_dict[key])
return property_dict return property_dict
......
...@@ -43,7 +43,7 @@ class TestOOoParser(unittest.TestCase): ...@@ -43,7 +43,7 @@ class TestOOoParser(unittest.TestCase):
parser = OOoParser() parser = OOoParser()
parser.openFile(open(makeFilePath('import_data_list.ods'), 'rb')) parser.openFile(open(makeFilePath('import_data_list.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Person'], mapping.keys()) self.assertEqual(['Person'], list(mapping.keys()))
person_mapping = mapping['Person'] person_mapping = mapping['Person']
self.assertTrue(isinstance(person_mapping, list)) self.assertTrue(isinstance(person_mapping, list))
self.assertTrue(102, len(person_mapping)) self.assertTrue(102, len(person_mapping))
...@@ -57,13 +57,13 @@ class TestOOoParser(unittest.TestCase): ...@@ -57,13 +57,13 @@ class TestOOoParser(unittest.TestCase):
parser.openFromString( parser.openFromString(
open(makeFilePath('import_data_list.ods'), 'rb').read()) open(makeFilePath('import_data_list.ods'), 'rb').read())
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Person'], mapping.keys()) self.assertEqual(['Person'], list(mapping.keys()))
def test_getSpreadSheetMappingStyle(self): def test_getSpreadSheetMappingStyle(self):
parser = OOoParser() parser = OOoParser()
parser.openFile(open(makeFilePath('import_data_list_with_style.ods'), 'rb')) parser.openFile(open(makeFilePath('import_data_list_with_style.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys()) self.assertEqual(['Feuille1'], list(mapping.keys()))
self.assertEqual(mapping['Feuille1'][1], self.assertEqual(mapping['Feuille1'][1],
['a line with style']) ['a line with style'])
self.assertEqual(mapping['Feuille1'][2], self.assertEqual(mapping['Feuille1'][2],
...@@ -77,7 +77,7 @@ class TestOOoParser(unittest.TestCase): ...@@ -77,7 +77,7 @@ class TestOOoParser(unittest.TestCase):
parser = OOoParser() parser = OOoParser()
parser.openFile(open(makeFilePath('import_data_list_data_type.ods'), 'rb')) parser.openFile(open(makeFilePath('import_data_list_data_type.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys()) self.assertEqual(['Feuille1'], list(mapping.keys()))
self.assertEqual(mapping['Feuille1'][0], self.assertEqual(mapping['Feuille1'][0],
['1234.5678']) ['1234.5678'])
self.assertEqual(mapping['Feuille1'][1], self.assertEqual(mapping['Feuille1'][1],
...@@ -110,7 +110,7 @@ class TestOOoParser(unittest.TestCase): ...@@ -110,7 +110,7 @@ class TestOOoParser(unittest.TestCase):
parser = OOoParser() parser = OOoParser()
parser.openFile(open(makeFilePath('complex_text.ods'), 'rb')) parser.openFile(open(makeFilePath('complex_text.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys()) self.assertEqual(['Feuille1'], list(mapping.keys()))
self.assertEqual(mapping['Feuille1'][0], [' leading space']) self.assertEqual(mapping['Feuille1'][0], [' leading space'])
self.assertEqual(mapping['Feuille1'][1], [' leading space']) self.assertEqual(mapping['Feuille1'][1], [' leading space'])
self.assertEqual(mapping['Feuille1'][2], ['tab\t']) self.assertEqual(mapping['Feuille1'][2], ['tab\t'])
...@@ -120,7 +120,7 @@ class TestOOoParser(unittest.TestCase): ...@@ -120,7 +120,7 @@ class TestOOoParser(unittest.TestCase):
parser = OOoParser() parser = OOoParser()
parser.openFile(open(makeFilePath('empty_cells.ods'), 'rb')) parser.openFile(open(makeFilePath('empty_cells.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping() mapping = parser.getSpreadsheetsMapping()
self.assertEqual(['Feuille1'], mapping.keys()) self.assertEqual(['Feuille1'], list(mapping.keys()))
self.assertEqual(mapping['Feuille1'], self.assertEqual(mapping['Feuille1'],
[ [
['A1', None, 'C1'], ['A1', None, 'C1'],
......
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