-
Notifications
You must be signed in to change notification settings - Fork 7
/
_compat.py
107 lines (78 loc) · 1.99 KB
/
_compat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# coding: utf-8
from __future__ import absolute_import
import os
try:
from rpython.rlib import jit
from rpython.rlib.listsort import TimSort
PYR = True
PY2 = False
PY3 = False
PY = -1
try:
USE_BIGINT = os.environ["RPAHEUI_BIGINT"]
except (KeyError, ValueError):
USE_BIGINT = ''
except ImportError:
# Python compatibility
import sys
PY = sys.version_info.major
PYR = False
PY2 = PY == 2
PY3 = PY == 3
USE_BIGINT = False
def omnipotent(*args, **kw):
return args and args[0]
class Omnipotent(object):
def __getattr__(self, name):
return omnipotent
def __call__(self, *args, **kw):
return self
class JitModule(Omnipotent):
JitDriver = Omnipotent()
jit = JitModule()
class TimSort(object):
def __init__(self, list):
self.list = list
def sort(self):
self.list.sort()
try:
unichr(0)
unichr = unichr
ord = ord
except NameError:
long = int
def unichr(n): # not rpython but python3
return chr(n)
ord3 = ord
def ord(n):
if type(n) == int: # noqa: E721
return n
return ord3(n)
try:
# rpython, python2
@jit.elidable
def _unicode(i):
return (b'%d' % i).decode('utf-8')
_unicode(0)
@jit.elidable
def _bytestr(i):
return b'%d' % i
except TypeError:
# python3
def _unicode(i):
return u'%d' % i
_unicode(0)
def _bytestr(i):
return b'%d' % i
try:
USE_BIGINT = os.environ["RPAHEUI_BIGINT"]
except (KeyError, ValueError):
USE_BIGINT = ''
if USE_BIGINT:
from aheui.int import bigint # Enable bigint in rpython build
else:
from aheui.int import smallint as bigint # noqa: F401 smallint or python support
try:
from aheui.storage.linkedlist import Stack, Queue, Port
except ImportError:
from aheui.storage.array import Stack, Queue, Port # noqa: F401 smallint or python support