diff options
author | Guido van Rossum <guido@python.org> | 1997-10-27 18:56:19 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-10-27 18:56:19 (GMT) |
commit | 036309b13eefbcc009f44142e29a98cbe9e2a460 (patch) | |
tree | 8db4dad5c13f34cb1e3ebee439596cca62c96e0e /Lib/urllib.py | |
parent | af8d2bf4d8643f7da7389a475f364c21836e8afe (diff) | |
download | cpython-036309b13eefbcc009f44142e29a98cbe9e2a460.zip cpython-036309b13eefbcc009f44142e29a98cbe9e2a460.tar.gz cpython-036309b13eefbcc009f44142e29a98cbe9e2a460.tar.bz2 |
This should hopefully finally clean up the remaining __del__ related
problems with this module, even if an instance of a derived class is
kept alive longer than the urllib module itself...
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index 422cb9e..a818adf 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -27,7 +27,7 @@ import os import sys -__version__ = '1.8' +__version__ = '1.9' MAXFTPCACHE = 10 # Trim the ftp cache beyond this size @@ -81,7 +81,7 @@ def urlcleanup(): ftpcache = {} class URLopener: - __tempfiles = [] + __tempfiles = None # Constructor def __init__(self, proxies=None): @@ -91,6 +91,7 @@ class URLopener: server_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-agent', server_version)] self.__tempfiles = [] + self.__unlink = os.unlink # See cleanup() self.tempcache = None # Undocumented feature: if you assign {} to tempcache, # it is used to cache files retrieved with @@ -110,15 +111,18 @@ class URLopener: self.cleanup() def cleanup(self): + # This code sometimes runs when the rest of this module + # has already been deleted, so it can't use any globals + # or import anything. if self.__tempfiles: - import os for file in self.__tempfiles: try: - os.unlink(file) - except os.error: + self.__unlink(file) + except: pass - URLopener.__tempfiles = [] - self.tempcache = None + del self.__tempfiles[:] + if self.tempcache: + self.tempcache.clear() # Add a header to be used by the HTTP interface only # e.g. u.addheader('Accept', 'sound/basic') @@ -429,11 +433,9 @@ class FancyURLopener(URLopener): return None, None def echo_off(self): - import os os.system("stty -echo") def echo_on(self): - import os print os.system("stty echo") |