Commit 6db3464c authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: More bytes()/str() fixups.

parent 3819e97f
...@@ -58,6 +58,7 @@ from Products.PythonScripts.Utility import allow_class ...@@ -58,6 +58,7 @@ from Products.PythonScripts.Utility import allow_class
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from warnings import warn from warnings import warn
import cgi import cgi
import six
DEFAULT_LISTBOX_DISPLAY_STYLE = 'table' DEFAULT_LISTBOX_DISPLAY_STYLE = 'table'
DEFAULT_LISTBOX_PAGE_NAVIGATION_TEMPLATE = 'ListBox_viewSliderPageNavigationRenderer' DEFAULT_LISTBOX_PAGE_NAVIGATION_TEMPLATE = 'ListBox_viewSliderPageNavigationRenderer'
...@@ -672,7 +673,7 @@ class ListBoxRenderer(object): ...@@ -672,7 +673,7 @@ class ListBoxRenderer(object):
def getTitle(self): def getTitle(self):
"""Return the title. Make sure that it is in unicode. """Return the title. Make sure that it is in unicode.
""" """
return str(self.field.get_value('title'), self.getEncoding()) return self.field.get_value('title')
def getMaxLineNumber(self): def getMaxLineNumber(self):
"""Return the maximum number of lines shown in a page. """Return the maximum number of lines shown in a page.
...@@ -861,7 +862,10 @@ class ListBoxRenderer(object): ...@@ -861,7 +862,10 @@ class ListBoxRenderer(object):
"""Return the columns. Make sure that the titles are in unicode. """Return the columns. Make sure that the titles are in unicode.
""" """
columns = self.field.get_value('columns') columns = self.field.get_value('columns')
return [(str(c[0]), str(c[1], self.getEncoding())) for c in columns] if six.PY3:
return columns
else:
return [(str(c[0]), str(c[1], self.getEncoding())) for c in columns]
@lazyMethod @lazyMethod
def getAllColumnList(self): def getAllColumnList(self):
...@@ -870,9 +874,14 @@ class ListBoxRenderer(object): ...@@ -870,9 +874,14 @@ class ListBoxRenderer(object):
""" """
all_column_list = list(self.getColumnList()) all_column_list = list(self.getColumnList())
all_column_id_set = {c[0] for c in all_column_list} all_column_id_set = {c[0] for c in all_column_list}
all_column_list.extend((str(c[0]), str(c[1], self.getEncoding())) if six.PY3:
for c in self.field.get_value('all_columns') all_column_list.extend(c
if c[0] not in all_column_id_set) for c in self.field.get_value('all_columns')
if c[0] not in all_column_id_set)
else:
all_column_list.extend((str(c[0]), str(c[1], self.getEncoding()))
for c in self.field.get_value('all_columns')
if c[0] not in all_column_id_set)
return all_column_list return all_column_list
@lazyMethod @lazyMethod
...@@ -887,7 +896,10 @@ class ListBoxRenderer(object): ...@@ -887,7 +896,10 @@ class ListBoxRenderer(object):
""" """
stat_columns = self.field.get_value('stat_columns') stat_columns = self.field.get_value('stat_columns')
if stat_columns: if stat_columns:
stat_column_list = [(str(c[0]), str(c[1], self.getEncoding())) for c in stat_columns] if six.PY3:
stat_column_list = stat_columns
else:
stat_column_list = [(str(c[0]), str(c[1], self.getEncoding())) for c in stat_columns]
else: else:
stat_column_list = [(c[0], c[0]) for c in self.getAllColumnList()] stat_column_list = [(c[0], c[0]) for c in self.getAllColumnList()]
return stat_column_list return stat_column_list
...@@ -917,21 +929,30 @@ class ListBoxRenderer(object): ...@@ -917,21 +929,30 @@ class ListBoxRenderer(object):
"""Return the domain root list. Make sure that the titles are in unicode. """Return the domain root list. Make sure that the titles are in unicode.
""" """
domain_root_list = self.field.get_value('domain_root_list') domain_root_list = self.field.get_value('domain_root_list')
return [(str(c[0]), str(c[1], self.getEncoding())) for c in domain_root_list] if six.PY3:
return domain_root_list
else:
return [(str(c[0]), str(c[1], self.getEncoding())) for c in domain_root_list]
@lazyMethod @lazyMethod
def getReportRootList(self): def getReportRootList(self):
"""Return the report root list. Make sure that the titles are in unicode. """Return the report root list. Make sure that the titles are in unicode.
""" """
report_root_list = self.field.get_value('report_root_list') report_root_list = self.field.get_value('report_root_list')
return [(str(c[0]), str(c[1], self.getEncoding())) for c in report_root_list] if six.PY3:
return report_root_list
else:
return [(str(c[0]), str(c[1], self.getEncoding())) for c in report_root_list]
@lazyMethod @lazyMethod
def getDisplayStyleList(self): def getDisplayStyleList(self):
"""Return the list of avaible display style. Make sure that the """Return the list of avaible display style. Make sure that the
titles are in unicode""" titles are in unicode"""
display_style_list = self.field.get_value('display_style_list') display_style_list = self.field.get_value('display_style_list')
return [(str(c[0]), str(c[1], self.getEncoding())) for c in \ if six.PY3:
return display_style_list
else:
return [(str(c[0]), str(c[1], self.getEncoding())) for c in \
display_style_list] display_style_list]
@lazyMethod @lazyMethod
...@@ -1606,7 +1627,7 @@ class ListBoxRenderer(object): ...@@ -1606,7 +1627,7 @@ class ListBoxRenderer(object):
param = param_dict.get(alias, param_dict.get(sql, u'')) param = param_dict.get(alias, param_dict.get(sql, u''))
if isinstance(param, dict): if isinstance(param, dict):
param = param.get('query', u'') param = param.get('query', u'')
if isinstance(param, str): if isinstance(param, bytes):
param = str(param, self.getEncoding()) param = str(param, self.getEncoding())
# Obtain a search field, if any. # Obtain a search field, if any.
...@@ -1690,7 +1711,11 @@ class ListBoxRenderer(object): ...@@ -1690,7 +1711,11 @@ class ListBoxRenderer(object):
processed_value = editable_field.render_view(value=original_value) processed_value = editable_field.render_view(value=original_value)
if not isinstance(processed_value, str): if not isinstance(processed_value, str):
processed_value = str(str(processed_value), self.getEncoding(), 'replace') if six.PY3:
processed_value = str(processed_value).encode(
self.getEncoding(), 'replace').decode()
else:
processed_value = str(str(processed_value), self.getEncoding(), 'replace')
value_list.append((original_value, processed_value)) value_list.append((original_value, processed_value))
...@@ -2284,7 +2309,11 @@ class ListBoxRendererLine(object): ...@@ -2284,7 +2309,11 @@ class ListBoxRendererLine(object):
if processed_value is None: if processed_value is None:
processed_value = u'' processed_value = u''
elif not isinstance(processed_value, str): elif not isinstance(processed_value, str):
processed_value = str(str(processed_value), renderer.getEncoding(), 'replace') if six.PY3:
processed_value = str(processed_value).encode(
renderer.getEncoding(), 'replace').decode()
else:
processed_value = str(str(processed_value), renderer.getEncoding(), 'replace')
value_list.append((original_value, processed_value)) value_list.append((original_value, processed_value))
...@@ -2398,7 +2427,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2398,7 +2427,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
except AttributeError: except AttributeError:
pass pass
if isinstance(url, str): if isinstance(url, bytes):
url = str(url, encoding) url = str(url, encoding)
if editable_field is not None: if editable_field is not None:
...@@ -2462,7 +2491,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -2462,7 +2491,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
editable=(not self.isSummary()) \ editable=(not self.isSummary()) \
and listbox_defines_column_as_editable and editable, and listbox_defines_column_as_editable and editable,
) )
if isinstance(cell_html, str): if isinstance(cell_html, bytes):
cell_html = str(cell_html, encoding) cell_html = str(cell_html, encoding)
else: else:
cell_html = u'' cell_html = u''
......
...@@ -54,7 +54,7 @@ from Acquisition import aq_base ...@@ -54,7 +54,7 @@ from Acquisition import aq_base
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
import warnings import warnings
import six
_MARKER = [] _MARKER = []
...@@ -1227,7 +1227,10 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -1227,7 +1227,10 @@ class SelectionTool( BaseTool, SimpleItem ):
return None return None
# XXX To avoid the difference of the string representations of int and long, # XXX To avoid the difference of the string representations of int and long,
# convert each element to a string. # convert each element to a string.
return md5(str(sorted(map(str, uid_list)))).hexdigest() if six.PY3:
return md5(str(sorted(uid_list)).encode()).hexdigest()
else:
return md5(str(sorted(map(str, uid_list)))).hexdigest()
# Related document searching # Related document searching
security.declarePublic('viewSearchRelatedDocumentDialog') security.declarePublic('viewSearchRelatedDocumentDialog')
......
...@@ -86,7 +86,7 @@ class TranslatedPropertyGetter(BaseGetter): ...@@ -86,7 +86,7 @@ class TranslatedPropertyGetter(BaseGetter):
localizer = instance.getPortalObject().Localizer localizer = instance.getPortalObject().Localizer
message_catalog = getattr(localizer, domain, None) message_catalog = getattr(localizer, domain, None)
if message_catalog is not None: if message_catalog is not None:
return message_catalog.gettext(str(value, 'utf8'), lang=self._language).encode('utf8') return message_catalog.gettext(value, lang=self._language)
else: else:
return value return value
......
...@@ -97,7 +97,7 @@ class TranslatedGetter(Getter): ...@@ -97,7 +97,7 @@ class TranslatedGetter(Getter):
state_id = wf._getWorkflowStateOf(instance, id_only=1) state_id = wf._getWorkflowStateOf(instance, id_only=1)
warn('Translated workflow state getters, such as %s are deprecated' % warn('Translated workflow state getters, such as %s are deprecated' %
self._id, DeprecationWarning) self._id, DeprecationWarning)
return portal.Localizer.erp5_ui.gettext(state_id).encode('utf8') return portal.Localizer.erp5_ui.gettext(state_id)
psyco.bind(__call__) psyco.bind(__call__)
...@@ -120,7 +120,7 @@ class TranslatedTitleGetter(TitleGetter): ...@@ -120,7 +120,7 @@ class TranslatedTitleGetter(TitleGetter):
if result == '': if result == '':
result = localizer.erp5_ui.gettext(state_title, result = localizer.erp5_ui.gettext(state_title,
lang=selected_language) lang=selected_language)
return result.encode('utf8') return result
psyco.bind(__call__) psyco.bind(__call__)
......
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