[YoutubeDL] urlopen: use build_opener again

Otherwise we would need to manually add handlers like HTTPRedirectHandler, instead we add a customized FileHandler instance that raises an error.
pull/8/head
Jaime Marquínez Ferrándiz 9 years ago
parent e37afbe0b8
commit 6240b0a278

@ -1986,14 +1986,19 @@ class YoutubeDL(object):
https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel) https_handler = make_HTTPS_handler(self.params, debuglevel=debuglevel)
ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel) ydlh = YoutubeDLHandler(self.params, debuglevel=debuglevel)
data_handler = compat_urllib_request_DataHandler() data_handler = compat_urllib_request_DataHandler()
unknown_handler = compat_urllib_request.UnknownHandler()
handlers = (proxy_handler, https_handler, cookie_processor, ydlh, data_handler, unknown_handler) # When passing our own FileHandler instance, build_opener won't add the
# we don't use build_opener because it automatically adds FileHandler, # default FileHandler and allows us to disable the file protocol, which
# which can be used for malicious purposes (see # can be used for malicious purposes (see
# https://github.com/rg3/youtube-dl/issues/8227) # https://github.com/rg3/youtube-dl/issues/8227)
opener = compat_urllib_request.OpenerDirector() file_handler = compat_urllib_request.FileHandler()
for handler in handlers:
opener.add_handler(handler) def file_open(*args, **kwargs):
raise compat_urllib_error.URLError('file protocol is disabled')
file_handler.file_open = file_open
opener = compat_urllib_request.build_opener(
proxy_handler, https_handler, cookie_processor, ydlh, data_handler, file_handler)
# Delete the default user-agent header, which would otherwise apply in # Delete the default user-agent header, which would otherwise apply in
# cases where our custom HTTP handler doesn't come into play # cases where our custom HTTP handler doesn't come into play

Loading…
Cancel
Save