Change urllib and urllib import with six.moves.urllib.

This commit is contained in:
Berker Peksag 2014-06-07 13:49:39 +03:00
parent dce76c3ee7
commit 120fa4ae95
2 changed files with 11 additions and 12 deletions

View 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:

View 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()))