Commit 4a551dca authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: unicode() => six.text_type().

parent bf486a45
......@@ -8,6 +8,7 @@ to use re) that would analyze text content of the doc
and return a dictionary of properties.
"""
#Proxify to allow discover of metadata when publishing document
import six
information = context.getContentInformation()
......@@ -16,7 +17,8 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode): v = v.encode('utf-8')
if six.PY2 and isinstance(v, six.text_type):
v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
pass # XXX - We can not trust reference on getContentInformation
......
import six
from Products.ERP5Type.Message import translateString
from Products.ERP5Form.Report import ReportSection
def translate(*args, **kw):
return six.text_type(translateString(*args, **kw))
request = container.REQUEST
section_category = request['section_category']
section_category_strict = request['section_category_strict']
......@@ -30,16 +34,16 @@ previous_period = 0
for idx, period in enumerate(period_list):
if idx != 0:
previous_period = period_list[idx - 1]
selection_columns.append(('period_%s' % idx, unicode(translateString(
selection_columns.append(('period_%s' % idx, translate(
'Period ${period_number} (from ${from} to ${to} days)',
mapping={'period_number': 1 + idx,
'from': previous_period,
'to': period} ))))
'to': period} )))
editable_columns.append(('period_%s' % idx, ''))
selection_columns.append(('period_%s' % (idx + 1),
unicode(translateString('Older (more than ${day_count} days)',
mapping={'day_count': period_list[-1]}))))
translate('Older (more than ${day_count} days)',
mapping={'day_count': period_list[-1]})))
editable_columns.append(('period_%s' % (idx + 1), ''))
selection_params = dict(section_category=section_category,
......
# coding: utf-8
import unicodedata
import six
from io import BytesIO
import zipfile
from Products.ERP5Type.Message import translateString
......@@ -42,9 +43,12 @@ attachment_list = (
'content': zipbuffer.getvalue(),
'name': zipfilename, }, )
subject = six.text_type(
translateString('French Accounting Transaction File'))
portal.ERP5Site_notifyReportComplete(
user_name=user_name,
subject=unicode(translateString('French Accounting Transaction File')),
subject=subject,
message='',
attachment_list=attachment_list)
......
......@@ -2,6 +2,7 @@
Generate a HTML Summary of an object.
Use "No ZODB" approach if possible.
"""
import six
request = context.REQUEST
portal = context.getPortalObject()
is_temp_object = context.isTempObject()
......@@ -40,7 +41,7 @@ else:
modification_date = context.modification_date
document_web_section_list = web_site.getWebSectionValueList(context)
inline_popup = context.Document_getPopupInfo(web_site, document_web_section_list)
if isinstance(inline_popup, unicode):
if six.PY2 and isinstance(inline_popup, six.text_type):
inline_popup = inline_popup.encode('utf-8')
found = context.Base_showFoundText()
portal_type = context.getTranslatedPortalType()
......
import six
from pprint import pformat
portal = context.getPortalObject()
request= portal.REQUEST
......@@ -89,7 +90,7 @@ for budget in budget_list:
conversion_ratio = 1
line_list.append(dict(is_budget=True,
title=budget.getTitle().decode('utf8'),
title=six.text_type(budget.getTitle()),
target_currency_title=target_currency_title,
conversion_ratio=conversion_ratio,
resource_title=budget.getResource() and
......@@ -149,9 +150,9 @@ for budget in budget_list:
# we use BudgetLine_asCellRange to get cell names, and have a default value
# for "virtual level 2"
title = budget_line.getTitle().decode('utf8')
title = six.text_type(budget_line.getTitle())
cell_name_dict = {budget_line.getResource(base=1):
budget_line.getTitle().decode('utf8')}
six.text_type(budget_line.getTitle())}
cell_style_dict = {budget_line.getResource(base=1): 'Level2'}
cell_depth_dict = {budget_line.getResource(base=1): 0}
......@@ -168,7 +169,7 @@ for budget in budget_list:
for cell_range_list in budget_line_as_cell_range_matrixbox:
for category, title in cell_range_list:
cell_name_dict[category] = title.decode('utf8').replace(u'\xA0', '')
cell_name_dict[category] = six.text_type(title).replace(u'\xA0', '')
if category in level_2_variation_category_list:
depth = -min_depth + (title.count('\xA0') / 4) or title.count('/')
cell_depth_dict[category] = depth
......@@ -323,7 +324,7 @@ for budget in budget_list:
if total_level_1_current_budget:
consumed_ratio = total_level_1_consumed_budget / total_level_1_current_budget
line_list.append(dict(is_level_1=True,
title=budget_line.getTitle().decode('utf8'),
title=six.text_type(budget_line.getTitle()),
initial_budget=total_level_1_initial_budget,
current_budget=total_level_1_current_budget,
engaged_budget=total_level_1_engaged_budget,
......
......@@ -644,7 +644,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(['5'],folder_object_list)
if six.PY2:
folder_object_list = [x.getObject().getId() for x in
person_module.searchFolder(title=unicode(title, 'utf-8'))]
person_module.searchFolder(title=six.text_type(title, 'utf-8'))]
self.assertEqual(['5'],folder_object_list)
def test_Collation(self):
......
......@@ -33,6 +33,7 @@ MAIN FILE: generate book in different output formats
# display_svg format for svg images (svg, png*)
import re
import six
from Products.PythonScripts.standard import html_quote
from base64 import b64encode
......@@ -83,8 +84,7 @@ book_version = html_quote(override_document_version) if override_document_versio
book_description = html_quote(override_document_description) if override_document_description else book.getDescription()
book_title = html_quote(override_document_title) if override_document_title else book.getTitle()
# unicode
if isinstance(book_content, unicode):
if six.PY2 and isinstance(book_content, six.text_type):
book_content = book_content.encode("UTF-8")
# backcompat
......
import re
import six
from base64 import b64encode
......@@ -35,7 +36,7 @@ contract_version = context.getVersion() or "001"
contract_description = context.getDescription()
contract_title = context.getTitle()
if isinstance(contract_content, unicode):
if six.PY2 and isinstance(contract_content, six.text_type):
contract_content = contract_content.encode("UTF-8")
contract_history_section_list = re.findall('<section.+?>.+?</section>', contract_content, re.S)
......
......@@ -22,6 +22,7 @@ MAIN FILE: render two pager in different output formats
# document_save: save file in document module (default None)
import re
import six
from Products.PythonScripts.standard import html_quote
from base64 import b64encode
......@@ -146,9 +147,10 @@ if leaflet_display_side:
)
#leaflet_content = leaflet_legalese.decode() + leaflet_content.decode()
if isinstance(leaflet_legalese, unicode):
if six.PY2:
if isinstance(leaflet_legalese, six.text_type):
leaflet_legalese = leaflet_legalese.encode("UTF-8")
if isinstance(leaflet_content, unicode):
if isinstance(leaflet_content, six.text_type):
leaflet_content = leaflet_content.encode("UTF-8")
leaflet_content = leaflet_legalese + leaflet_content
......
......@@ -21,6 +21,7 @@ MAIN FILE: render press release in different output formats
# document_save: save file in document module (default None)
import re
import six
from base64 import b64encode
blank = ''
......@@ -137,9 +138,10 @@ if release_display_about:
release_relative_url=release_relative_url,
)
#release_content = release_content.decode() + release_about.decode()
if isinstance(release_content, unicode):
if six.PY2:
if isinstance(release_content, six.text_type):
release_content = release_content.encode("UTF-8")
if isinstance(release_about, unicode):
if isinstance(release_about, six.text_type):
release_about = release_about.encode("UTF-8")
release_content = release_content + release_about
......
import six
text = context.asText()
LENGTH = 25
#TODO: Think about the display length of multibyte characters.
try:
return unicode(text, 'utf-8')[:LENGTH].encode('utf-8')
return six.text_type(text, 'utf-8')[:LENGTH].encode('utf-8')
except UnicodeDecodeError:
return text[:LENGTH]
......@@ -41,6 +41,7 @@ from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import ModuleSecurityInfo
from tempfile import mkdtemp
import shutil
import six
class getTransactionalDirectory(str):
......@@ -137,9 +138,9 @@ try:
self.client.setException(SubversionLoginError(realm))
return False, '', '', False
# BBB. support older versions of pysvn <= 1.6.3
if isinstance(user, unicode):
if six.PY2 and isinstance(user, six.text_type):
user = user.encode('utf-8')
if isinstance(password, unicode):
if six.PY2 and isinstance(password, six.text_type):
password = password.encode('utf-8')
return True, user, password, False
......@@ -175,7 +176,7 @@ try:
def __call__(self, instance):
value = getattr(instance._obj, self._key)
if isinstance(value, unicode):
if six.PY2 and isinstance(value, six.text_type):
value = value.encode('utf-8')
#elif isinstance(value, pysvn.Entry):
elif str(type(value)) == "<type 'entry'>":
......
......@@ -7,6 +7,7 @@ To use, write your own method (probably External Method, since it is most likely
to use re) that would analyze text content of the doc
and return a dictionary of properties.
"""
import six
information = context.getContentInformation()
result = {}
......@@ -14,7 +15,7 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode): v = v.encode('utf-8')
if six.PY2 and isinstance(v, six.text_type): v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
pass # XXX - We can not trust reference on getContentInformation
......@@ -26,7 +27,7 @@ for k, v in information.items():
result['contributor'] = p.getRelativeUrl()
elif key == 'keywords':
if isinstance(v, (list, tuple)):
v = [isinstance(x, unicode) and x.encode('utf-8') or x for x in v]
v = [x.encode('utf-8') if six.PY2 and isinstance(x, six.text_type) else x for x in v]
else:
v = v.split()
result['subject_list'] = v
......
import six
portal = context.getPortalObject()
post_message_post_module = portal.getDefaultModuleValue(post_portal_type, None)
if isinstance(post_message_data, six.text_type):
post_message_data = post_message_data.encode()
message_post = post_message_post_module.newContent(
portal_type=post_portal_type,
title="Post Message for %s" % context.getTitle(),
......
......@@ -2,6 +2,7 @@
This script has proxy role, as only manager can access workflow configuration.
"""
import six
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
......@@ -11,9 +12,9 @@ workflow = portal.portal_workflow.ticket_workflow
for state in workflow.getStateValueList():
state_title = state.title_or_id()
state_title = unicode(translateString(
state_title = six.text_type(translateString(
'%s [state in %s]' % (state_title, workflow.getId()),
default=unicode(translateString(state_title))))
default=six.text_type(translateString(state_title))))
info[state.getReference()] = state_title
return info
......@@ -28,9 +28,9 @@ for worklist in workflow.getWorklistValueList():
# so that it looks good in the module view.
key = 'translated_%s_title' % key
state_title = workflow.getStateValueByReference(value[0]).title_or_id()
value = unicode(translateString(
value = six.text_type(translateString(
'%s [state in %s]' % (state_title, workflow.getId()),
default=unicode(translateString(state_title))))
default=six.text_type(translateString(state_title))))
if isinstance(value, (tuple, list)):
query_list.extend([{
......
# return worklists from ticket workflow in JSON format
from Products.ERP5Type.Message import translateString
import json
import six
portal = context.getPortalObject()
worklist_query_dict = portal.ERP5Site_getTicketWorkflowWorklistInfoDict(
......@@ -11,7 +12,7 @@ worklist_query_dict = portal.ERP5Site_getTicketWorkflowWorklistInfoDict(
# extend this information with the query from our helper script.
worklist_action_list = [
{
'action_name': unicode(translateString(action['name'].rsplit(' (', 1)[0])), # Action name include the count, but we display it separatly.
'action_name': six.text_type(translateString(action['name'].rsplit(' (', 1)[0])), # Action name include the count, but we display it separatly.
'action_count': action['count'],
'query': worklist_query_dict[action['worklist_id']],
}
......
......@@ -115,7 +115,7 @@ def unicodeDict(d):
return d
for k, v in six.iteritems(d):
if isinstance(v, str):
d.update({k:unicode(v, 'utf8')})
d.update({k: six.text_type(v, 'utf8')})
return d
line_list = context.PaySheetTransaction_getLineListAsDict()
......
......@@ -167,7 +167,7 @@ def unicodeDict(d):
return d
for k, v in six.iteritems(d):
if isinstance(v, str):
d.update({k:unicode(v, 'utf8')})
d.update({k: six.text_type(v, 'utf8')})
return d
source_section = paysheet.getSourceSectionValue()
......
......@@ -541,7 +541,7 @@ class SyncMLSubscription(XMLObject):
xml_document = etree.tostring(xml_document, encoding='utf-8',
pretty_print=True)
if six.PY2 and isinstance(xml_document, unicode):
if six.PY2 and isinstance(xml_document, six.text_type):
xml_document = xml_document.encode('utf-8')
# Link the signature to the document
if signature:
......
......@@ -111,7 +111,7 @@ class CrawlableMixin:
# For now take into acount only a and img tags
if attribute_name not in ('href',):
continue
if isinstance(link, six.text_type):
if six.PY2 and isinstance(link, six.text_type):
link = link.encode('utf-8')
href_list.append(link)
return href_list
......@@ -129,7 +129,7 @@ class CrawlableMixin:
path_part = '/'.join(path_part.split('/')[:-1])
base_url = urlunsplit((splitted_url[0], splitted_url[1], path_part, None,
None))
if isinstance(base_url, six.text_type):
if six.PY2 and isinstance(base_url, six.text_type):
base_url = base_url.encode('utf-8')
return base_url
......@@ -145,7 +145,7 @@ class CrawlableMixin:
# in www.example.com or www.3.example.com
# keep only the example.com part
reference_domain = ''.join(reference_domain.split('.')[-2:])
if isinstance(reference_domain, six.text_type):
if six.PY2 and isinstance(reference_domain, six.text_type):
reference_domain = reference_domain.encode('utf-8')
url_list = []
base_url = self.getContentBaseURL()
......@@ -159,7 +159,7 @@ class CrawlableMixin:
if not url:
continue
url_domain = urlsplit(url)[1]
if isinstance(url_domain, six.text_type):
if six.PY2 and isinstance(url_domain, six.text_type):
url_domain = url_domain.encode('utf-8')
if url_domain and ''.join(url_domain.split('.')[-2:]) != reference_domain:
continue
......
......@@ -43,7 +43,7 @@ try:
except ImportError:
# BBB backport https://github.com/zopefoundation/Zope/pull/893 with py2 support
def make_content_disposition(disposition, file_name):
if six.PY2 and not isinstance(file_name, unicode):
if six.PY2 and not isinstance(file_name, six.text_type):
file_name = file_name.decode('utf-8')
try:
file_name.encode('us-ascii')
......
......@@ -104,9 +104,9 @@ for table_name in spreadsheet_list.keys():
# 1 table = 1 base category
base_category_name = table_name
base_category_id = getIDFromString(base_category_name)
if six.PY2 and isinstance(base_category_name, unicode):
if six.PY2 and isinstance(base_category_name, six.text_type):
base_category_name = base_category_name.encode('utf8')
if six.PY2 and isinstance(base_category_id, unicode):
if six.PY2 and isinstance(base_category_id, six.text_type):
base_category_id = base_category_id.encode('utf8')
category_list = category_list_spreadsheet_mapping.setdefault(base_category_id, [])
category_list.append({ 'path' : base_category_id
......
......@@ -12,8 +12,10 @@ if translation_service is not None :
if not encoding:
return translation_service.translate(catalog, msg, lang=lang, **kw)
msg = translation_service.translate(catalog, msg, lang=lang, **kw)
if isinstance(msg, six.text_type):
if six.PY2 and isinstance(msg, six.text_type):
msg = msg.encode(encoding)
elif six.PY3 and isinstance(msg, six.binary_type):
msg = msg.decode(encoding)
return msg
except AttributeError: # This happens in unit testing, because it is not able to find something with get_context()
pass
......
......@@ -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
......
......@@ -624,7 +624,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
"""
user = _getAuthenticatedUser(self)
user_str = user.getIdOrUserName()
if isinstance(user_str, six.text_type):
if six.PY2 and isinstance(user_str, six.text_type):
user_str = user_str.encode('utf-8')
user_is_superuser = (user == system_user) or (user_str == ERP5Security.SUPER_USER)
allowedRolesAndUsers = self._listAllowedRolesAndUsers(user)
......
......@@ -705,7 +705,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')
......@@ -897,7 +897,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
......@@ -909,7 +909,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:
......@@ -931,7 +931,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:
......@@ -964,7 +964,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
......@@ -974,7 +974,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
......@@ -984,7 +984,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
......@@ -1751,7 +1751,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()
......@@ -2381,7 +2381,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()
......@@ -2716,7 +2716,10 @@ class ListBoxListRenderer(ListBoxRenderer):
title_listboxline = ListBoxLine()
title_listboxline.markTitleLine()
for c in self.getSelectedColumnList():
if six.PY2:
title_listboxline.addColumn(c[0], c[1].encode(self.getEncoding()))
else:
title_listboxline.addColumn(c[0], c[1])
listboxline_list.append(title_listboxline)
# Obtain the list of lines.
......@@ -2742,7 +2745,7 @@ class ListBoxListRenderer(ListBoxRenderer):
listboxline.checkLine(uid in checked_uid_set)
for (original_value, processed_value), (sql, title) in zip(line.getValueList(), self.getSelectedColumnList()):
if isinstance(original_value, six.text_type):
if six.PY2 and isinstance(original_value, six.text_type):
value = original_value.encode(self.getEncoding())
else:
value = original_value
......@@ -2760,7 +2763,7 @@ class ListBoxListRenderer(ListBoxRenderer):
stat_listboxline.markStatLine()
for (original_value, processed_value), (sql, title) in zip(self.getStatValueList(), self.getSelectedColumnList()):
if isinstance(original_value, six.text_type):
if six.PY2 and isinstance(original_value, six.text_type):
value = original_value.encode(self.getEncoding())
else:
value = original_value
......
......@@ -44,6 +44,7 @@ from ZODB.POSException import ConflictError
from Products.ERP5Type.Utils import UpperCase
from zLOG import LOG
import six
try:
from zExceptions 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
......
......@@ -133,9 +133,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if uids is None: uids = []
if columns is None: columns = []
if checked_uids is None: checked_uids = []
if six.PY2 and isinstance(method_path, six.text_type):
# XXX Because method_path is an URI, it must be in ASCII.
# Shouldn't Zope automatically does this conversion? -yo
if type(method_path) is type(u'a'):
method_path = method_path.encode('ascii')
self.method_path = method_path
self.params = params
......@@ -170,9 +170,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if kw is not None:
for k,v in six.iteritems(kw):
if k in ('domain', 'report', 'domain_path', 'report_path', 'domain_list', 'report_list') or v is not None:
if six.PY2 and k == 'method_path' and isinstance(v, six.text_type):
# XXX Because method_path is an URI, it must be in ASCII.
# Shouldn't Zope automatically does this conversion? -yo
if k == 'method_path' and isinstance(v, six.text_type):
v = v.encode('ascii')
if getattr(self, k, None) != v:
setattr(self, k, v)
......
......@@ -1502,6 +1502,7 @@ class TestIngestion(IngestionTestCase):
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1510,7 +1511,7 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode):
if six.PY2 and isinstance(v, six.text_type):
v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
......@@ -1583,6 +1584,7 @@ return result
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1591,7 +1593,7 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode):
if six.PY2 and isinstance(v, six.text_type):
v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
......@@ -1723,6 +1725,7 @@ context.setReference(reference)
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1731,7 +1734,7 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode):
if six.PY2 and isinstance(v, six.text_type):
v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
......@@ -1814,6 +1817,7 @@ return result
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1822,7 +1826,7 @@ property_id_list = context.propertyIds()
for k, v in information.items():
key = k.lower()
if v:
if isinstance(v, unicode):
if six.PY2 and isinstance(v, six.text_type):
v = v.encode('utf-8')
if key in property_id_list:
if key == 'reference':
......
......@@ -104,7 +104,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', 'surrogateescape')
......
......@@ -154,19 +154,10 @@ class Message(Persistent):
Return the translated message as a string object.
"""
message = self.translate()
if isinstance(message, six.text_type):
if six.PY2 and isinstance(message, six.text_type):
message = message.encode('utf-8')
return message
def __unicode__(self):
"""
Return the translated message as a unicode object.
"""
message = self.translate()
if isinstance(message, str):
message = message.decode('utf-8')
return message
def __len__(self):
return len(str(self))
......@@ -176,6 +167,17 @@ class Message(Persistent):
def __getslice__(self, i, j):
return str(self)[i:j]
if six.PY2:
def __unicode__(self):
"""
Return the translated message as a unicode object.
"""
message = self.translate()
if isinstance(message, str):
message = message.decode('utf-8')
return message
Message.__unicode__ = __unicode__
InitializeClass(Message)
allow_class(Message)
......
......@@ -2123,7 +2123,7 @@ class FloatWidget(TextWidget):
# field.
for x in xrange(0, precision):
format += '0'
if isinstance(value, six.text_type):
if six.PY2 and isinstance(value, six.text_type):
value = value.encode(field.get_form_encoding())
return {'query': value,
'format': format,
......
......@@ -51,7 +51,7 @@ class BaseMailTemplate:
# So I remove it.
if text.endswith('\n'):
text = text[:-1]
if not self.html() and isinstance(text, six.text_type):
if six.PY2 and not self.html() and isinstance(text, six.text_type):
text = text.encode(encoding,'replace')
# now turn the result into a MIMEText object
msg = MIMEText(
......
......@@ -540,7 +540,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