Remove to-be-deprecated urllib.request.urlretrieve function reference… · python/cpython@f20eca7
@@ -56,12 +56,20 @@ The simplest way to use urllib.request is as follows::
5656 with urllib.request.urlopen('http://python.org/') as response:
5757 html = response.read()
585859-If you wish to retrieve a resource via URL and store it in a temporary location,
60-you can do so via the :func:`~urllib.request.urlretrieve` function::
59+If you wish to retrieve a resource via URL and store it in a temporary
60+location, you can do so via the :func:`shutil.copyfileobj` and
61+:func:`tempfile.NamedTemporaryFile` functions::
616263+ import shutil
64+ import tempfile
6265 import urllib.request
63- local_filename, headers = urllib.request.urlretrieve('http://python.org/')
64- html = open(local_filename)
66+67+ with urllib.request.urlopen('http://python.org/') as response:
68+ with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
69+ shutil.copyfileobj(response, tmp_file)
70+71+ with open(tmp_file.name) as html:
72+ pass
65736674Many uses of urllib will be that simple (note that instead of an 'http:' URL we
6775could have used a URL starting with 'ftp:', 'file:', etc.). However, it's the