1
2
3
4
5
6
7
8
9
10
11
12 | # encoding: UTF-8
# api: python
# type: functions
# title: Python2 and Python3 compatibility
# version: 0.1
#
# Renames some Python3 modules into their Py2 equivalent.
# Slim local alternative to `six` module.
import sys
|
|
| 1
2
3
4
5
6
7
8
9
10
11
12 | # encoding: UTF-8
# api: python
# type: functions
# title: Python2 and Python3 compatibility
# version: 0.2
#
# Renames some Python3 modules into their Py2 equivalent.
# Slim local alternative to `six` module.
import sys
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | import urllib2
from urllib import urlencode
import urlparse
import cookielib
# filesys
from StringIO import StringIO
# Python 3
else:
# version tags
PY2 = 0 |
>
>
>
>
| 28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 | import urllib2
from urllib import urlencode
import urlparse
import cookielib
# filesys
from StringIO import StringIO
from gzip import GzipFile
def gzip_decode(bytes):
return GzipFile(fileobj=StringIO(bytes)).read()
# return zlib.decompress(bytes, 16 + zlib.MAX_WBITS) # not fully compatible
# Python 3
else:
# version tags
PY2 = 0 |
50
51
52
53
54
55
56
57
58
| import urllib.request as urllib2
from urllib.parse import urlencode
import urllib.parse as urlparse
from http import cookiejar as cookielib
# filesys
from io import StringIO
|
>
|
>
>
>
>
>
>
>
>
>
>
> | 54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 | import urllib.request as urllib2
from urllib.parse import urlencode
import urllib.parse as urlparse
from http import cookiejar as cookielib
# filesys
from io import StringIO
from gzip import decompress as gzip_decode
# Both
# find_executable() is only needed by channels/configwin
try:
from distutils.spawn import find_executable
except:
def find_executable(bin):
exists = [os.path.exists(dir+"/"+bin) for dir in os.environ.get("PATH").split(":")+["/"]]
return exists[0] if len(exists) else None
|