summaryrefslogtreecommitdiff
path: root/odoo/tools/pycompat.py
diff options
context:
space:
mode:
authorxmo-odoo <xmo@odoo.com>2017-04-27 13:59:33 +0200
committerGitHub <noreply@github.com>2017-04-27 13:59:33 +0200
commit2e6a589f417af48e3322955ffff6e94b6d8a24e3 (patch)
treeaa613ecc1f74a9531a03de89aa2bdc7bb32eed3b /odoo/tools/pycompat.py
parentde4a2216b953abb86094c9bfa5f45b1eaaa79d3d (diff)
[FIX] builtins removed from Python 3
* Reverse wrapper courtesy of @rco-odoo's original P3 branch * thin compat module stripped down from werkzeug (to augment as needed) issue 8530
Diffstat (limited to 'odoo/tools/pycompat.py')
-rw-r--r--odoo/tools/pycompat.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/odoo/tools/pycompat.py b/odoo/tools/pycompat.py
new file mode 100644
index 00000000000..114f7f2bd87
--- /dev/null
+++ b/odoo/tools/pycompat.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# to remove if we decide to add a dependency on six or future
+# very strongly inspired by https://github.com/pallets/werkzeug/blob/master/werkzeug/_compat.py
+import sys
+
+PY2 = sys.version_info[0]
+
+if PY2:
+ # pylint: disable=long-builtin,xrange-builtin
+ integer_types = (int, long)
+
+ range = xrange
+
+ # noinspection PyUnresolvedReferences
+ from itertools import imap, izip, ifilter
+
+ def implements_iterator(cls):
+ cls.next = cls.__next__
+ del cls.__next__
+ return cls
+else:
+ integer_types = (int,)
+
+ range = range
+
+ imap = map
+ izip = zip
+ ifilter = filter
+
+ def implements_iterator(cls):
+ return cls