diff options
author | Philipp Hagemeister <[email protected]> | 2013-11-24 15:18:44 +0100 |
---|---|---|
committer | Philipp Hagemeister <[email protected]> | 2013-11-24 15:18:44 +0100 |
commit | e03db0a0773e078d9b677d396ad78362654956af (patch) | |
tree | 17192285892d996eb7b9819e79e04729e166e81a /youtube_dl/utils.py | |
parent | a1ee09e815cb413d67cee17ad686224b26182dfb (diff) | |
parent | 267ed0c5d3547c68f1d34203c2ae4b0d826a29d9 (diff) | |
download | youtube-dl-e03db0a0773e078d9b677d396ad78362654956af.tar.gz youtube-dl-e03db0a0773e078d9b677d396ad78362654956af.zip |
Merge branch 'master' into opener-to-ydl
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0d2b7bd10..317aee2b5 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -12,6 +12,7 @@ import os import pipes import platform import re +import ssl import socket import sys import traceback @@ -536,12 +537,29 @@ def formatSeconds(secs): return '%d' % secs def make_HTTPS_handler(opts_no_check_certificate): - if sys.version_info < (3,2): - # Python's 2.x handler is very simplistic - return compat_urllib_request.HTTPSHandler() + if sys.version_info < (3, 2): + import httplib + + class HTTPSConnectionV3(httplib.HTTPSConnection): + def __init__(self, *args, **kwargs): + httplib.HTTPSConnection.__init__(self, *args, **kwargs) + + def connect(self): + sock = socket.create_connection((self.host, self.port), self.timeout) + if self._tunnel_host: + self.sock = sock + self._tunnel() + try: + self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv3) + except ssl.SSLError as e: + self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv23) + + class HTTPSHandlerV3(compat_urllib_request.HTTPSHandler): + def https_open(self, req): + return self.do_open(HTTPSConnectionV3, req) + return HTTPSHandlerV3() else: - import ssl - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + context = ssl.SSLContext(ssl.PROTOCOL_SSLv3) context.set_default_verify_paths() context.verify_mode = (ssl.CERT_NONE |