|
11 | 11 | import logging |
12 | 12 | from optparse import OptionParser |
13 | 13 | import os |
14 | | - |
15 | | -from urllib2 import (HTTPHandler, HTTPCookieProcessor, |
16 | | - HTTPBasicAuthHandler, HTTPPasswordMgrWithDefaultRealm) |
| 14 | +import sys |
17 | 15 |
|
18 | 16 | if sys.version_info[0] > 2: |
19 | 17 | import http.cookiejar as cookiejar_ |
20 | 18 | import http.client as http_client_ |
21 | 19 | from urllib.request import Request as Request_ |
| 20 | + from urllib.request import HTTPHandler as HTTPHandler_ |
| 21 | + from urllib.request import HTTPCookieProcessor as HTTPCookieProcessor_ |
| 22 | + from urllib.request import HTTPBasicAuthHandler as HTTPBasicAuthHandler_ |
| 23 | + from urllib.request import HTTPPasswordMgrWithDefaultRealm as \ |
| 24 | + HTTPPasswordMgrWithDefaultRealm_ |
22 | 25 | from urllib.request import ProxyHandler as ProxyHandler_ |
23 | 26 | from urllib.error import HTTPError as HTTPError_ |
24 | 27 | import urllib.parse as urlparse_ |
25 | 28 | else: |
26 | 29 | import cookielib as cookiejar_ |
27 | 30 | import httplib as http_client_ |
28 | 31 | from urllib2 import Request as Request_ |
| 32 | + from urllib2 import HTTPHandler as HTTPHandler_ |
| 33 | + from urllib2 import HTTPCookieProcessor as HTTPCookieProcessor_ |
| 34 | + from urllib2 import HTTPBasicAuthHandler as HTTPBasicAuthHandler_ |
| 35 | + from urllib2 import HTTPPasswordMgrWithDefaultRealm as \ |
| 36 | + HTTPPasswordMgrWithDefaultRealm_ |
29 | 37 | from urllib2 import ProxyHandler as ProxyHandler_ |
30 | 38 | from urllib2 import HTTPError as HTTPError_ |
31 | 39 | import urlparse as urlparse_ |
|
36 | 44 |
|
37 | 45 | log = logging.getLogger(__name__) |
38 | 46 |
|
39 | | -class AccumulatingHTTPCookieProcessor(HTTPCookieProcessor): |
| 47 | +class AccumulatingHTTPCookieProcessor(HTTPCookieProcessor_): |
40 | 48 | """Cookie processor that adds new cookies (instead of replacing the existing |
41 | 49 | ones as HTTPCookieProcessor does) |
42 | 50 | """ |
@@ -171,14 +179,14 @@ def open_url(url, config, data=None, handlers=None): |
171 | 179 | handlers.append(cookie_handler) |
172 | 180 |
|
173 | 181 | if config.debug: |
174 | | - http_handler = HTTPHandler(debuglevel=debuglevel) |
| 182 | + http_handler = HTTPHandler_(debuglevel=debuglevel) |
175 | 183 | https_handler = HTTPSContextHandler(config.ssl_context, |
176 | 184 | debuglevel=debuglevel) |
177 | 185 | handlers.extend([http_handler, https_handler]) |
178 | 186 |
|
179 | 187 | if config.http_basicauth: |
180 | 188 | # currently only supports http basic auth |
181 | | - auth_handler = HTTPBasicAuthHandler(HTTPPasswordMgrWithDefaultRealm()) |
| 189 | + auth_handler = HTTPBasicAuthHandler_(HTTPPasswordMgrWithDefaultRealm_()) |
182 | 190 | auth_handler.add_password(realm=None, uri=url, |
183 | 191 | user=config.httpauth[0], |
184 | 192 | passwd=config.httpauth[1]) |
@@ -208,6 +216,10 @@ def open_url(url, config, data=None, handlers=None): |
208 | 216 | return_code = 0 |
209 | 217 | return_message = '' |
210 | 218 | response = None |
| 219 | + |
| 220 | + # FIXME |
| 221 | + response = opener.open(request) |
| 222 | + |
211 | 223 | try: |
212 | 224 | response = opener.open(request) |
213 | 225 | return_message = response.msg |
|
0 commit comments