homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients orsenthil, vstinner, xtreak
Date 2019年07月01日.19:27:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562009264.84.0.848471907966.issue37475@roundup.psfhosted.org>
In-reply-to
Content
I have added Senthil for thoughts. The temporary files is also stored in a module level variable. Looking into the git history there were some changes in e24f96a05973ddbb59d88c03570aef8545c5ef10 . The function is also marked as legacy in __all__ with compat code in 2to3. urlcleanup also sets the global variable _opener to None so it does the extra work of uninstalling the global variable opener set by install_opener which is also not documented.
urlretrieve enables retrieving and storing the content in a temporary file to return (tempfilename, headers) to be read later. In case the user doesn't give a filename it implicitly creates a temporary file. There is similar code in urllib.request.URLopener().retrieve [0] too where the temporary files are created implicitly but __del__ is overridden where the temp files are deleted as the program exits. I think it's better to ask the user to give filename and so that the user is responsible for the file but since the behavior is present for a long time there is backwards compatibility in changing this and there might be some code depending on the implicit temporary file created as a feature. 
One possible way would be to have a wrapper class that creates the temporary file when not given and then deletes it or calls urlcleanup on __del__ to clean it up as the GC is called like URLopener.retrieve? This would be done only when user doesn't give a file and for the temporary files generated by urlretrieve.
[0] https://github.com/python/cpython/blob/67310023f299b5a2fad71fca449b46d280036690/Lib/urllib/request.py#L1702 
History
Date User Action Args
2019年07月01日 19:27:44xtreaksetrecipients: + xtreak, orsenthil, vstinner
2019年07月01日 19:27:44xtreaksetmessageid: <1562009264.84.0.848471907966.issue37475@roundup.psfhosted.org>
2019年07月01日 19:27:44xtreaklinkissue37475 messages
2019年07月01日 19:27:44xtreakcreate

AltStyle によって変換されたページ (->オリジナル) /