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

py2/py3: unicode() does not exist in Python 3.

parent 54b93a15
......@@ -4,6 +4,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/TradeModelLine_view/my_quantity/render_pdf;
price_renderer nocall:here/OrderLine_view/my_total_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())"> <office:scripts/>
<office:font-face-decls>
<style:font-face style:name="StarSymbol" svg:font-family="StarSymbol" style:font-charset="x-symbol"/>
......
......@@ -3,6 +3,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/Base_viewTradeFieldLibrary/my_view_mode_quantity/render_pdf;
price_renderer nocall:here/Base_viewTradeFieldLibrary/my_view_mode_total_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language());">
<head>
<meta charset="utf-8">
......
......@@ -3,6 +3,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/Base_viewMRPFieldLibrary/my_quantity/render_pdf;
price_renderer nocall:here/Base_viewMRPFieldLibrary/my_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())">
<office:scripts/>
<office:font-face-decls>
......
<office:document-content xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:tal='http://xml.zope.org/namespaces/tal' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:i18n='http://xml.zope.org/namespaces/i18n' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:metal='http://xml.zope.org/namespaces/metal' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oooc='http://openoffice.org/2004/calc' tal:attributes='dummy python:request.RESPONSE.setHeader("Content-Type", "text/html;; charset=utf-8")' office:version='1.0'
tal:define='data_dict here/ProductionPackingList_getODTDataDict'>
tal:define='data_dict here/ProductionPackingList_getODTDataDict;
unicode python: unicode if bytes==str else lambda t, encoding: t;'>
<office:scripts/>
<office:font-face-decls>
<style:font-face svg:font-family='StarSymbol' style:name='StarSymbol' style:font-charset='x-symbol'/>
......
<office:document-content xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:tal='http://xml.zope.org/namespaces/tal' xmlns:i18n='http://xml.zope.org/namespaces/i18n' xmlns:metal='http://xml.zope.org/namespaces/metal' tal:attributes='dummy python:request.RESPONSE.setHeader("Content-Type", "text/html;; charset=utf-8")' office:version='1.0' tal:define="global frame_width python:25.8; render_prefix render_prefix|nothing" metal:define-macro="master" i18n:domain="erp5_ui">
<tal:block metal:use-macro="here/style_macros/macros/style_macro"/>
<office:body>
<office:body tal:define="unicode python: unicode if bytes==str else lambda t, encoding: t;">
<office:spreadsheet>
<table:table table:style-name='ta1' table:print='false' tal:attributes="table:name python: unicode(here.getTitle(), 'utf-8')" i18n:attributes="table:name">
......
<office:document-content xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:tal='http://xml.zope.org/namespaces/tal' xmlns:i18n='http://xml.zope.org/namespaces/i18n' xmlns:metal='http://xml.zope.org/namespaces/metal' tal:attributes='dummy python:request.RESPONSE.setHeader("Content-Type", "text/html;; charset=utf-8")' office:version='1.0' tal:define="global frame_width python:25.8; global landscape python: int(request.get('landscape', 0) or 0)" metal:define-macro="master" i18n:domain="erp5_ui">
<tal:block metal:use-macro="here/style_macros/macros/style_macro"/>
<office:body>
<office:body tal:define="unicode python: unicode if bytes==str else lambda t, encoding: t">
<office:spreadsheet>
<tal:block tal:define="rendered_report_item_list rendered_report_item_list | python:[];
report_item_list python: rendered_report_item_list or [];
dummy python: request.set('here', here);
unicode python: unicode if bytes==str else lambda t, encoding: t;
global sheet_per_report_section python: request.get('sheet_per_report_section', False); ">
<tal:block tal:condition="not: report_item_list">
<tal:block tal:condition="python: form.meta_type == 'ERP5 Report'">
......
<office:document-content xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:tal='http://xml.zope.org/namespaces/tal' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:i18n='http://xml.zope.org/namespaces/i18n' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:metal='http://xml.zope.org/namespaces/metal' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:oooc='http://openoffice.org/2004/calc' tal:attributes='dummy python:request.RESPONSE.setHeader("Content-Type", "text/html;; charset=utf-8")' office:version='1.0'
tal:define="quantity_renderer nocall:here/Base_viewFieldLibrary/my_money_quantity/render_pdf;
price_renderer nocall:here/PaySheetTransaction_viewFieldLibrary/my_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())">
<office:scripts/>
<office:font-face-decls>
......
......@@ -4,6 +4,7 @@
quantity_renderer nocall:here/Base_viewFieldLibrary/my_view_mode_money_quantity/render_pdf;
gross_category python:'base_amount/payroll/report/salary/gross';
price_renderer nocall:here/PaySheetTransaction_viewFieldLibrary/my_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())">
<office:scripts/>
<office:font-face-decls>
......
......@@ -2,6 +2,7 @@
macro is found. It's used to display description field -->
<tal:block
tal:define="unicode python: unicode if bytes==str else lambda t, encoding: t;"
xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'
xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0'
xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0'
......
......@@ -27,9 +27,10 @@
xmlns:metal='http://xml.zope.org/namespaces/metal'>
<tal:block metal:define-macro="other_informations"
tal:define="data_dict here/PaySheetTransaction_getOtherInformationsDataDict;
quantity_renderer nocall:here/Base_viewFieldLibrary/my_view_mode_money_quantity/render_pdf;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language());
hour_renderer nocall:here/AnnotationLine_viewFieldLibrary/my_work_time_annotation_line_quantity/render_pdf;">
quantity_renderer nocall:here/Base_viewFieldLibrary/my_view_mode_money_quantity/render_pdf;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language());
unicode python: unicode if bytes==str else lambda t, encoding: t;
hour_renderer nocall:here/AnnotationLine_viewFieldLibrary/my_work_time_annotation_line_quantity/render_pdf;">
<table:table-row table:style-name='Tableau3.8'>
<table:table-cell table:style-name='Tableau3.A8' office:value-type='string'>
<text:p text:style-name='Table_20_Contents' />
......
......@@ -3,6 +3,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/Base_viewTradeFieldLibrary/my_view_mode_quantity/render_pdf;
price_renderer nocall:here/Base_viewTradeFieldLibrary/my_view_mode_total_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language());">
<head>
<meta charset="utf-8">
......
......@@ -3,6 +3,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/TradeModelLine_view/my_quantity/render_pdf;
price_renderer nocall:here/OrderLine_view/my_total_price/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())">
<office:scripts/>
<office:font-face-decls>
......
......@@ -3,6 +3,7 @@
set_precision python: request.set('precision', here.getQuantityPrecisionFromResource(here.getPriceCurrency()));
quantity_renderer nocall:here/TradeModelLine_view/my_quantity/render_pdf;
date_renderer nocall:here/OrderLine_view/my_start_date/render_pdf;
unicode python: unicode if bytes==str else lambda t, encoding: t;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language())">
<office:scripts/>
<office:font-face-decls>
......
"""Returns the `text_content` that should be set on the translation data script for this RJS website.
"""
import json
from Products.ERP5Type.Utils import str2unicode, unicode2str
portal = context.getPortalObject()
Base_translateString = context.Base_translateString
......@@ -38,14 +39,13 @@ tmp = {}
for language in context.getAvailableLanguageSet():
tmp[language] = {}
for word in translatable_message_set:
tmp[language][word] = unicode(Base_translateString(word, lang = language), 'utf-8')
tmp[language][word] = str2unicode(Base_translateString(word, lang = language))
# We pass unicode to this json.dump(ensure_ascii=False), so that it produce
# UTF-8 string and not escaped characters. At the end we return an UTF-8
# encoded string and not an unicode instance, because text_content property
# is usually UTF-8 encoded str (not unicode).
return (u"""/**
return unicode2str(u"""/**
* This translation data is generated automatically and updated with upgrader in post-upgarde.
* Do not edit manually, but use "Update Translation Data" action on web site to update from
* Localizer and from data-i18n tags on web pages.
......@@ -64,4 +64,4 @@ return (u"""/**
sort_keys=True,
indent=2,
ensure_ascii=False,
separators=(',', ': ')).splitlines()))).encode('utf-8')
separators=(',', ': ')).splitlines())))
......@@ -2,6 +2,7 @@ from Products.PythonScripts.standard import Object
from ZODB.POSException import ConflictError
from zExceptions import Unauthorized
from Products.ERP5Type.Document import newTempBase
import six
Base_translateString = context.Base_translateString
try:
......@@ -43,19 +44,19 @@ for prop_dict in context.getPropertyMap():
new_value = base_error_message
if new_value != old_value or error:
# check if values are unicode convertible (binary are not)
if isinstance(new_value, (str, unicode)):
if not isinstance(new_value, six.text_type):
try:
unicode(str(new_value), 'utf-8')
six.text_type(new_value if isinstance(new_value, bytes) else str(new_value), 'utf-8')
except UnicodeDecodeError:
new_value = binary_data_explanation
if isinstance(old_value, (str, unicode)):
if not isinstance(old_value, six.text_type):
try:
unicode(str(old_value), 'utf-8')
six.text_type(old_value if isinstance(old_value, bytes) else str(old_value), 'utf-8')
except UnicodeDecodeError:
old_value = binary_data_explanation
if isinstance(current_value, (str, unicode)):
if not isinstance(current_value, six.text_type):
try:
unicode(str(current_value), 'utf-8')
six.text_type(current_value if isinstance(current_value, bytes) else str(current_value), 'utf-8')
except UnicodeDecodeError:
current_value = binary_data_explanation
x = {'property_name': prop,
......
......@@ -53,7 +53,7 @@ def checkPythonScript(script_instance, script_path):
'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math']
code = script_instance.body()
if six.PY2:
code = unicode(code, 'utf8')
code = six.text_type(code, 'utf8')
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'bound_names': extra_builtins +
script_instance.getBindingAssignments().getAssignedNamesInOrder(),
......@@ -80,7 +80,7 @@ def checkComponent(component_instance):
jio_key=component_relative_url,),)
code = component_instance.getTextContent()
if six.PY2:
code = unicode(code, 'utf8')
code = six.text_type(code, 'utf8')
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'code': code}))['annotations']:
annotation['component_path'] = component_relative_url
......
......@@ -706,7 +706,7 @@ class ListBoxRenderer:
"""Return the title. Make sure that it is in unicode.
"""
if six.PY2:
return unicode(self.field.get_value('title'), self.getEncoding())
return six.text_type(self.field.get_value('title'), self.getEncoding())
else:
return self.field.get_value('title')
......@@ -898,7 +898,7 @@ class ListBoxRenderer:
"""
columns = self.field.get_value('columns')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in columns]
return [(str(c[0]), six.text_type(c[1], self.getEncoding())) for c in columns]
else:
return columns
......@@ -910,7 +910,7 @@ class ListBoxRenderer:
all_column_list = list(self.getColumnList())
all_column_id_set = {c[0] for c in all_column_list}
if six.PY2:
all_column_list.extend((str(c[0]), unicode(c[1], self.getEncoding()))
all_column_list.extend((str(c[0]), six.text_type(c[1], self.getEncoding()))
for c in self.field.get_value('all_columns')
if c[0] not in all_column_id_set)
else:
......@@ -932,7 +932,7 @@ class ListBoxRenderer:
stat_columns = self.field.get_value('stat_columns')
if stat_columns:
if six.PY2:
stat_column_list = [(str(c[0]), unicode(c[1], self.getEncoding())) for c in stat_columns]
stat_column_list = [(str(c[0]), six.text_type(c[1], self.getEncoding())) for c in stat_columns]
else:
stat_column_list = stat_columns
else:
......@@ -965,7 +965,7 @@ class ListBoxRenderer:
"""
domain_root_list = self.field.get_value('domain_root_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in domain_root_list]
return [(str(c[0]), six.text_type(c[1], self.getEncoding())) for c in domain_root_list]
else:
return domain_root_list
......@@ -975,7 +975,7 @@ class ListBoxRenderer:
"""
report_root_list = self.field.get_value('report_root_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in report_root_list]
return [(str(c[0]), six.text_type(c[1], self.getEncoding())) for c in report_root_list]
else:
return report_root_list
......@@ -985,7 +985,7 @@ class ListBoxRenderer:
titles are in unicode"""
display_style_list = self.field.get_value('display_style_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in \
return [(str(c[0]), six.text_type(c[1], self.getEncoding())) for c in \
display_style_list]
else:
return display_style_list
......@@ -1749,7 +1749,7 @@ class ListBoxRenderer:
if not isinstance(processed_value, six.text_type):
if six.PY2:
processed_value = unicode(str(processed_value), self.getEncoding(), 'replace')
processed_value = six.text_type(str(processed_value), self.getEncoding(), 'replace')
else:
processed_value = str(processed_value).encode(
self.getEncoding(), 'replace').decode()
......@@ -2384,7 +2384,7 @@ class ListBoxRendererLine:
processed_value = u''
elif not isinstance(processed_value, six.text_type):
if six.PY2:
processed_value = unicode(str(processed_value), renderer.getEncoding(), 'replace')
processed_value = six.text_type(str(processed_value), renderer.getEncoding(), 'replace')
else:
processed_value = str(processed_value).encode(
renderer.getEncoding(), 'replace').decode()
......
......@@ -44,6 +44,7 @@ from ZODB.POSException import ConflictError
from Products.ERP5Type.Utils import UpperCase
from zLOG import LOG
import six
try:
from webdav.Lockable import ResourceLockedError
......@@ -304,18 +305,16 @@ if ReportTool:
#LOG('ReportTool_renderPDF', 0, 'encoding = %r' % encoding)
rhandler = ERP5ResourceHandler(context, getattr(self, 'resourcePath', None))
# if zope gives us the xml in unicode
# we need to encode it before it can be parsed
template_xml = getattr(context, templatename)(*args, **kwargs)
if type(template_xml) is type(u''):
template_xml = self._encode(template_xml, encoding)
if type(document_xml) is type(u''):
document_xml = self._encode(document_xml, encoding)
if not isinstance(template_xml, six.text_type):
template_xml = template_xml.decode(encoding)
if not isinstance(document_xml, six.text_type):
document_xml = document_xml.decode(encoding)
#LOG('ReportTool_renderPDF', 0, 'template_xml = %r, document_xml = %r' % (template_xml, document_xml))
# XXXXX Because reportlab does not support UTF-8, use Latin-1. What a mess.
template_xml = unicode(template_xml,encoding).encode('iso-8859-1')
document_xml = unicode(document_xml,encoding).encode('iso-8859-1','replace')
template_xml = template_xml.encode('iso-8859-1')
document_xml = document_xml.encode('iso-8859-1', 'replace')
encoding = 'iso-8859-1'
# create the PDFTemplate from xml
......
......@@ -894,7 +894,9 @@ class ODFStrategy(Implicit):
if isinstance(field_value, six.text_type):
value = field_value
elif field_value is not None:
value = unicode(str(field_value), 'utf-8')
value = str(field_value)
if six.PY2:
value = value.decode('utf-8')
return value
class ODTStrategy(ODFStrategy):
......
......@@ -98,7 +98,7 @@ def asString(value):
if value is None:
result = ''
else:
if six.PY2 and isinstance(value, unicode):
if six.PY2 and isinstance(value, six.text_type):
result = value.encode('utf-8')
elif six.PY3 and isinstance(value, bytes):
result = value.decode('utf-8')
......
......@@ -1389,10 +1389,14 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
with self.assertRaises(TypeError):
person.setSocialTitle(social_title_value)
# Passing a unicode object to a not-Value setter should raise
with self.assertRaises(TypeError):
organisation = self.portal.organisation_module.newContent()
person.setSubordination(unicode(organisation.getRelativeUrl()))
if six.PY2:
# Passing a unicode object to a not-Value setter should raise
person.setSubordination(six.text_type(organisation.getRelativeUrl()))
else:
# Passing a bytes object to a not-Value setter should raise
person.setSubordination(organisation.getRelativeUrl().encode())
from Products.ERP5Type.Tool.ComponentTool import ComponentTool
......
......@@ -535,7 +535,7 @@ class SafeHTML:
# avoid breaking now.
# continue into the loop with repaired html
else:
if isinstance(orig, unicode):
if isinstance(orig, six.text_type):
orig = orig.encode('utf-8')
data.setData(orig)
break
......
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