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

py2/py3: long does not exist in Python 3.

parent d450aedc
...@@ -27,6 +27,10 @@ from mimetools import choose_boundary ...@@ -27,6 +27,10 @@ from mimetools import choose_boundary
from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
from DateTime import DateTime from DateTime import DateTime
import re import re
import six
if six.PY3:
long = int
class BigFile(File): class BigFile(File):
""" """
......
...@@ -49,6 +49,9 @@ from Testing import ZopeTestCase ...@@ -49,6 +49,9 @@ from Testing import ZopeTestCase
from zLOG import LOG from zLOG import LOG
from six.moves import range from six.moves import range
if six.PY3:
long = int
def format_stack(thread=None): def format_stack(thread=None):
frame_dict = sys._current_frames() frame_dict = sys._current_frames()
if thread is not None: if thread is not None:
......
# export_only : allow to disable the uid column and the id of columns # export_only : allow to disable the uid column and the id of columns
import six
result = '' result = ''
request = context.REQUEST request = context.REQUEST
...@@ -9,7 +10,7 @@ listboxline_list = context.get_value('default', render_format='list', REQUEST=re ...@@ -9,7 +10,7 @@ listboxline_list = context.get_value('default', render_format='list', REQUEST=re
def encode(value): def encode(value):
if isinstance(value, bool): if isinstance(value, bool):
return '"%s"' % value return '"%s"' % value
if isinstance(value, (int, long, float)): if isinstance(value, six.integer_types + (float,)):
return str(value) return str(value)
else: else:
if isinstance(value, str): if isinstance(value, str):
......
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
error python: value[2]" error python: value[2]"
class="DataA" align="left" class="DataA" align="left"
tal:attributes="class python: error and (css + 'Error') or css; tal:attributes="class python: error and (css + 'Error') or css;
align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'"> align python: isinstance(original_value, modules['six'].integer_types + (float,)) and 'right' or 'left'">
<input tal:condition="not: repeat/value/index" <input tal:condition="not: repeat/value/index"
type="hidden" value="1" name="listbox_uid:list" type="hidden" value="1" name="listbox_uid:list"
tal:attributes="value python: line.getUid() or ''; tal:attributes="value python: line.getUid() or '';
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
<tal:block tal:repeat="value here/getStatValueList"> <tal:block tal:repeat="value here/getStatValueList">
<td class="Data" align="left" <td class="Data" align="left"
tal:define="original_value python: value[0]; processed_value python: value[1]" tal:define="original_value python: value[0]; processed_value python: value[1]"
tal:attributes="align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'" tal:attributes="align python: isinstance(original_value, modules['six'].integer_types + (float,)) and 'right' or 'left'"
tal:content="structure processed_value" /> tal:content="structure processed_value" />
</tal:block> </tal:block>
</tr> </tr>
......
...@@ -63,6 +63,7 @@ from Products.ERP5Type.Message import Message ...@@ -63,6 +63,7 @@ from Products.ERP5Type.Message import Message
from collections import OrderedDict from collections import OrderedDict
from Products.ERP5Form.Selection import Selection from Products.ERP5Form.Selection import Selection
from Products.PythonScripts.standard import Object from Products.PythonScripts.standard import Object
import six
MARKER = Object() MARKER = Object()
...@@ -83,7 +84,7 @@ def toBasicTypes(obj): ...@@ -83,7 +84,7 @@ def toBasicTypes(obj):
"""Ensure that obj contains only basic types.""" """Ensure that obj contains only basic types."""
if obj is None: if obj is None:
return obj return obj
if isinstance(obj, (bool, int, float, long, str, unicode)): if isinstance(obj, (bool, float, str) + six.integer_types + six.text_type):
return obj return obj
if isinstance(obj, list): if isinstance(obj, list):
return [toBasicTypes(x) for x in obj] return [toBasicTypes(x) for x in obj]
......
...@@ -273,9 +273,9 @@ ...@@ -273,9 +273,9 @@
</span> </span>
<span style="color: green;">&nbsp;:&nbsp;</span> <span style="color: green;">&nbsp;:&nbsp;</span>
<tal:block tal:condition="show_search_line"> <tal:block tal:condition="show_search_line">
<span tal:condition="python: isinstance(original_value,(float, int, long))" <span tal:condition="python: isinstance(original_value, modules['six'].integer_types + (float,))"
id="data_short" tal:content="python: original_value" /> id="data_short" tal:content="python: original_value" />
<span tal:condition="python: not isinstance(original_value,(float, int, long))" <span tal:condition="python: not isinstance(original_value, modules['six'].integer_types + (float,))"
id="data_short" tal:content="data_short" /> id="data_short" tal:content="data_short" />
</tal:block> </tal:block>
<tal:block tal:condition="not:show_search_line"> <tal:block tal:condition="not:show_search_line">
...@@ -302,7 +302,7 @@ ...@@ -302,7 +302,7 @@
<tal:block tal:condition="python: original_value is not None"> <tal:block tal:condition="python: original_value is not None">
<span align="right" <span align="right"
tal:define="original_value python: valueZ[0]; processed_value python: valueZ[1]" tal:define="original_value python: valueZ[0]; processed_value python: valueZ[1]"
tal:attributes="align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'" tal:attributes="align python: isinstance(original_value, modules['six'].integer_types + (float,)) and 'right' or 'left'"
tal:content="structure processed_value" /> tal:content="structure processed_value" />
</tal:block> </tal:block>
</div> </div>
......
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
--> -->
<tal:block metal:define-macro="cell_value"> <tal:block metal:define-macro="cell_value">
<tal:block tal:define="is_list python:same_type(value, []) or same_type(value, ()); <tal:block tal:define="is_list python:same_type(value, []) or same_type(value, ());
is_float python: isinstance(value, (int, long, float));"> is_float python: isinstance(value, modules['six'].integer_types + (float,));">
<tal:block tal:condition="python: is_list"> <tal:block tal:condition="python: is_list">
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
</tal:block> </tal:block>
<tal:block tal:condition="python: value is not None and not is_list"> <tal:block tal:condition="python: value is not None and not is_list">
<tal:block tal:condition="is_float"> <tal:block tal:condition="is_float">
<tal:block tal:condition="python: isinstance(value, (int, long))"> <tal:block tal:condition="python: isinstance(value, modules['six'].integer_types)">
<table:table-cell tal:define="field python: editable_fields.get(column_id, None)" <table:table-cell tal:define="field python: editable_fields.get(column_id, None)"
tal:attributes="office:value value; tal:attributes="office:value value;
table:style-name string:${style_prefix}figure" table:style-name string:${style_prefix}figure"
......
...@@ -3,6 +3,7 @@ import datetime ...@@ -3,6 +3,7 @@ import datetime
import time import time
import json import json
from DateTime import DateTime from DateTime import DateTime
import six
response = container.REQUEST.RESPONSE response = container.REQUEST.RESPONSE
start = time.time() start = time.time()
...@@ -32,7 +33,7 @@ for line in results.tuples(): ...@@ -32,7 +33,7 @@ for line in results.tuples():
v = v.isoformat() v = v.isoformat()
elif isinstance(v, Decimal): elif isinstance(v, Decimal):
v = float(v) v = float(v)
elif isinstance(v, (long, int, float)) and not isSafeInteger(v): elif isinstance(v, six.integer_types + (float,)) and not isSafeInteger(v):
# if numbers are too large to be handled by javascript, we simply return them # if numbers are too large to be handled by javascript, we simply return them
# as string, this will still not work for pivot table, but at least the spreadsheet # as string, this will still not work for pivot table, but at least the spreadsheet
# will not display truncated values. # will not display truncated values.
......
...@@ -40,6 +40,10 @@ from lxml import etree ...@@ -40,6 +40,10 @@ from lxml import etree
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
from erp5.component.tool.WebServiceTool import ConnectionError from erp5.component.tool.WebServiceTool import ConnectionError
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
import six
if six.PY3:
long = int
ID_SEPARATOR="-" ID_SEPARATOR="-"
......
...@@ -330,7 +330,7 @@ ...@@ -330,7 +330,7 @@
error python: value[2]" error python: value[2]"
class="DataA" align="left" class="DataA" align="left"
tal:attributes="class python: error and (css + 'Error') or css; tal:attributes="class python: error and (css + 'Error') or css;
align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'"> align python: isinstance(original_value, modules['six'].integer_types + (float,)) and 'right' or 'left'">
<input tal:condition="not: repeat/value/index" <input tal:condition="not: repeat/value/index"
type="hidden" value="1" name="listbox_uid:list" type="hidden" value="1" name="listbox_uid:list"
tal:attributes="value python: line.getUid() or ''; tal:attributes="value python: line.getUid() or '';
...@@ -348,7 +348,7 @@ ...@@ -348,7 +348,7 @@
<tal:block tal:repeat="value here/getStatValueList"> <tal:block tal:repeat="value here/getStatValueList">
<td class="Data" align="left" <td class="Data" align="left"
tal:define="original_value python: value[0]; processed_value python: value[1]" tal:define="original_value python: value[0]; processed_value python: value[1]"
tal:attributes="align python: isinstance(original_value, (float, int, long)) and 'right' or 'left'" tal:attributes="align python: isinstance(original_value, modules['six'].integer_types + (float,)) and 'right' or 'left'"
tal:content="structure processed_value" /> tal:content="structure processed_value" />
</tal:block> </tal:block>
</tr> </tr>
......
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