diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
commit | cc7362d28bd9c43cb6839809f86e59874f2fe458 (patch) | |
tree | 1053748f5890c769d1e99806bc0c8bcffca6f0fe /libbe/util/http.py | |
parent | 003bd13629d9db2f14156f97b74a4672e9ecdf77 (diff) | |
download | bugseverywhere-cc7362d28bd9c43cb6839809f86e59874f2fe458.tar.gz |
2to3 conversion of the repo.
Diffstat (limited to 'libbe/util/http.py')
-rw-r--r-- | libbe/util/http.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/libbe/util/http.py b/libbe/util/http.py index a1ab06a..2e4dae8 100644 --- a/libbe/util/http.py +++ b/libbe/util/http.py @@ -23,8 +23,8 @@ # httplib.responses # but it is slow to load. -import urllib -import urllib2 +import urllib.request, urllib.parse, urllib.error +import urllib.request, urllib.error, urllib.parse from libbe import TESTING @@ -92,19 +92,19 @@ def get_post_url(url, get=True, data=None, data_dict=None, headers=[], if get is True: if data_dict != {}: # encode get parameters in the url - param_string = urllib.urlencode(data_dict) + param_string = urllib.parse.urlencode(data_dict) url = '{}?{}'.format(url, param_string) else: - data = urllib.urlencode(data_dict) + data = urllib.parse.urlencode(data_dict) else: assert get is False, (data, get) assert data_dict is None, (data, data_dict) headers = dict(headers) headers['User-Agent'] = agent - req = urllib2.Request(url, data=data, headers=headers) + req = urllib.request.Request(url, data=data, headers=headers) try: - response = urllib2.urlopen(req) - except urllib2.HTTPError, e: + response = urllib.request.urlopen(req) + except urllib.error.HTTPError as e: if e.code == HTTP_USER_ERROR: lines = ['The server reported a user error (HTTPError)'] else: @@ -115,7 +115,7 @@ def get_post_url(url, get=True, data=None, data_dict=None, headers=[], lines.append('Error code: {}'.format(e.code)) msg = '\n'.join(lines) raise HTTPError(error=e, url=url, msg=msg) - except urllib2.URLError, e: + except urllib.error.URLError as e: msg = ('We failed to connect to the server (URLError).\nURL: {}\n' 'Reason: {}').format(url, e.reason) raise HTTPError(error=e, url=url, msg=msg) @@ -132,7 +132,7 @@ if TESTING: def test_get(self): url = 'http://bugseverywhere.org/' page,final_url,info = get_post_url(url=url) - self.failUnless(final_url == url, + self.assertTrue(final_url == url, 'Redirect?\n Expected: "{}"\n Got: "{}"'.format( url, final_url)) @@ -140,6 +140,6 @@ if TESTING: url = 'http://physics.drexel.edu/~wking/code/be/redirect' expected = 'http://physics.drexel.edu/~wking/' page,final_url,info = get_post_url(url=url) - self.failUnless(final_url == expected, + self.assertTrue(final_url == expected, 'Redirect?\n Expected: "{}"\n Got: "{}"'.format( expected, final_url)) |