mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup urllib imports
This commit is contained in:
parent
d6402a0fdd
commit
1c22094803
@ -19,19 +19,19 @@ enc = getattr(sys.stdout, 'encoding', 'utf-8') or 'utf-8'
|
|||||||
if enc.lower() == 'ascii':
|
if enc.lower() == 'ascii':
|
||||||
enc = 'utf-8'
|
enc = 'utf-8'
|
||||||
calibre_version = signature = None
|
calibre_version = signature = None
|
||||||
urllib = __import__('urllib.request' if py3 else 'urllib', fromlist=1)
|
|
||||||
has_ssl_verify = hasattr(ssl, 'create_default_context')
|
has_ssl_verify = hasattr(ssl, 'create_default_context')
|
||||||
|
|
||||||
if py3:
|
if py3:
|
||||||
unicode = str
|
unicode = str
|
||||||
raw_input = input
|
raw_input = input
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.request import BaseHandler, build_opener, Request
|
from urllib.request import BaseHandler, build_opener, Request, urlopen, getproxies, addinfourl
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
encode_for_subprocess = lambda x:x
|
encode_for_subprocess = lambda x:x
|
||||||
else:
|
else:
|
||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
from urllib import urlopen, getproxies, addinfourl
|
||||||
from urllib2 import BaseHandler, build_opener, Request
|
from urllib2 import BaseHandler, build_opener, Request
|
||||||
import httplib
|
import httplib
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ class RangeHandler(BaseHandler):
|
|||||||
|
|
||||||
def http_error_206(self, req, fp, code, msg, hdrs):
|
def http_error_206(self, req, fp, code, msg, hdrs):
|
||||||
# 206 Partial Content Response
|
# 206 Partial Content Response
|
||||||
r = urllib.addinfourl(fp, hdrs, req.get_full_url())
|
r = addinfourl(fp, hdrs, req.get_full_url())
|
||||||
r.code = code
|
r.code = code
|
||||||
r.msg = msg
|
r.msg = msg
|
||||||
return r
|
return r
|
||||||
@ -287,7 +287,7 @@ def do_download(dest):
|
|||||||
offset = os.path.getsize(dest)
|
offset = os.path.getsize(dest)
|
||||||
|
|
||||||
# Get content length and check if range is supported
|
# Get content length and check if range is supported
|
||||||
rq = urllib.urlopen(DLURL)
|
rq = urlopen(DLURL)
|
||||||
headers = rq.info()
|
headers = rq.info()
|
||||||
size = int(headers['content-length'])
|
size = int(headers['content-length'])
|
||||||
accepts_ranges = headers.get('accept-ranges', None) == 'bytes'
|
accepts_ranges = headers.get('accept-ranges', None) == 'bytes'
|
||||||
@ -359,7 +359,7 @@ def download_tarball():
|
|||||||
# Get tarball signature securely {{{
|
# Get tarball signature securely {{{
|
||||||
|
|
||||||
def get_proxies(debug=True):
|
def get_proxies(debug=True):
|
||||||
proxies = urllib.getproxies()
|
proxies = getproxies()
|
||||||
for key, proxy in list(proxies.items()):
|
for key, proxy in list(proxies.items()):
|
||||||
if not proxy or '..' in proxy:
|
if not proxy or '..' in proxy:
|
||||||
del proxies[key]
|
del proxies[key]
|
||||||
@ -664,7 +664,7 @@ def download_and_extract(destdir):
|
|||||||
def check_version():
|
def check_version():
|
||||||
global calibre_version
|
global calibre_version
|
||||||
if calibre_version == '%version':
|
if calibre_version == '%version':
|
||||||
calibre_version = urllib.urlopen('http://code.calibre-ebook.com/latest').read()
|
calibre_version = urlopen('http://code.calibre-ebook.com/latest').read()
|
||||||
|
|
||||||
|
|
||||||
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
||||||
|
@ -68,19 +68,19 @@ enc = getattr(sys.stdout, 'encoding', 'utf-8') or 'utf-8'
|
|||||||
if enc.lower() == 'ascii':
|
if enc.lower() == 'ascii':
|
||||||
enc = 'utf-8'
|
enc = 'utf-8'
|
||||||
calibre_version = signature = None
|
calibre_version = signature = None
|
||||||
urllib = __import__('urllib.request' if py3 else 'urllib', fromlist=1)
|
|
||||||
has_ssl_verify = hasattr(ssl, 'create_default_context')
|
has_ssl_verify = hasattr(ssl, 'create_default_context')
|
||||||
|
|
||||||
if py3:
|
if py3:
|
||||||
unicode = str
|
unicode = str
|
||||||
raw_input = input
|
raw_input = input
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.request import BaseHandler, build_opener, Request
|
from urllib.request import BaseHandler, build_opener, Request, urlopen, getproxies, addinfourl
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
encode_for_subprocess = lambda x:x
|
encode_for_subprocess = lambda x:x
|
||||||
else:
|
else:
|
||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
from urllib import urlopen, getproxies, addinfourl
|
||||||
from urllib2 import BaseHandler, build_opener, Request
|
from urllib2 import BaseHandler, build_opener, Request
|
||||||
import httplib
|
import httplib
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ class RangeHandler(BaseHandler):
|
|||||||
|
|
||||||
def http_error_206(self, req, fp, code, msg, hdrs):
|
def http_error_206(self, req, fp, code, msg, hdrs):
|
||||||
# 206 Partial Content Response
|
# 206 Partial Content Response
|
||||||
r = urllib.addinfourl(fp, hdrs, req.get_full_url())
|
r = addinfourl(fp, hdrs, req.get_full_url())
|
||||||
r.code = code
|
r.code = code
|
||||||
r.msg = msg
|
r.msg = msg
|
||||||
return r
|
return r
|
||||||
@ -336,7 +336,7 @@ def do_download(dest):
|
|||||||
offset = os.path.getsize(dest)
|
offset = os.path.getsize(dest)
|
||||||
|
|
||||||
# Get content length and check if range is supported
|
# Get content length and check if range is supported
|
||||||
rq = urllib.urlopen(DLURL)
|
rq = urlopen(DLURL)
|
||||||
headers = rq.info()
|
headers = rq.info()
|
||||||
size = int(headers['content-length'])
|
size = int(headers['content-length'])
|
||||||
accepts_ranges = headers.get('accept-ranges', None) == 'bytes'
|
accepts_ranges = headers.get('accept-ranges', None) == 'bytes'
|
||||||
@ -408,7 +408,7 @@ def download_tarball():
|
|||||||
# Get tarball signature securely {{{
|
# Get tarball signature securely {{{
|
||||||
|
|
||||||
def get_proxies(debug=True):
|
def get_proxies(debug=True):
|
||||||
proxies = urllib.getproxies()
|
proxies = getproxies()
|
||||||
for key, proxy in list(proxies.items()):
|
for key, proxy in list(proxies.items()):
|
||||||
if not proxy or '..' in proxy:
|
if not proxy or '..' in proxy:
|
||||||
del proxies[key]
|
del proxies[key]
|
||||||
@ -713,7 +713,7 @@ def download_and_extract(destdir):
|
|||||||
def check_version():
|
def check_version():
|
||||||
global calibre_version
|
global calibre_version
|
||||||
if calibre_version == '%version':
|
if calibre_version == '%version':
|
||||||
calibre_version = urllib.urlopen('http://code.calibre-ebook.com/latest').read()
|
calibre_version = urlopen('http://code.calibre-ebook.com/latest').read()
|
||||||
|
|
||||||
|
|
||||||
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
def run_installer(install_dir, isolated, bin_dir, share_dir):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user