test_http.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import unicode_literals
  4. # Allow direct execution
  5. import os
  6. import sys
  7. import unittest
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. import contextlib
  10. import gzip
  11. import io
  12. import ssl
  13. import tempfile
  14. import threading
  15. import zlib
  16. # avoid deprecated alias assertRaisesRegexp
  17. if hasattr(unittest.TestCase, 'assertRaisesRegex'):
  18. unittest.TestCase.assertRaisesRegexp = unittest.TestCase.assertRaisesRegex
  19. try:
  20. import brotli
  21. except ImportError:
  22. brotli = None
  23. try:
  24. from urllib.request import pathname2url
  25. except ImportError:
  26. from urllib import pathname2url
  27. from youtube_dl.compat import (
  28. compat_http_cookiejar_Cookie,
  29. compat_http_server,
  30. compat_str as str,
  31. compat_urllib_error,
  32. compat_urllib_HTTPError,
  33. compat_urllib_parse,
  34. compat_urllib_request,
  35. )
  36. from youtube_dl.utils import (
  37. sanitized_Request,
  38. urlencode_postdata,
  39. )
  40. from test.helper import (
  41. FakeYDL,
  42. FakeLogger,
  43. http_server_port,
  44. )
  45. from youtube_dl import YoutubeDL
  46. TEST_DIR = os.path.dirname(os.path.abspath(__file__))
  47. class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
  48. protocol_version = 'HTTP/1.1'
  49. # work-around old/new -style class inheritance
  50. def super(self, meth_name, *args, **kwargs):
  51. from types import MethodType
  52. try:
  53. super()
  54. fn = lambda s, m, *a, **k: getattr(super(), m)(*a, **k)
  55. except TypeError:
  56. fn = lambda s, m, *a, **k: getattr(compat_http_server.BaseHTTPRequestHandler, m)(s, *a, **k)
  57. self.super = MethodType(fn, self)
  58. return self.super(meth_name, *args, **kwargs)
  59. def log_message(self, format, *args):
  60. pass
  61. def _headers(self):
  62. payload = str(self.headers).encode('utf-8')
  63. self.send_response(200)
  64. self.send_header('Content-Type', 'application/json')
  65. self.send_header('Content-Length', str(len(payload)))
  66. self.end_headers()
  67. self.wfile.write(payload)
  68. def _redirect(self):
  69. self.send_response(int(self.path[len('/redirect_'):]))
  70. self.send_header('Location', '/method')
  71. self.send_header('Content-Length', '0')
  72. self.end_headers()
  73. def _method(self, method, payload=None):
  74. self.send_response(200)
  75. self.send_header('Content-Length', str(len(payload or '')))
  76. self.send_header('Method', method)
  77. self.end_headers()
  78. if payload:
  79. self.wfile.write(payload)
  80. def _status(self, status):
  81. payload = '<html>{0} NOT FOUND</html>'.format(status).encode('utf-8')
  82. self.send_response(int(status))
  83. self.send_header('Content-Type', 'text/html; charset=utf-8')
  84. self.send_header('Content-Length', str(len(payload)))
  85. self.end_headers()
  86. self.wfile.write(payload)
  87. def _read_data(self):
  88. if 'Content-Length' in self.headers:
  89. return self.rfile.read(int(self.headers['Content-Length']))
  90. def _test_url(self, path, host='127.0.0.1', scheme='http', port=None):
  91. return '{0}://{1}:{2}/{3}'.format(
  92. scheme, host,
  93. port if port is not None
  94. else http_server_port(self.server), path)
  95. def do_POST(self):
  96. data = self._read_data()
  97. if self.path.startswith('/redirect_'):
  98. self._redirect()
  99. elif self.path.startswith('/method'):
  100. self._method('POST', data)
  101. elif self.path.startswith('/headers'):
  102. self._headers()
  103. else:
  104. self._status(404)
  105. def do_HEAD(self):
  106. if self.path.startswith('/redirect_'):
  107. self._redirect()
  108. elif self.path.startswith('/method'):
  109. self._method('HEAD')
  110. else:
  111. self._status(404)
  112. def do_PUT(self):
  113. data = self._read_data()
  114. if self.path.startswith('/redirect_'):
  115. self._redirect()
  116. elif self.path.startswith('/method'):
  117. self._method('PUT', data)
  118. else:
  119. self._status(404)
  120. def do_GET(self):
  121. def respond(payload=b'<html><video src="/vid.mp4" /></html>',
  122. payload_type='text/html; charset=utf-8',
  123. payload_encoding=None,
  124. resp_code=200):
  125. self.send_response(resp_code)
  126. self.send_header('Content-Type', payload_type)
  127. if payload_encoding:
  128. self.send_header('Content-Encoding', payload_encoding)
  129. self.send_header('Content-Length', str(len(payload))) # required for persistent connections
  130. self.end_headers()
  131. self.wfile.write(payload)
  132. def gzip_compress(p):
  133. buf = io.BytesIO()
  134. with contextlib.closing(gzip.GzipFile(fileobj=buf, mode='wb')) as f:
  135. f.write(p)
  136. return buf.getvalue()
  137. if self.path == '/video.html':
  138. respond()
  139. elif self.path == '/vid.mp4':
  140. respond(b'\x00\x00\x00\x00\x20\x66\x74[video]', 'video/mp4')
  141. elif self.path == '/302':
  142. if sys.version_info[0] == 3:
  143. # XXX: Python 3 http server does not allow non-ASCII header values
  144. self.send_response(404)
  145. self.end_headers()
  146. return
  147. new_url = self._test_url('中文.html')
  148. self.send_response(302)
  149. self.send_header(b'Location', new_url.encode('utf-8'))
  150. self.end_headers()
  151. elif self.path == '/%E4%B8%AD%E6%96%87.html':
  152. respond()
  153. elif self.path == '/%c7%9f':
  154. respond()
  155. elif self.path.startswith('/redirect_'):
  156. self._redirect()
  157. elif self.path.startswith('/method'):
  158. self._method('GET')
  159. elif self.path.startswith('/headers'):
  160. self._headers()
  161. elif self.path.startswith('/308-to-headers'):
  162. self.send_response(308)
  163. self.send_header('Location', '/headers')
  164. self.send_header('Content-Length', '0')
  165. self.end_headers()
  166. elif self.path == '/trailing_garbage':
  167. payload = b'<html><video src="/vid.mp4" /></html>'
  168. compressed = gzip_compress(payload) + b'trailing garbage'
  169. respond(compressed, payload_encoding='gzip')
  170. elif self.path == '/302-non-ascii-redirect':
  171. new_url = self._test_url('中文.html')
  172. # actually respond with permanent redirect
  173. self.send_response(301)
  174. self.send_header('Location', new_url)
  175. self.send_header('Content-Length', '0')
  176. self.end_headers()
  177. elif self.path == '/content-encoding':
  178. encodings = self.headers.get('ytdl-encoding', '')
  179. payload = b'<html><video src="/vid.mp4" /></html>'
  180. for encoding in filter(None, (e.strip() for e in encodings.split(','))):
  181. if encoding == 'br' and brotli:
  182. payload = brotli.compress(payload)
  183. elif encoding == 'gzip':
  184. payload = gzip_compress(payload)
  185. elif encoding == 'deflate':
  186. payload = zlib.compress(payload)
  187. elif encoding == 'unsupported':
  188. payload = b'raw'
  189. break
  190. else:
  191. self._status(415)
  192. return
  193. respond(payload, payload_encoding=encodings)
  194. else:
  195. self._status(404)
  196. def send_header(self, keyword, value):
  197. """
  198. Forcibly allow HTTP server to send non percent-encoded non-ASCII characters in headers.
  199. This is against what is defined in RFC 3986: but we need to test that we support this
  200. since some sites incorrectly do this.
  201. """
  202. if keyword.lower() == 'connection':
  203. return self.super('send_header', keyword, value)
  204. if not hasattr(self, '_headers_buffer'):
  205. self._headers_buffer = []
  206. self._headers_buffer.append('{0}: {1}\r\n'.format(keyword, value).encode('utf-8'))
  207. def end_headers(self):
  208. if hasattr(self, '_headers_buffer'):
  209. self.wfile.write(b''.join(self._headers_buffer))
  210. self._headers_buffer = []
  211. self.super('end_headers')
  212. class TestHTTP(unittest.TestCase):
  213. def setUp(self):
  214. # HTTP server
  215. self.http_httpd = compat_http_server.HTTPServer(
  216. ('127.0.0.1', 0), HTTPTestRequestHandler)
  217. self.http_port = http_server_port(self.http_httpd)
  218. self.http_server_thread = threading.Thread(target=self.http_httpd.serve_forever)
  219. self.http_server_thread.daemon = True
  220. self.http_server_thread.start()
  221. try:
  222. from http.server import ThreadingHTTPServer
  223. except ImportError:
  224. try:
  225. from socketserver import ThreadingMixIn
  226. except ImportError:
  227. from SocketServer import ThreadingMixIn
  228. class ThreadingHTTPServer(ThreadingMixIn, compat_http_server.HTTPServer):
  229. pass
  230. # HTTPS server
  231. certfn = os.path.join(TEST_DIR, 'testcert.pem')
  232. self.https_httpd = ThreadingHTTPServer(
  233. ('127.0.0.1', 0), HTTPTestRequestHandler)
  234. try:
  235. sslctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
  236. sslctx.verify_mode = ssl.CERT_NONE
  237. sslctx.check_hostname = False
  238. sslctx.load_cert_chain(certfn, None)
  239. self.https_httpd.socket = sslctx.wrap_socket(
  240. self.https_httpd.socket, server_side=True)
  241. except AttributeError:
  242. self.https_httpd.socket = ssl.wrap_socket(
  243. self.https_httpd.socket, certfile=certfn, server_side=True)
  244. self.https_port = http_server_port(self.https_httpd)
  245. self.https_server_thread = threading.Thread(target=self.https_httpd.serve_forever)
  246. self.https_server_thread.daemon = True
  247. self.https_server_thread.start()
  248. def tearDown(self):
  249. def closer(svr):
  250. def _closer():
  251. svr.shutdown()
  252. svr.server_close()
  253. return _closer
  254. shutdown_thread = threading.Thread(target=closer(self.http_httpd))
  255. shutdown_thread.start()
  256. self.http_server_thread.join(2.0)
  257. shutdown_thread = threading.Thread(target=closer(self.https_httpd))
  258. shutdown_thread.start()
  259. self.https_server_thread.join(2.0)
  260. def _test_url(self, path, host='127.0.0.1', scheme='http', port=None):
  261. return '{0}://{1}:{2}/{3}'.format(
  262. scheme, host,
  263. port if port is not None
  264. else self.https_port if scheme == 'https'
  265. else self.http_port, path)
  266. @unittest.skipUnless(
  267. sys.version_info >= (3, 2)
  268. or (sys.version_info[0] == 2 and sys.version_info[1:] >= (7, 9)),
  269. 'No support for certificate check in SSL')
  270. def test_nocheckcertificate(self):
  271. with FakeYDL({'logger': FakeLogger()}) as ydl:
  272. with self.assertRaises(compat_urllib_error.URLError):
  273. ydl.urlopen(sanitized_Request(self._test_url('headers', scheme='https')))
  274. with FakeYDL({'logger': FakeLogger(), 'nocheckcertificate': True}) as ydl:
  275. r = ydl.urlopen(sanitized_Request(self._test_url('headers', scheme='https')))
  276. self.assertEqual(r.getcode(), 200)
  277. r.close()
  278. def test_percent_encode(self):
  279. with FakeYDL() as ydl:
  280. # Unicode characters should be encoded with uppercase percent-encoding
  281. res = ydl.urlopen(sanitized_Request(self._test_url('中文.html')))
  282. self.assertEqual(res.getcode(), 200)
  283. res.close()
  284. # don't normalize existing percent encodings
  285. res = ydl.urlopen(sanitized_Request(self._test_url('%c7%9f')))
  286. self.assertEqual(res.getcode(), 200)
  287. res.close()
  288. def test_unicode_path_redirection(self):
  289. with FakeYDL() as ydl:
  290. r = ydl.urlopen(sanitized_Request(self._test_url('302-non-ascii-redirect')))
  291. self.assertEqual(r.url, self._test_url('%E4%B8%AD%E6%96%87.html'))
  292. r.close()
  293. def test_redirect(self):
  294. with FakeYDL() as ydl:
  295. def do_req(redirect_status, method, check_no_content=False):
  296. data = b'testdata' if method in ('POST', 'PUT') else None
  297. res = ydl.urlopen(sanitized_Request(
  298. self._test_url('redirect_{0}'.format(redirect_status)),
  299. method=method, data=data))
  300. if check_no_content:
  301. self.assertNotIn('Content-Type', res.headers)
  302. return res.read().decode('utf-8'), res.headers.get('method', '')
  303. # A 303 must either use GET or HEAD for subsequent request
  304. self.assertEqual(do_req(303, 'POST'), ('', 'GET'))
  305. self.assertEqual(do_req(303, 'HEAD'), ('', 'HEAD'))
  306. self.assertEqual(do_req(303, 'PUT'), ('', 'GET'))
  307. # 301 and 302 turn POST only into a GET, with no Content-Type
  308. self.assertEqual(do_req(301, 'POST', True), ('', 'GET'))
  309. self.assertEqual(do_req(301, 'HEAD'), ('', 'HEAD'))
  310. self.assertEqual(do_req(302, 'POST', True), ('', 'GET'))
  311. self.assertEqual(do_req(302, 'HEAD'), ('', 'HEAD'))
  312. self.assertEqual(do_req(301, 'PUT'), ('testdata', 'PUT'))
  313. self.assertEqual(do_req(302, 'PUT'), ('testdata', 'PUT'))
  314. # 307 and 308 should not change method
  315. for m in ('POST', 'PUT'):
  316. self.assertEqual(do_req(307, m), ('testdata', m))
  317. self.assertEqual(do_req(308, m), ('testdata', m))
  318. self.assertEqual(do_req(307, 'HEAD'), ('', 'HEAD'))
  319. self.assertEqual(do_req(308, 'HEAD'), ('', 'HEAD'))
  320. # These should not redirect and instead raise an HTTPError
  321. for code in (300, 304, 305, 306):
  322. with self.assertRaises(compat_urllib_HTTPError):
  323. do_req(code, 'GET')
  324. def test_content_type(self):
  325. # https://github.com/yt-dlp/yt-dlp/commit/379a4f161d4ad3e40932dcf5aca6e6fb9715ab28
  326. with FakeYDL({'nocheckcertificate': True}) as ydl:
  327. # method should be auto-detected as POST
  328. r = sanitized_Request(self._test_url('headers', scheme='https'), data=urlencode_postdata({'test': 'test'}))
  329. headers = ydl.urlopen(r).read().decode('utf-8')
  330. self.assertIn('Content-Type: application/x-www-form-urlencoded', headers)
  331. # test http
  332. r = sanitized_Request(self._test_url('headers'), data=urlencode_postdata({'test': 'test'}))
  333. headers = ydl.urlopen(r).read().decode('utf-8')
  334. self.assertIn('Content-Type: application/x-www-form-urlencoded', headers)
  335. def test_cookiejar(self):
  336. with FakeYDL() as ydl:
  337. ydl.cookiejar.set_cookie(compat_http_cookiejar_Cookie(
  338. 0, 'test', 'ytdl', None, False, '127.0.0.1', True,
  339. False, '/headers', True, False, None, False, None, None, {}))
  340. data = ydl.urlopen(sanitized_Request(
  341. self._test_url('headers'))).read().decode('utf-8')
  342. self.assertIn('Cookie: test=ytdl', data)
  343. def test_passed_cookie_header(self):
  344. # We should accept a Cookie header being passed as in normal headers and handle it appropriately.
  345. with FakeYDL() as ydl:
  346. # Specified Cookie header should be used
  347. res = ydl.urlopen(sanitized_Request(
  348. self._test_url('headers'), headers={'Cookie': 'test=test'})).read().decode('utf-8')
  349. self.assertIn('Cookie: test=test', res)
  350. # Specified Cookie header should be removed on any redirect
  351. res = ydl.urlopen(sanitized_Request(
  352. self._test_url('308-to-headers'), headers={'Cookie': 'test=test'})).read().decode('utf-8')
  353. self.assertNotIn('Cookie: test=test', res)
  354. # Specified Cookie header should override global cookiejar for that request
  355. ydl.cookiejar.set_cookie(compat_http_cookiejar_Cookie(
  356. 0, 'test', 'ytdlp', None, False, '127.0.0.1', True,
  357. False, '/headers', True, False, None, False, None, None, {}))
  358. data = ydl.urlopen(sanitized_Request(
  359. self._test_url('headers'), headers={'Cookie': 'test=test'})).read().decode('utf-8')
  360. self.assertNotIn('Cookie: test=ytdlp', data)
  361. self.assertIn('Cookie: test=test', data)
  362. def test_no_compression_compat_header(self):
  363. with FakeYDL() as ydl:
  364. data = ydl.urlopen(
  365. sanitized_Request(
  366. self._test_url('headers'),
  367. headers={'Youtubedl-no-compression': True})).read()
  368. self.assertIn(b'Accept-Encoding: identity', data)
  369. self.assertNotIn(b'youtubedl-no-compression', data.lower())
  370. def test_gzip_trailing_garbage(self):
  371. # https://github.com/ytdl-org/youtube-dl/commit/aa3e950764337ef9800c936f4de89b31c00dfcf5
  372. # https://github.com/ytdl-org/youtube-dl/commit/6f2ec15cee79d35dba065677cad9da7491ec6e6f
  373. with FakeYDL() as ydl:
  374. data = ydl.urlopen(sanitized_Request(self._test_url('trailing_garbage'))).read().decode('utf-8')
  375. self.assertEqual(data, '<html><video src="/vid.mp4" /></html>')
  376. def __test_compression(self, encoding):
  377. with FakeYDL() as ydl:
  378. res = ydl.urlopen(
  379. sanitized_Request(
  380. self._test_url('content-encoding'),
  381. headers={'ytdl-encoding': encoding}))
  382. self.assertEqual(res.headers.get('Content-Encoding'), encoding)
  383. self.assertEqual(res.read(), b'<html><video src="/vid.mp4" /></html>')
  384. @unittest.skipUnless(brotli, 'brotli support is not installed')
  385. @unittest.expectedFailure
  386. def test_brotli(self):
  387. self.__test_compression('br')
  388. @unittest.expectedFailure
  389. def test_deflate(self):
  390. self.__test_compression('deflate')
  391. @unittest.expectedFailure
  392. def test_gzip(self):
  393. self.__test_compression('gzip')
  394. @unittest.expectedFailure # not yet implemented
  395. def test_multiple_encodings(self):
  396. # https://www.rfc-editor.org/rfc/rfc9110.html#section-8.4
  397. with FakeYDL() as ydl:
  398. for pair in ('gzip,deflate', 'deflate, gzip', 'gzip, gzip', 'deflate, deflate'):
  399. res = ydl.urlopen(
  400. sanitized_Request(
  401. self._test_url('content-encoding'),
  402. headers={'ytdl-encoding': pair}))
  403. self.assertEqual(res.headers.get('Content-Encoding'), pair)
  404. self.assertEqual(res.read(), b'<html><video src="/vid.mp4" /></html>')
  405. def test_unsupported_encoding(self):
  406. # it should return the raw content
  407. with FakeYDL() as ydl:
  408. res = ydl.urlopen(
  409. sanitized_Request(
  410. self._test_url('content-encoding'),
  411. headers={'ytdl-encoding': 'unsupported'}))
  412. self.assertEqual(res.headers.get('Content-Encoding'), 'unsupported')
  413. self.assertEqual(res.read(), b'raw')
  414. def _build_proxy_handler(name):
  415. class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
  416. proxy_name = name
  417. def log_message(self, format, *args):
  418. pass
  419. def do_GET(self):
  420. self.send_response(200)
  421. self.send_header('Content-Type', 'text/plain; charset=utf-8')
  422. self.end_headers()
  423. self.wfile.write('{0}: {1}'.format(self.proxy_name, self.path).encode('utf-8'))
  424. return HTTPTestRequestHandler
  425. class TestProxy(unittest.TestCase):
  426. def setUp(self):
  427. self.proxy = compat_http_server.HTTPServer(
  428. ('127.0.0.1', 0), _build_proxy_handler('normal'))
  429. self.port = http_server_port(self.proxy)
  430. self.proxy_thread = threading.Thread(target=self.proxy.serve_forever)
  431. self.proxy_thread.daemon = True
  432. self.proxy_thread.start()
  433. self.geo_proxy = compat_http_server.HTTPServer(
  434. ('127.0.0.1', 0), _build_proxy_handler('geo'))
  435. self.geo_port = http_server_port(self.geo_proxy)
  436. self.geo_proxy_thread = threading.Thread(target=self.geo_proxy.serve_forever)
  437. self.geo_proxy_thread.daemon = True
  438. self.geo_proxy_thread.start()
  439. def tearDown(self):
  440. def closer(svr):
  441. def _closer():
  442. svr.shutdown()
  443. svr.server_close()
  444. return _closer
  445. shutdown_thread = threading.Thread(target=closer(self.proxy))
  446. shutdown_thread.start()
  447. self.proxy_thread.join(2.0)
  448. shutdown_thread = threading.Thread(target=closer(self.geo_proxy))
  449. shutdown_thread.start()
  450. self.geo_proxy_thread.join(2.0)
  451. def _test_proxy(self, host='127.0.0.1', port=None):
  452. return '{0}:{1}'.format(
  453. host, port if port is not None else self.port)
  454. def test_proxy(self):
  455. geo_proxy = self._test_proxy(port=self.geo_port)
  456. ydl = YoutubeDL({
  457. 'proxy': self._test_proxy(),
  458. 'geo_verification_proxy': geo_proxy,
  459. })
  460. url = 'http://foo.com/bar'
  461. response = ydl.urlopen(url).read().decode('utf-8')
  462. self.assertEqual(response, 'normal: {0}'.format(url))
  463. req = compat_urllib_request.Request(url)
  464. req.add_header('Ytdl-request-proxy', geo_proxy)
  465. response = ydl.urlopen(req).read().decode('utf-8')
  466. self.assertEqual(response, 'geo: {0}'.format(url))
  467. def test_proxy_with_idn(self):
  468. ydl = YoutubeDL({
  469. 'proxy': self._test_proxy(),
  470. })
  471. url = 'http://中文.tw/'
  472. response = ydl.urlopen(url).read().decode('utf-8')
  473. # b'xn--fiq228c' is '中文'.encode('idna')
  474. self.assertEqual(response, 'normal: http://xn--fiq228c.tw/')
  475. class TestFileURL(unittest.TestCase):
  476. # See https://github.com/ytdl-org/youtube-dl/issues/8227
  477. def test_file_urls(self):
  478. tf = tempfile.NamedTemporaryFile(delete=False)
  479. tf.write(b'foobar')
  480. tf.close()
  481. url = compat_urllib_parse.urljoin('file://', pathname2url(tf.name))
  482. with FakeYDL() as ydl:
  483. self.assertRaisesRegexp(
  484. compat_urllib_error.URLError, 'file:// scheme is explicitly disabled in youtube-dl for security reasons', ydl.urlopen, url)
  485. # not yet implemented
  486. """
  487. with FakeYDL({'enable_file_urls': True}) as ydl:
  488. res = ydl.urlopen(url)
  489. self.assertEqual(res.read(), b'foobar')
  490. res.close()
  491. """
  492. os.unlink(tf.name)
  493. if __name__ == '__main__':
  494. unittest.main()