Change urllib and urllib import with six.moves.urllib.
This commit is contained in:
parent
dce76c3ee7
commit
120fa4ae95
@ -15,8 +15,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
|
||||||
import urllib2
|
from six.moves.urllib import request, parse
|
||||||
|
|
||||||
import celery
|
import celery
|
||||||
from celery.registry import tasks
|
from celery.registry import tasks
|
||||||
@ -42,15 +42,15 @@ def handle_push_urls(feed_url):
|
|||||||
hubparameters = {
|
hubparameters = {
|
||||||
'hub.mode': 'publish',
|
'hub.mode': 'publish',
|
||||||
'hub.url': feed_url}
|
'hub.url': feed_url}
|
||||||
hubdata = urllib.urlencode(hubparameters)
|
hubdata = parse.urlencode(hubparameters)
|
||||||
hubheaders = {
|
hubheaders = {
|
||||||
"Content-type": "application/x-www-form-urlencoded",
|
"Content-type": "application/x-www-form-urlencoded",
|
||||||
"Connection": "close"}
|
"Connection": "close"}
|
||||||
for huburl in mgg.app_config["push_urls"]:
|
for huburl in mgg.app_config["push_urls"]:
|
||||||
hubrequest = urllib2.Request(huburl, hubdata, hubheaders)
|
hubrequest = request.Request(huburl, hubdata, hubheaders)
|
||||||
try:
|
try:
|
||||||
hubresponse = urllib2.urlopen(hubrequest)
|
hubresponse = request.urlopen(hubrequest)
|
||||||
except (urllib2.HTTPError, urllib2.URLError) as exc:
|
except (request.HTTPError, request.URLError) as exc:
|
||||||
# We retry by default 3 times before failing
|
# We retry by default 3 times before failing
|
||||||
_log.info("PuSH url %r gave error %r", huburl, exc)
|
_log.info("PuSH url %r gave error %r", huburl, exc)
|
||||||
try:
|
try:
|
||||||
|
@ -18,8 +18,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from urllib2 import urlopen, Request, HTTPError
|
from six.moves.urllib import request, parse
|
||||||
from urllib import urlencode
|
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_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`
|
data_parser: The parser function that is used to parse the `data`
|
||||||
argument
|
argument
|
||||||
'''
|
'''
|
||||||
data_parser = kw.get('data_parser', urlencode)
|
data_parser = kw.get('data_parser', parse.urlencode)
|
||||||
headers = kw.get('headers', {})
|
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):
|
def json_processing_callback(entry):
|
||||||
@ -76,11 +75,11 @@ def json_processing_callback(entry):
|
|||||||
data_parser=json.dumps)
|
data_parser=json.dumps)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
urlopen(request)
|
request.urlopen(request)
|
||||||
_log.debug('Processing callback for {0} sent'.format(entry))
|
_log.debug('Processing callback for {0} sent'.format(entry))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except HTTPError:
|
except request.HTTPError:
|
||||||
_log.error('Failed to send callback: {0}'.format(
|
_log.error('Failed to send callback: {0}'.format(
|
||||||
traceback.format_exc()))
|
traceback.format_exc()))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user