|
1 | | -# -*- coding: utf-8 -*- |
2 | 1 | # Copyright (c) 2012 Kenneth Reitz. |
3 | 2 |
|
4 | 3 | # Permission to use, copy, modify, and/or distribute this software for any |
|
13 | 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | 14 |
|
16 | | -""" |
17 | | -pythoncompat |
18 | | -""" |
19 | | - |
20 | | - |
| 15 | +"""pythoncompat""" |
21 | 16 | import sys |
22 | | - |
23 | | -# ------- |
24 | | -# Pythons |
25 | | -# ------- |
26 | | - |
27 | | -# Syntax sugar. |
28 | | -_ver = sys.version_info |
29 | | - |
30 | | -#: Python 2.x? |
31 | | -is_py2 = (_ver[0] == 2) |
32 | | - |
33 | | -#: Python 3.x? |
34 | | -is_py3 = (_ver[0] == 3) |
35 | | - |
36 | | -# --------- |
37 | | -# Specifics |
38 | | -# --------- |
39 | | - |
40 | | -if is_py2: |
41 | | - from StringIO import StringIO |
42 | | - from urllib2 import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\ |
43 | | - HTTPHandler, build_opener, HTTPError, URLError |
44 | | - from httplib import BadStatusLine, HTTPException |
45 | | - from urlparse import urlunparse |
46 | | - from urllib import urlencode, quote_plus |
47 | | - |
48 | | - bytes = str |
49 | | - unicode = unicode |
50 | | - basestring = basestring |
51 | | -elif is_py3: |
52 | | - from io import StringIO |
53 | | - from urllib.request import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\ |
54 | | - HTTPHandler, build_opener |
55 | | - from urllib.error import HTTPError, URLError |
56 | | - from http.client import HTTPException, BadStatusLine |
57 | | - from urllib.parse import urlunparse, urlencode, quote_plus |
58 | | - |
59 | | - unicode = str |
60 | | - bytes = bytes |
61 | | - basestring = (str,bytes) |
| 17 | +from http.client import BadStatusLine, HTTPException |
| 18 | +from io import StringIO |
| 19 | +from urllib.error import HTTPError, URLError |
| 20 | +from urllib.parse import quote_plus, urlencode, urlunparse |
| 21 | +from urllib.request import HTTPDigestAuthHandler, HTTPHandler, HTTPPasswordMgr, Request, build_opener |
| 22 | + |
| 23 | +unicode = str |
| 24 | +bytes = bytes |
| 25 | +basestring = (str,bytes) |
0 commit comments