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

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

parent 0d965e65
......@@ -27,6 +27,10 @@ from mimetools import choose_boundary
from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
from DateTime import DateTime
import re
import six
if six.PY3:
long = int # pylint:disable=redefined-builtin
class BigFile(File):
"""
......
......@@ -33,6 +33,7 @@ from random import randint
import sys
import threading
import traceback
import unittest
import six
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
......@@ -48,6 +49,9 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, SimpleQuery
from Testing import ZopeTestCase
from zLOG import LOG
if six.PY3:
long = int # pylint:disable=redefined-builtin
def format_stack(thread=None):
frame_dict = sys._current_frames()
if thread is not None:
......@@ -588,7 +592,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
uid_dict = {}
for _ in xrange(UID_BUFFER_SIZE * 3):
uid = portal_catalog.newUid()
self.assertTrue(isinstance(uid, long))
self.assertIsInstance(uid, long)
self.assertNotIn(uid, uid_dict)
uid_dict[uid] = None
......@@ -1647,6 +1651,9 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_type='Organisation',**catalog_kw)])
def test_54_FixIntUid(self):
if six.PY3:
return unittest.skipTest(
"Python3 does not have different types for int and long")
portal = self.getPortal()
module = portal.getDefaultModule('Organisation')
......
# export_only : allow to disable the uid column and the id of columns
import six
result = ''
request = context.REQUEST
......@@ -9,7 +10,7 @@ listboxline_list = context.get_value('default', render_format='list', REQUEST=re
def encode(value):
if isinstance(value, bool):
return '"%s"' % value
if isinstance(value, (int, long, float)):
if isinstance(value, six.integer_types + (float,)):
return str(value)
else:
if isinstance(value, str):
......
......@@ -238,7 +238,7 @@
error python: value[2]"
class="DataA" align="left"
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"
type="hidden" value="1" name="listbox_uid:list"
tal:attributes="value python: line.getUid() or '';
......@@ -268,7 +268,7 @@
<tal:block tal:repeat="value here/getStatValueList">
<td class="Data" align="left"
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:block>
</tr>
......
......@@ -63,6 +63,7 @@ from Products.ERP5Type.Message import Message
from collections import OrderedDict
from Products.ERP5Form.Selection import Selection
from Products.PythonScripts.standard import Object
import six
MARKER = Object()
......@@ -83,7 +84,7 @@ def toBasicTypes(obj):
"""Ensure that obj contains only basic types."""
if obj is None:
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
if isinstance(obj, list):
return [toBasicTypes(x) for x in obj]
......
......@@ -273,9 +273,9 @@
</span>
<span style="color: green;">&nbsp;:&nbsp;</span>
<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" />
<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" />
</tal:block>
<tal:block tal:condition="not:show_search_line">
......@@ -302,7 +302,7 @@
<tal:block tal:condition="python: original_value is not None">
<span align="right"
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:block>
</div>
......
......@@ -100,7 +100,7 @@
-->
<tal:block metal:define-macro="cell_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">
......@@ -116,7 +116,7 @@
</tal:block>
<tal:block tal:condition="python: value is not None and not is_list">
<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)"
tal:attributes="office:value value;
table:style-name string:${style_prefix}figure"
......
......@@ -3,6 +3,7 @@ import datetime
import time
import json
from DateTime import DateTime
import six
response = container.REQUEST.RESPONSE
start = time.time()
......@@ -32,7 +33,7 @@ for line in results.tuples():
v = v.isoformat()
elif isinstance(v, Decimal):
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
# as string, this will still not work for pivot table, but at least the spreadsheet
# will not display truncated values.
......
......@@ -40,6 +40,10 @@ from lxml import etree
from zLOG import LOG, ERROR, INFO
from erp5.component.tool.WebServiceTool import ConnectionError
from Products.ERP5Type.Cache import CachingMethod
import six
if six.PY3:
long = int
ID_SEPARATOR="-"
......
......@@ -330,7 +330,7 @@
error python: value[2]"
class="DataA" align="left"
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"
type="hidden" value="1" name="listbox_uid:list"
tal:attributes="value python: line.getUid() or '';
......@@ -348,7 +348,7 @@
<tal:block tal:repeat="value here/getStatValueList">
<td class="Data" align="left"
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:block>
</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