[bridgedb/master] Replace urllib2 with urllib.request

commit c0b8941b4ffdf0d8a182cfa04eb65f57576c2e25 Author: Damian Johnson <atagar@torproject.org> Date: Fri Jan 10 15:02:14 2020 -0800 Replace urllib2 with urllib.request Python 3.x renamed this module... Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 823, in loadByName return self.suiteFactory([self.findByName(name, recurse=recurse)]) ... File "./bridgedb/test/test_captcha.py", line 24, in <module> from bridgedb import captcha File "/home/atagar/Desktop/tor/bridgedb/bridgedb/captcha.py", line 66, in <module> import urllib2 builtins.ImportError: No module named 'urllib2' Test results are unchanged... before: FAILED (skips=2, failures=7, errors=144, successes=321) after: FAILED (skips=2, failures=7, errors=144, successes=321) --- bridgedb/captcha.py | 6 +++--- bridgedb/test/test_captcha.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bridgedb/captcha.py b/bridgedb/captcha.py index 5c67df0..49cf838 100644 --- a/bridgedb/captcha.py +++ b/bridgedb/captcha.py @@ -63,7 +63,7 @@ import logging import random import os import time -import urllib2 +import urllib.request from BeautifulSoup import BeautifulSoup @@ -185,14 +185,14 @@ class ReCaptcha(Captcha): form = "/noscript?k=%s" % self.publicKey # Extract and store image from recaptcha - html = urllib2.urlopen(urlbase + form).read() + html = urllib.request.urlopen(urlbase + form).read() # FIXME: The remaining lines currently cannot be reliably unit tested: soup = BeautifulSoup(html) # pragma: no cover imgurl = urlbase + "/" + soup.find('img')['src'] # pragma: no cover cField = soup.find( # pragma: no cover 'input', {'name': 'recaptcha_challenge_field'}) # pragma: no cover self.challenge = str(cField['value']) # pragma: no cover - self.image = urllib2.urlopen(imgurl).read() # pragma: no cover + self.image = urllib.request.urlopen(imgurl).read() # pragma: no cover class GimpCaptcha(Captcha): diff --git a/bridgedb/test/test_captcha.py b/bridgedb/test/test_captcha.py index 281aadc..24a14a4 100644 --- a/bridgedb/test/test_captcha.py +++ b/bridgedb/test/test_captcha.py @@ -57,7 +57,7 @@ class ReCaptchaTests(unittest.TestCase): def test_get(self): """Test get() method.""" - # Force urllib2 to do anything less idiotic than the defaults: + # Force urllib.request to do anything less idiotic than the defaults: envkey = 'HTTPS_PROXY' oldkey = None if os.environ.has_key(envkey): @@ -65,9 +65,9 @@ class ReCaptchaTests(unittest.TestCase): os.environ[envkey] = '127.0.0.1:9150' # This stupid thing searches the environment for ``<protocol>_PROXY`` # variables, hence the above 'HTTPS_PROXY' env setting: - proxy = captcha.urllib2.ProxyHandler() - opener = captcha.urllib2.build_opener(proxy) - captcha.urllib2.install_opener(opener) + proxy = captcha.urllib.request.ProxyHandler() + opener = captcha.urllib.request.build_opener(proxy) + captcha.urllib.request.install_opener(opener) try: # There isn't really a reliable way to test this function! :(
participants (1)
-
phw@torproject.org