-
Notifications
You must be signed in to change notification settings - Fork 0
/
_py2with3compatibility.py
30 lines (26 loc) · 1.05 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
"""
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
from urlparse import urlparse
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
from urllib.error import HTTPError
def cmp_f(a, b):
return ((a > b) - (a < b))