From 120fa4ae95329007c529b310f4e950146d44159f Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 7 Jun 2014 13:49:39 +0300 Subject: [PATCH] Change urllib and urllib import with six.moves.urllib. --- mediagoblin/processing/task.py | 12 ++++++------ mediagoblin/tools/processing.py | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index 7f683485..1a21c6d2 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -15,8 +15,8 @@ # along with this program. If not, see . 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: diff --git a/mediagoblin/tools/processing.py b/mediagoblin/tools/processing.py index 2abe6452..39a329c5 100644 --- a/mediagoblin/tools/processing.py +++ b/mediagoblin/tools/processing.py @@ -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())) -- 2.25.1