Commit c71a47c8 authored by Jérome Perrin's avatar Jérome Perrin

Merge remote-tracking branch 'upstream/master' into zope4py2

parents 5252fde2 e9531ee8
...@@ -224,7 +224,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -224,7 +224,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
file_path = os.path.join(cfg.instancehome, 'tests', test_title+'.py') file_path = os.path.join(cfg.instancehome, 'tests', test_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
f = file(file_path, 'w') f = open(file_path, 'w')
f.write(test_data) f.write(test_data)
f.close() f.close()
self.assertTrue(os.path.exists(file_path)) self.assertTrue(os.path.exists(file_path))
...@@ -2371,7 +2371,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -2371,7 +2371,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
file_path = os.path.join(cfg.instancehome, 'PropertySheet', ps_title+'.py') file_path = os.path.join(cfg.instancehome, 'PropertySheet', ps_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
f = file(file_path, 'w') f = open(file_path, 'w')
f.write(ps_data) f.write(ps_data)
f.close() f.close()
self.assertTrue(os.path.exists(file_path)) self.assertTrue(os.path.exists(file_path))
...@@ -2463,7 +2463,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -2463,7 +2463,7 @@ class BusinessTemplateMixin(ERP5TypeTestCase, LogInterceptor):
file_path = os.path.join(cfg.instancehome, 'PropertySheet', ps_title+'.py') file_path = os.path.join(cfg.instancehome, 'PropertySheet', ps_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
f = file(file_path, 'w') f = open(file_path, 'w')
f.write(ps_data) f.write(ps_data)
f.close() f.close()
self.assertTrue(os.path.exists(file_path)) self.assertTrue(os.path.exists(file_path))
...@@ -8036,7 +8036,7 @@ class _LocalTemplateItemMixin: ...@@ -8036,7 +8036,7 @@ class _LocalTemplateItemMixin:
file_path = os.path.join(self.document_base_path, self.document_title+'.py') file_path = os.path.join(self.document_base_path, self.document_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
f = file(file_path, 'w') f = open(file_path, 'w')
f.write(self.document_data) f.write(self.document_data)
f.close() f.close()
self.assertTrue(os.path.exists(file_path)) self.assertTrue(os.path.exists(file_path))
...@@ -8048,7 +8048,7 @@ class _LocalTemplateItemMixin: ...@@ -8048,7 +8048,7 @@ class _LocalTemplateItemMixin:
file_path = os.path.join(self.document_base_path, self.document_title+'.py') file_path = os.path.join(self.document_base_path, self.document_title+'.py')
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
f = file(file_path, 'w') f = open(file_path, 'w')
f.write(self.document_data_updated) f.write(self.document_data_updated)
f.close() f.close()
self.assertTrue(os.path.exists(file_path)) self.assertTrue(os.path.exists(file_path))
...@@ -8070,12 +8070,12 @@ class _LocalTemplateItemMixin: ...@@ -8070,12 +8070,12 @@ class _LocalTemplateItemMixin:
def stepCheckDocumentExists(self, sequence=None, **kw): def stepCheckDocumentExists(self, sequence=None, **kw):
self.assertFalse(not os.path.exists(sequence['document_path'])) self.assertFalse(not os.path.exists(sequence['document_path']))
self.assertEqual(file(sequence['document_path']).read(), self.assertEqual(open(sequence['document_path']).read(),
sequence['document_data']) sequence['document_data'])
def stepCheckUpdatedDocumentExists(self, sequence=None, **kw): def stepCheckUpdatedDocumentExists(self, sequence=None, **kw):
self.assertFalse(not os.path.exists(sequence['document_path'])) self.assertFalse(not os.path.exists(sequence['document_path']))
self.assertEqual(file(sequence['document_path']).read(), self.assertEqual(open(sequence['document_path']).read(),
sequence['document_data_updated']) sequence['document_data_updated'])
def stepCheckDocumentRemoved(self, sequence=None, **kw): def stepCheckDocumentRemoved(self, sequence=None, **kw):
......
...@@ -693,7 +693,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -693,7 +693,7 @@ class TestCRMMailIngestion(BaseTestCRM):
def _readTestData(self, filename): def _readTestData(self, filename):
"""read test data from data directory.""" """read test data from data directory."""
return file(makeFilePath(filename)).read() return open(makeFilePath(filename)).read()
def _ingestMail(self, filename=None, data=None): def _ingestMail(self, filename=None, data=None):
"""ingest an email from the mail in data dir named `filename`""" """ingest an email from the mail in data dir named `filename`"""
......
...@@ -32,7 +32,7 @@ class FileTransport: ...@@ -32,7 +32,7 @@ class FileTransport:
def send(self, to_url, data, sync_id, content_type): def send(self, to_url, data, sync_id, content_type):
filename = to_url[len('file:/'):] filename = to_url[len('file:/'):]
try: try:
stream = file(filename, 'w') stream = open(filename, 'w')
stream.write(data) stream.write(data)
stream.close() stream.close()
except IOError: except IOError:
......
...@@ -262,7 +262,7 @@ class SynchronizationTool(BaseTool): ...@@ -262,7 +262,7 @@ class SynchronizationTool(BaseTool):
filename = from_url[len('file:'):] filename = from_url[len('file:'):]
xml = None xml = None
try: try:
stream = file(filename, 'r') stream = open(filename, 'r')
except IOError: except IOError:
# XXX-Aurel : Why raising here make unit tests to fail ? # XXX-Aurel : Why raising here make unit tests to fail ?
# raise ValueError("Impossible to read file %s, error is %s" # raise ValueError("Impossible to read file %s, error is %s"
......
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Generic method called when submitting a form in dialog mode. Generic method called when submitting a form in dialog mode.
Responsible for validating form data and redirecting to the form action. Responsible for validating form data and redirecting to the form action.
""" """
import six
# XXX We should not use meta_type properly, # XXX We should not use meta_type properly,
# XXX We need to discuss this problem.(yusei) # XXX We need to discuss this problem.(yusei)
...@@ -131,9 +132,8 @@ if len(listbox_id_list): ...@@ -131,9 +132,8 @@ if len(listbox_id_list):
for listbox_id in listbox_id_list: for listbox_id in listbox_id_list:
listbox_line_list = [] listbox_line_list = []
listbox = kw[listbox_id] listbox = kw[listbox_id]
listbox_keys = listbox.keys() for key, value in sorted(six.iteritems(listbox)):
for key in sorted(listbox_keys): listbox_line = value
listbox_line = listbox[key]
listbox_line['listbox_key'] = key listbox_line['listbox_key'] = key
listbox_line_list.append(listbox_line) listbox_line_list.append(listbox_line)
listbox_line_list = tuple(listbox_line_list) listbox_line_list = tuple(listbox_line_list)
......
...@@ -35,16 +35,12 @@ if p.portal_templates.compareVersions(bt1.getVersion(), bt2.getVersion()) < 0: ...@@ -35,16 +35,12 @@ if p.portal_templates.compareVersions(bt1.getVersion(), bt2.getVersion()) < 0:
else: else:
modified_object_list = getModifiedObjectList(bt1, bt2) modified_object_list = getModifiedObjectList(bt1, bt2)
keys = modified_object_list.keys()
i = 0
object_list = [] object_list = []
for object_id in sorted(keys): for i, (object_id, value) in enumerate(sorted(six.iteritems(modified_object_list))):
object_state, object_class = modified_object_list[object_id] object_state, object_class = value
line = newTempBase(context, 'tmp_install_%s' %(str(i))) line = newTempBase(context, 'tmp_install_%s' %(str(i)))
line.edit(object_id=object_id, object_state=object_state, object_class=object_class, bt1=bt1.getId(), bt2=bt2.getId()) line.edit(object_id=object_id, object_state=object_state, object_class=object_class, bt1=bt1.getId(), bt2=bt2.getId())
line.setUid('new_%s' % object_id) line.setUid('new_%s' % object_id)
object_list.append(line) object_list.append(line)
i += 1
return object_list return object_list
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Utils import ensure_list from Products.ERP5Type.Utils import ensure_list
import six
Base_translateString = context.Base_translateString Base_translateString = context.Base_translateString
def getModifiedObjectList(context): def getModifiedObjectList(context):
...@@ -21,7 +22,6 @@ getModifiedObjectList = CachingMethod(getModifiedObjectList, ...@@ -21,7 +22,6 @@ getModifiedObjectList = CachingMethod(getModifiedObjectList,
cache_id_generator=cache_id_generator) cache_id_generator=cache_id_generator)
modified_object_list = getModifiedObjectList(context) modified_object_list = getModifiedObjectList(context)
keys = ensure_list(modified_object_list.keys())
no_backup_list = ['Action', 'SiteProperty', 'Module', 'Document', no_backup_list = ['Action', 'SiteProperty', 'Module', 'Document',
'PropertySheet', 'Extension', 'Test', 'Product', 'Role', 'PropertySheet', 'Extension', 'Test', 'Product', 'Role',
...@@ -40,10 +40,9 @@ backup_title = Base_translateString('Backup And Upgrade') ...@@ -40,10 +40,9 @@ backup_title = Base_translateString('Backup And Upgrade')
remove_title = Base_translateString('Remove') remove_title = Base_translateString('Remove')
save_and_remove_title = Base_translateString('Backup And Remove') save_and_remove_title = Base_translateString('Backup And Remove')
i = 0
object_list = [] object_list = []
for object_id in sorted(keys): for i, (object_id, value) in enumerate(sorted(six.iteritems(modified_object_list))):
object_state, object_class = modified_object_list[object_id] object_state, object_class = value
line = newTempBase(context, 'tmp_install_%s' %(str(i))) line = newTempBase(context, 'tmp_install_%s' %(str(i)))
if object_state == 'New': if object_state == 'New':
choice_item_list=[[install_title, 'install']] choice_item_list=[[install_title, 'install']]
...@@ -66,7 +65,6 @@ for object_id in sorted(keys): ...@@ -66,7 +65,6 @@ for object_id in sorted(keys):
choice_item_list=choice_item_list) choice_item_list=choice_item_list)
line.setUid('new_%s' % str(object_id)) line.setUid('new_%s' % str(object_id))
object_list.append(line) object_list.append(line)
i += 1
object_list.sort(key=lambda x:(x.object_class, x.object_state)) object_list.sort(key=lambda x:(x.object_class, x.object_state))
return object_list return object_list
...@@ -19,7 +19,7 @@ if hasattr(request, listbox_id): ...@@ -19,7 +19,7 @@ if hasattr(request, listbox_id):
# initialize the listbox # initialize the listbox
listbox=request[listbox_id] listbox=request[listbox_id]
keys_list = sorted(listbox.keys(), key=int) keys_list = sorted(listbox, key=int)
if keys_list != []: if keys_list != []:
first_empty_line_id = int(keys_list[-1])+1 first_empty_line_id = int(keys_list[-1])+1
......
import six
REQUEST = container.REQUEST REQUEST = container.REQUEST
Base_translateString = context.Base_translateString Base_translateString = context.Base_translateString
...@@ -45,8 +46,7 @@ save_and_remove_title = Base_translateString('Backup And Remove') ...@@ -45,8 +46,7 @@ save_and_remove_title = Base_translateString('Backup And Remove')
for bt in bt_id_list: for bt in bt_id_list:
bt_title, modified_object_list = bt_object_dict[bt] bt_title, modified_object_list = bt_object_dict[bt]
keys = modified_object_list.keys() for i, (object_id, value) in enumerate(sorted(six.iteritems(modified_object_list))):
for i, object_id in enumerate(sorted(keys)):
object_state, object_class = modified_object_list[object_id] object_state, object_class = modified_object_list[object_id]
object_id = bt+'|'+object_id object_id = bt+'|'+object_id
line = newTempBase(context, 'tmp_install_%s' % i) line = newTempBase(context, 'tmp_install_%s' % i)
......
...@@ -116,7 +116,7 @@ class URLOpener(FancyURLopener): ...@@ -116,7 +116,7 @@ class URLOpener(FancyURLopener):
if auth: h.putheader('Authorization', 'Basic %s' % auth) if auth: h.putheader('Authorization', 'Basic %s' % auth)
if realhost: h.putheader('Host', realhost) if realhost: h.putheader('Host', realhost)
for args in self.addheaders: apply(h.putheader, args) for args in self.addheaders: h.putheader(*args)
h.endheaders() h.endheaders()
if data is not None: if data is not None:
h.send(data + '\r\n') h.send(data + '\r\n')
......
...@@ -63,7 +63,7 @@ class ExtractMessageCatalog(TestXHTML): ...@@ -63,7 +63,7 @@ class ExtractMessageCatalog(TestXHTML):
messages = dict(getattr(self.portal.Localizer, i)._messages) messages = dict(getattr(self.portal.Localizer, i)._messages)
result[i].update(messages) result[i].update(messages)
f = file('%s.pot' % i, 'w') f = open('%s.pot' % i, 'w')
for msgid in result[i].keys(): for msgid in result[i].keys():
f.write('msgid "%s"\nmsgstr ""\n\n' % msgid) f.write('msgid "%s"\nmsgstr ""\n\n' % msgid)
......
...@@ -186,4 +186,4 @@ class BusinessTemplateInfoDir(BusinessTemplateInfoBase): ...@@ -186,4 +186,4 @@ class BusinessTemplateInfoDir(BusinessTemplateInfoBase):
return fileinfo return fileinfo
def readFileInfo(self, fileinfo): def readFileInfo(self, fileinfo):
return file(fileinfo).read() return open(fileinfo).read()
...@@ -143,26 +143,24 @@ def Base_asXML(object, root=None): ...@@ -143,26 +143,24 @@ def Base_asXML(object, root=None):
# We have to describe the workflow history # We have to describe the workflow history
if getattr(self, 'workflow_history', None) is not None: if getattr(self, 'workflow_history', None) is not None:
workflow_list = self.workflow_history workflow_list = self.workflow_history
workflow_list_keys = workflow_list.keys()
for workflow_id in sorted(workflow_list_keys): # Make sure it is sorted for workflow_id, workflow_action_list in sorted(six.iteritems(workflow_list)): # Make sure it is sorted
for workflow_action in workflow_list[workflow_id]: for workflow_action in workflow_action_list:
workflow_node = SubElement(object, 'workflow_action', workflow_node = SubElement(object, 'workflow_action',
attrib=dict(workflow_id=workflow_id)) attrib=dict(workflow_id=workflow_id))
workflow_variable_list = workflow_action.keys() workflow_variable_list = workflow_action.keys()
for workflow_variable in sorted(workflow_variable_list): for workflow_variable, variable_node_text in sorted(six.iteritems(workflow_action)):
variable_type = "string" # Somewhat bad, should find a better way variable_type = "string" # Somewhat bad, should find a better way
if workflow_variable.find('time') >= 0: if workflow_variable.find('time') >= 0:
variable_type = "date" variable_type = "date"
if workflow_variable.find('language_revs') >= 0: # XXX specific to cps if workflow_variable.find('language_revs') >= 0: # XXX specific to cps
variable_type = "dict" variable_type = "dict"
if workflow_action[workflow_variable] is None: if variable_node_text is None:
variable_type = 'None' variable_type = 'None'
variable_node = SubElement(workflow_node, workflow_variable, variable_node = SubElement(workflow_node, workflow_variable,
attrib=dict(type=variable_type)) attrib=dict(type=variable_type))
if variable_type != 'None': if variable_type != 'None':
variable_node_text = str(workflow_action[workflow_variable]) variable_node.text = six.text_type(str(variable_node_text), 'utf-8')
variable_node.text = six.text_type(variable_node_text, 'utf-8')
if workflow_variable == 'time': if workflow_variable == 'time':
time = variable_node.text time = variable_node.text
......
...@@ -35,7 +35,7 @@ def DA_fromFile(self, filename): ...@@ -35,7 +35,7 @@ def DA_fromFile(self, filename):
""" """
Read the file and update self Read the file and update self
""" """
f = file(filename) f = open(filename)
s = f.read() s = f.read()
f.close() f.close()
self.fromText(s) self.fromText(s)
......
...@@ -113,7 +113,7 @@ def Application_resolveConflict(self, old_state, saved_state, new_state): ...@@ -113,7 +113,7 @@ def Application_resolveConflict(self, old_state, saved_state, new_state):
new_state['test_distributing_node'] = test_distributing_node_set.pop() new_state['test_distributing_node'] = test_distributing_node_set.pop()
old, saved, new = [set(state.pop('test_processing_nodes', {}).items()) old, saved, new = [set(state.pop('test_processing_nodes', {}).items())
for state in old_state, saved_state, new_state] for state in (old_state, saved_state, new_state)]
# The value of these attributes don't have proper __eq__ implementation. # The value of these attributes don't have proper __eq__ implementation.
for attr in '__before_traverse__', '__before_publishing_traverse__': for attr in '__before_traverse__', '__before_publishing_traverse__':
del old_state[attr], saved_state[attr] del old_state[attr], saved_state[attr]
......
...@@ -75,18 +75,23 @@ class Python3StyleTest(ERP5TypeTestCase): ...@@ -75,18 +75,23 @@ class Python3StyleTest(ERP5TypeTestCase):
if error: if error:
self.fail(error) self.fail(error)
def test_raiseFixApplied(self): def test_applyFixApplied(self):
self._testFixer('raise') self._testFixer('apply')
def test_importFixApplied(self):
self._testFixer('import')
def test_hasKeyFixApplied(self): def test_hasKeyFixApplied(self):
self._testFixer('has_key') self._testFixer('has_key')
def test_importFixApplied(self):
self._testFixer('import')
def test_numliteralsFixApplied(self): def test_numliteralsFixApplied(self):
self._testFixer('numliterals') self._testFixer('numliterals')
def test_numliteralsFixApplied(self):
self._testFixer('paren')
def test_raiseFixApplied(self):
self._testFixer('raise')
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -27,7 +27,7 @@ class TestField: ...@@ -27,7 +27,7 @@ class TestField:
class ValidatorTestCase(unittest.TestCase): class ValidatorTestCase(unittest.TestCase):
def assertValidatorRaises(self, exception, error_key, f, *args, **kw): def assertValidatorRaises(self, exception, error_key, f, *args, **kw):
try: try:
apply(f, args, kw) f(*args, **kw)
except exception as e: except exception as e:
if hasattr(e, 'error_key') and e.error_key != error_key: if hasattr(e, 'error_key') and e.error_key != error_key:
self.fail('Got wrong error. Expected %s received %s' % self.fail('Got wrong error. Expected %s received %s' %
......
...@@ -646,10 +646,8 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem): ...@@ -646,10 +646,8 @@ class MessageCatalog(LanguageManager, ObjectManager, SimpleItem):
return x return x
# Generate sorted msgids to simplify diffs # Generate sorted msgids to simplify diffs
dkeys = d.keys() for k, v in sorted(six.iteritems(d)):
for k in sorted(dkeys):
r.append('msgid "%s"' % backslashescape(k)) r.append('msgid "%s"' % backslashescape(k))
v = d[k]
r.append('msgstr "%s"' % backslashescape(v)) r.append('msgstr "%s"' % backslashescape(v))
r.append('') r.append('')
......
...@@ -118,8 +118,7 @@ class BaseMailTemplate: ...@@ -118,8 +118,7 @@ class BaseMailTemplate:
# we want to have it stored in ERP5, for mail threading # we want to have it stored in ERP5, for mail threading
headers['Message-ID'] = make_msgid() headers['Message-ID'] = make_msgid()
# turn headers into an ordered list for predictable header order # turn headers into an ordered list for predictable header order
keys = headers.keys() return msg, values, [(key, value) for key, value in sorted(six.iteritems(headers))]
return msg,values,[(key,headers[key]) for key in sorted(keys)]
security.declarePrivate('_send') security.declarePrivate('_send')
def _send(self,mfrom,mto,msg): def _send(self,mfrom,mto,msg):
......
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