-
Notifications
You must be signed in to change notification settings - Fork 245
/
_py2with3compatibility.py
52 lines (46 loc) · 1.3 KB
/
_py2with3compatibility.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
"""
Logic to take care of imports depending on the python version
"""
import sys
if sys.version_info[0] == 2:
# python 2 modules
from commands import getstatusoutput as run_cmd
from commands import getstatusoutput, getoutput
from httplib import HTTPSConnection
# urllib
from urllib import urlencode, quote_plus, quote, unquote
from urllib2 import (
Request,
urlopen,
HTTPSHandler,
build_opener,
install_opener,
unquote,
HTTPError,
HTTPPasswordMgrWithDefaultRealm,
HTTPBasicAuthHandler,
HTTPCookieProcessor,
)
from urlparse import urlparse
from cookielib import CookieJar
else:
# python 3 modules
from subprocess import getstatusoutput as run_cmd
from subprocess import getstatusoutput, getoutput
from http.client import HTTPSConnection
# urllib
from urllib.parse import urlencode, quote_plus, quote, unquote, urlparse
from urllib.request import (
Request,
urlopen,
HTTPSHandler,
build_opener,
install_opener,
HTTPPasswordMgrWithDefaultRealm,
HTTPBasicAuthHandler,
HTTPCookieProcessor,
)
from urllib.error import HTTPError
from http.cookiejar import CookieJar
def cmp_f(a, b):
return (a > b) - (a < b)