Change urllib and urllib import with six.moves.urllib.
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 7 Jun 2014 10:49:39 +0000 (13:49 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sat, 7 Jun 2014 10:49:39 +0000 (13:49 +0300)
mediagoblin/processing/task.py
mediagoblin/tools/processing.py

index 7f68348566b5897b68d23c0c4a8b634c08b07edd..1a21c6d2fc8ffcf2461e70256d24a8487dd97383 100644 (file)
@@ -15,8 +15,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
-import urllib
-import urllib2
+
+from six.moves.urllib import request, parse
 
 import celery
 from celery.registry import tasks
@@ -42,15 +42,15 @@ def handle_push_urls(feed_url):
     hubparameters = {
         'hub.mode': 'publish',
         'hub.url': feed_url}
-    hubdata = urllib.urlencode(hubparameters)
+    hubdata = parse.urlencode(hubparameters)
     hubheaders = {
         "Content-type": "application/x-www-form-urlencoded",
         "Connection": "close"}
     for huburl in mgg.app_config["push_urls"]:
-        hubrequest = urllib2.Request(huburl, hubdata, hubheaders)
+        hubrequest = request.Request(huburl, hubdata, hubheaders)
         try:
-            hubresponse = urllib2.urlopen(hubrequest)
-        except (urllib2.HTTPError, urllib2.URLError) as exc:
+            hubresponse = request.urlopen(hubrequest)
+        except (request.HTTPError, request.URLError) as exc:
             # We retry by default 3 times before failing
             _log.info("PuSH url %r gave error %r", huburl, exc)
             try:
index 2abe64525dd8af46860f4ea453d09662e7ac0227..39a329c5130636ad60bdade8bdd2082c2b58cd73 100644 (file)
@@ -18,8 +18,7 @@ import logging
 import json
 import traceback
 
-from urllib2 import urlopen, Request, HTTPError
-from urllib import urlencode
+from six.moves.urllib import request, parse
 
 _log = logging.getLogger(__name__)
 
@@ -37,10 +36,10 @@ def create_post_request(url, data, **kw):
         data_parser: The parser function that is used to parse the `data`
             argument
     '''
-    data_parser = kw.get('data_parser', urlencode)
+    data_parser = kw.get('data_parser', parse.urlencode)
     headers = kw.get('headers', {})
 
-    return Request(url, data_parser(data), headers=headers)
+    return request.Request(url, data_parser(data), headers=headers)
 
 
 def json_processing_callback(entry):
@@ -76,11 +75,11 @@ def json_processing_callback(entry):
             data_parser=json.dumps)
 
     try:
-        urlopen(request)
+        request.urlopen(request)
         _log.debug('Processing callback for {0} sent'.format(entry))
 
         return True
-    except HTTPError:
+    except request.HTTPError:
         _log.error('Failed to send callback: {0}'.format(
             traceback.format_exc()))