use six to support python 2 and 3
This commit is contained in:
parent
1b1dcf1c58
commit
d4d09b56b6
28 changed files with 1730 additions and 1678 deletions
14
ox/api.py
14
ox/api.py
|
|
@ -3,10 +3,10 @@
|
|||
# GPL 2011
|
||||
from __future__ import with_statement
|
||||
|
||||
import cookielib
|
||||
from six.moves import http_cookiejar as cookielib
|
||||
import gzip
|
||||
import StringIO
|
||||
import urllib2
|
||||
from six import StringIO
|
||||
from six.moves import urllib
|
||||
from types import MethodType
|
||||
|
||||
from . import __version__
|
||||
|
|
@ -29,8 +29,8 @@ class API(object):
|
|||
self._cj = cj
|
||||
else:
|
||||
self._cj = cookielib.CookieJar()
|
||||
self._opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self._cj),
|
||||
urllib2.HTTPHandler(debuglevel=self.debuglevel))
|
||||
self._opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self._cj),
|
||||
urllib.HTTPHandler(debuglevel=self.debuglevel))
|
||||
self._opener.addheaders = [
|
||||
('User-Agent', '%s/%s' % (self.__name__, self.__version__))
|
||||
]
|
||||
|
|
@ -64,7 +64,7 @@ class API(object):
|
|||
result = {}
|
||||
try:
|
||||
body = str(form)
|
||||
request = urllib2.Request(str(url))
|
||||
request = urllib.reuqest.Request(str(url))
|
||||
request.add_header('Content-type', form.get_content_type())
|
||||
request.add_header('Content-Length', str(len(body)))
|
||||
request.add_header('Accept-Encoding', 'gzip, deflate')
|
||||
|
|
@ -75,7 +75,7 @@ class API(object):
|
|||
result = gzip.GzipFile(fileobj=StringIO.StringIO(result)).read()
|
||||
result = result.decode('utf-8')
|
||||
return json.loads(result)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib.error.HTTPError as e:
|
||||
if self.DEBUG:
|
||||
import webbrowser
|
||||
if e.code >= 500:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue