You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/02/10 22:44:41 UTC

[allura] 10/41: [#8349] further updates after urllib import changes

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8349
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 6276654e81c9094983a73b26fc7531b0b59d856b
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Feb 10 13:24:56 2020 -0500

    [#8349] further updates after urllib import changes
---
 Allura/allura/lib/custom_middleware.py           |  8 ++++++--
 Allura/allura/lib/helpers.py                     |  1 -
 Allura/allura/tests/test_helpers.py              | 16 ++++++++--------
 ForgeImporters/forgeimporters/tests/test_base.py |  2 +-
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index b1fd554..4771599 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -30,6 +30,7 @@ from tg.support.middlewares import _call_wsgi_application as call_wsgi_applicati
 from timermiddleware import Timer, TimerMiddleware
 from webob import exc, Request
 import pysolr
+import six
 
 from allura.lib import helpers as h
 import allura.model.repository
@@ -295,7 +296,10 @@ class AlluraTimerMiddleware(TimerMiddleware):
         import ming
         import pymongo
         import socket
-        import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse
+        if six.PY2:
+            import urllib2 as urlopen_pkg
+        else:
+            import urllib.requests as urlopen_pkg
         import activitystream
         import pygments
         import difflib
@@ -341,7 +345,7 @@ class AlluraTimerMiddleware(TimerMiddleware):
             Timer('socket_write', socket._fileobject, 'write', 'writelines',
                   'flush', debug_each_call=False),
             Timer('solr', pysolr.Solr, 'add', 'delete', 'search', 'commit'),
-            Timer('urlopen', urllib2, 'urlopen'),
+            Timer('urlopen', urlopen_pkg, 'urlopen'),
             Timer('base_repo_tool.{method_name}',
                   allura.model.repository.RepositoryImplementation, 'last_commit_ids'),
             Timer('pygments', pygments, 'highlight'),  # often called from within a template so will overlap w/ jinja
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index d874a0d..3812707 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -24,7 +24,6 @@ import os
 import os.path
 import difflib
 import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error
-import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse
 import re
 import unicodedata
 import json
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 0308f17..514f43e 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -438,13 +438,13 @@ back\\\\\-slash escaped
 
 class TestUrlOpen(TestCase):
 
-    @patch('allura.lib.helpers.urllib2')
-    def test_no_error(self, urllib2):
+    @patch('six.moves.urllib.request.urlopen')
+    def test_no_error(self, urlopen):
         r = h.urlopen('myurl')
-        self.assertEqual(r, six.moves.urllib.request.urlopen.return_value)
-        six.moves.urllib.request.urlopen.assert_called_once_with('myurl', timeout=None)
+        self.assertEqual(r, urlopen.return_value)
+        urlopen.assert_called_once_with('myurl', timeout=None)
 
-    @patch('allura.lib.helpers.urllib2.urlopen')
+    @patch('six.moves.urllib.request.urlopen')
     def test_socket_timeout(self, urlopen):
         import socket
 
@@ -454,7 +454,7 @@ class TestUrlOpen(TestCase):
         self.assertRaises(socket.timeout, h.urlopen, 'myurl')
         self.assertEqual(urlopen.call_count, 4)
 
-    @patch('allura.lib.helpers.urllib2.urlopen')
+    @patch('six.moves.urllib.request.urlopen')
     def test_socket_reset(self, urlopen):
         import socket
         import errno
@@ -465,7 +465,7 @@ class TestUrlOpen(TestCase):
         self.assertRaises(socket.error, h.urlopen, 'myurl')
         self.assertEqual(urlopen.call_count, 4)
 
-    @patch('allura.lib.helpers.urllib2.urlopen')
+    @patch('six.moves.urllib.request.urlopen')
     def test_handled_http_error(self, urlopen):
         from six.moves.urllib.error import HTTPError
 
@@ -475,7 +475,7 @@ class TestUrlOpen(TestCase):
         self.assertRaises(HTTPError, h.urlopen, 'myurl')
         self.assertEqual(urlopen.call_count, 4)
 
-    @patch('allura.lib.helpers.urllib2.urlopen')
+    @patch('six.moves.urllib.request.urlopen')
     def test_unhandled_http_error(self, urlopen):
         from six.moves.urllib.error import HTTPError
 
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index 917bea5..ffbaa40 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -36,7 +36,7 @@ from forgeimporters import base
 class TestProjectExtractor(TestCase):
 
     @mock.patch('forgeimporters.base.h.urlopen')
-    @mock.patch('forgeimporters.base.urllib2.Request')
+    @mock.patch('six.moves.urllib.request.Request')
     def test_urlopen(self, Request, urlopen):
         r = base.ProjectExtractor.urlopen('myurl', data='foo')
         Request.assert_called_once_with('myurl', data='foo')