[py3k] import urllib2 from six.moves
authorRémi Cardona <remi.cardona@logilab.fr>
Tue, 15 Sep 2015 18:50:25 +0200
changeset 10610 d53b9c157f99
parent 10609 e2d8e81bfe68
child 10611 f4dec0cca9a1
[py3k] import urllib2 from six.moves
server/sources/datafeed.py
--- a/server/sources/datafeed.py	Tue Sep 15 16:56:57 2015 +0200
+++ b/server/sources/datafeed.py	Tue Sep 15 18:50:25 2015 +0200
@@ -19,13 +19,14 @@
 database
 """
 
-import urllib2
 import StringIO
 from os.path import exists
 from datetime import datetime, timedelta
 from cookielib import CookieJar
 
 from six.moves.urllib.parse import urlparse
+from six.moves.urllib.request import Request, build_opener, HTTPCookieProcessor
+from six.moves.urllib.error import HTTPError
 
 from lxml import etree
 
@@ -355,7 +356,7 @@
         # no chance with cwclientlib, fall back to former implementation
         if purl.scheme in ('http', 'https'):
             self.source.info('GET %s', url)
-            req = urllib2.Request(url)
+            req = Request(url)
             return _OPENER.open(req, timeout=self.source.http_timeout)
 
         # url is probably plain content
@@ -534,7 +535,7 @@
         if urlparse(url).scheme in ('http', 'https'):
             try:
                 _OPENER.open(url, timeout=self.source.http_timeout)
-            except urllib2.HTTPError as ex:
+            except HTTPError as ex:
                 if ex.code == 404:
                     return True
         return False
@@ -561,10 +562,10 @@
         return Message(StringIO.StringIO())
 
 # use a cookie enabled opener to use session cookie if any
-_OPENER = urllib2.build_opener()
+_OPENER = build_opener()
 try:
     from logilab.common import urllib2ext
     _OPENER.add_handler(urllib2ext.HTTPGssapiAuthHandler())
 except ImportError: # python-kerberos not available
     pass
-_OPENER.add_handler(urllib2.HTTPCookieProcessor(CookieJar()))
+_OPENER.add_handler(HTTPCookieProcessor(CookieJar()))