test_http.py 22 KB

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