Commit 1d4131ad authored by Arnaud Fontaine's avatar Arnaud Fontaine

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

parent d37ead64
......@@ -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
......@@ -44,9 +45,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 Products.ERP5Type.Utils import str2bytes, bytes2str
......@@ -84,8 +85,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
from Products.ERP5Type.Utils import bytes2str, str2bytes
......@@ -36,7 +37,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
......@@ -147,10 +148,11 @@ if leaflet_display_side:
)
#leaflet_content = leaflet_legalese.decode() + leaflet_content.decode()
if isinstance(leaflet_legalese, unicode):
leaflet_legalese = leaflet_legalese.encode("UTF-8")
if isinstance(leaflet_content, unicode):
leaflet_content = leaflet_content.encode("UTF-8")
if six.PY2:
if isinstance(leaflet_legalese, six.text_type):
leaflet_legalese = leaflet_legalese.encode("UTF-8")
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
from Products.ERP5Type.Utils import bytes2str, str2bytes
......@@ -138,10 +139,11 @@ if release_display_about:
release_relative_url=release_relative_url,
)
#release_content = release_content.decode() + release_about.decode()
if isinstance(release_content, unicode):
release_content = release_content.encode("UTF-8")
if isinstance(release_about, unicode):
release_about = release_about.encode("UTF-8")
if six.PY2:
if isinstance(release_content, six.text_type):
release_content = release_content.encode("UTF-8")
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
......@@ -8,6 +9,6 @@ if six.PY3:
# But in PY2, this must be converted to unicode() first...
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()
......
......@@ -540,7 +540,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:
......
......@@ -206,7 +206,7 @@ def handleHrefObject(obj, src, default_mimetype="text/html", default_data=b"<p>L
# use the same behavior as when we call a script from browser URL bar.
if not hasattr(obj, "getPortalType") and callable(obj):
mime, data = "text/html", obj()
if isinstance(data, unicode):
if six.PY2 and isinstance(data, six.text_type):
data = data.encode("utf-8")
return handleLinkedData(mime, data, src)
......
......@@ -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():
title_listboxline.addColumn(c[0], c[1].encode(self.getEncoding()))
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
......
......@@ -134,9 +134,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if uids is None: uids = []
if columns is None: columns = []
if checked_uids is None: checked_uids = []
# 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'):
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
method_path = method_path.encode('ascii')
self.method_path = method_path
self.params = params
......@@ -171,9 +171,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:
# 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):
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
v = v.encode('ascii')
if getattr(self, k, None) != v:
setattr(self, k, v)
......
......@@ -1520,6 +1520,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()
......@@ -1528,7 +1529,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':
......@@ -1601,6 +1602,7 @@ return result
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1609,7 +1611,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':
......@@ -1741,6 +1743,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()
......@@ -1749,7 +1752,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':
......@@ -1832,6 +1835,7 @@ return result
"""
input_script_id = 'Document_getPropertyDictFromContent'
python_code = """from Products.CMFCore.utils import getToolByName
import six
portal = context.getPortalObject()
information = context.getContentInformation()
......@@ -1840,7 +1844,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')
......
......@@ -114,7 +114,7 @@ class Message(Persistent):
if self.domain is None:
# Map the translated string with given parameters
if type(self.mapping) is dict:
if isinstance(message, six.text_type) :
if six.PY2 and isinstance(message, six.text_type) :
message = message.encode('utf-8')
message = Template(message).substitute(self.mapping)
else:
......@@ -124,7 +124,7 @@ class Message(Persistent):
if self.mapping:
unicode_mapping = {}
for k, v in six.iteritems(self.mapping):
if isinstance(v, str):
if six.PY2 and isinstance(v, str):
v = v.decode('utf-8')
unicode_mapping[k] = v
else:
......@@ -139,9 +139,9 @@ class Message(Persistent):
message = translated_message
if isinstance(self.message, str):
if isinstance(message, six.text_type):
if six.PY2 and isinstance(message, six.text_type):
message = message.encode('utf-8')
elif isinstance(message, str):
elif six.PY2 and isinstance(message, str):
message = message.decode('utf-8')
return message
......@@ -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)
......
......@@ -1809,7 +1809,7 @@ def legacyNormalizeUrl(url, base_url=None):
# Remove trailing '?'
# http://www.example.com/? -> http://www.example.com/
url = re_cleanup_tail.sub('', url)
if isinstance(url, six.text_type):
if six.PY2 and isinstance(url, six.text_type):
url = url.encode('utf-8')
return url
......@@ -1831,7 +1831,7 @@ def urlnormNormaliseUrl(url, base_url=None):
if base_url and not (url_protocol or url_domain):
# Make relative URL absolute
url = urljoin(base_url, url)
if isinstance(url, six.text_type):
if six.PY2 and isinstance(url, six.text_type):
url = url.encode('utf-8')
return url
......
......@@ -456,7 +456,7 @@ class Field:
return obj.method_name
elif obj_type is TALESField.TALESMethod:
return obj._text
elif obj_type is six.text_type:
elif six.PY2 and isinstance(obj_type, six.text_type):
return obj.encode('utf-8')
return str(obj)
from Products.ERP5Type.Utils import ensure_list
......
......@@ -517,7 +517,7 @@ class SelectionValidator(StringBaseValidator):
# will remain integers.
# XXX it is impossible with the UI currently to fill in unicode
# items, but it's possible to do it with the TALES tab
if field.get_value('unicode') and isinstance(item_value, six.text_type):
if six.PY2 and field.get_value('unicode') and isinstance(item_value, six.text_type):
str_value = item_value.encode(field.get_form_encoding())
else:
str_value = str(item_value)
......
......@@ -1568,7 +1568,7 @@ class DateTimeWidget(Widget):
format_dict = self.format_to_sql_format_dict
input_order = format_dict.get(self.getInputOrder(field),
self.sql_format_default)
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': field.get_value('date_separator').join(input_order),
......@@ -2129,7 +2129,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