-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathcompat.py
More file actions
35 lines (30 loc) · 820 Bytes
/
compat.py
File metadata and controls
35 lines (30 loc) · 820 Bytes
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
import sys
PY3 = sys.version_info[0] == 3
try:
from itertools import izip
xrange = xrange
except ImportError:
# py3
izip = zip
xrange = range
# end handle python version
try:
# Python 2
buffer = buffer
memoryview = buffer
except NameError:
# Python 3 has no `buffer`; only `memoryview`
# However, it's faster to just slice the object directly, maybe it keeps a view internally
def buffer(obj, offset, size=None):
if size is None:
# return memoryview(obj)[offset:]
return obj[offset:]
else:
# return memoryview(obj)[offset:offset+size]
return obj[offset:offset+size]
# end buffer reimplementation
memoryview = memoryview
try:
MAXSIZE = sys.maxint
except AttributeError:
MAXSIZE = sys.maxsize