mirror of
https://github.com/python/cpython.git
synced 2025-07-16 15:55:18 +00:00
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...
This commit is contained in:
parent
af8d2bf4d8
commit
036309b13e
1 changed files with 11 additions and 9 deletions
|
@ -27,7 +27,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
__version__ = '1.8'
|
__version__ = '1.9'
|
||||||
|
|
||||||
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
|
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def urlcleanup():
|
||||||
ftpcache = {}
|
ftpcache = {}
|
||||||
class URLopener:
|
class URLopener:
|
||||||
|
|
||||||
__tempfiles = []
|
__tempfiles = None
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
def __init__(self, proxies=None):
|
def __init__(self, proxies=None):
|
||||||
|
@ -91,6 +91,7 @@ class URLopener:
|
||||||
server_version = "Python-urllib/%s" % __version__
|
server_version = "Python-urllib/%s" % __version__
|
||||||
self.addheaders = [('User-agent', server_version)]
|
self.addheaders = [('User-agent', server_version)]
|
||||||
self.__tempfiles = []
|
self.__tempfiles = []
|
||||||
|
self.__unlink = os.unlink # See cleanup()
|
||||||
self.tempcache = None
|
self.tempcache = None
|
||||||
# Undocumented feature: if you assign {} to tempcache,
|
# Undocumented feature: if you assign {} to tempcache,
|
||||||
# it is used to cache files retrieved with
|
# it is used to cache files retrieved with
|
||||||
|
@ -110,15 +111,18 @@ class URLopener:
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
|
||||||
def cleanup(self):
|
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:
|
if self.__tempfiles:
|
||||||
import os
|
|
||||||
for file in self.__tempfiles:
|
for file in self.__tempfiles:
|
||||||
try:
|
try:
|
||||||
os.unlink(file)
|
self.__unlink(file)
|
||||||
except os.error:
|
except:
|
||||||
pass
|
pass
|
||||||
URLopener.__tempfiles = []
|
del self.__tempfiles[:]
|
||||||
self.tempcache = None
|
if self.tempcache:
|
||||||
|
self.tempcache.clear()
|
||||||
|
|
||||||
# Add a header to be used by the HTTP interface only
|
# Add a header to be used by the HTTP interface only
|
||||||
# e.g. u.addheader('Accept', 'sound/basic')
|
# e.g. u.addheader('Accept', 'sound/basic')
|
||||||
|
@ -429,11 +433,9 @@ class FancyURLopener(URLopener):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def echo_off(self):
|
def echo_off(self):
|
||||||
import os
|
|
||||||
os.system("stty -echo")
|
os.system("stty -echo")
|
||||||
|
|
||||||
def echo_on(self):
|
def echo_on(self):
|
||||||
import os
|
|
||||||
print
|
print
|
||||||
os.system("stty echo")
|
os.system("stty echo")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue