mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Py3 compat for https downloader
This commit is contained in:
parent
1e64794997
commit
ec2567b580
@ -6,11 +6,11 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import ssl, socket, re, httplib
|
||||
from urlparse import urlsplit
|
||||
import ssl, socket, re
|
||||
from contextlib import closing
|
||||
|
||||
from calibre import get_proxies
|
||||
from calibre.constants import ispy3
|
||||
|
||||
class HTTPError(ValueError):
|
||||
|
||||
@ -21,6 +21,21 @@ class HTTPError(ValueError):
|
||||
self.code = code
|
||||
self.url = url
|
||||
|
||||
if ispy3:
|
||||
from urllib.parse import urlparse
|
||||
import http.client as httplib
|
||||
class HTTPSConnection(httplib.HTTPSConnection):
|
||||
|
||||
def __init__(self, ssl_version, *args, **kwargs):
|
||||
context = kwargs['context'] = ssl.SSLContext(ssl_version)
|
||||
cf = kwargs.pop('cert_file')
|
||||
context.load_verify_locations(cf)
|
||||
context.verify_mode = ssl.CERT_REQUIRED
|
||||
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
|
||||
else:
|
||||
import httplib
|
||||
from urlparse import urlsplit as urlparse
|
||||
|
||||
# Check certificate hostname {{{
|
||||
# Implementation taken from python 3
|
||||
class CertificateError(ValueError):
|
||||
@ -146,7 +161,7 @@ def get_https_resource_securely(
|
||||
if ssl_version is None:
|
||||
ssl_version = ssl.PROTOCOL_TLSv1
|
||||
cacerts = P(cacerts, allow_user_override=False)
|
||||
p = urlsplit(url)
|
||||
p = urlparse(url)
|
||||
if p.scheme != 'https':
|
||||
raise ValueError('URL scheme must be https, not %s' % p.scheme)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user