ftpcache = {}
class URLopener:
- tempcache = None # So close() in __del__() won't fail
+ __tempfiles = []
# Constructor
def __init__(self, proxies=None):
self.cleanup()
def cleanup(self):
- if self.tempcache:
+ if self.__tempfiles:
import os
- for url in self.tempcache.keys():
+ for file in self.__tempfiles:
try:
- os.unlink(self.tempcache[url][0])
+ os.unlink(file)
except os.error:
pass
- del self.tempcache[url]
+ URLopener.__tempfiles = []
+ self.tempcache = None
# Add a header to be used by the HTTP interface only
# e.g. u.addheader('Accept', 'sound/basic')
if not filename:
import tempfile
filename = tempfile.mktemp()
+ self.__tempfiles.append(filename)
result = filename, headers
if self.tempcache is not None:
self.tempcache[url] = result
# Interpret ../ (important because of symlinks)
while basepath and path[:3] == '../':
path = path[3:]
- i = string.rfind(basepath, '/')
+ i = string.rfind(basepath[:-1], '/')
if i > 0:
- basepath = basepath[:i-1]
+ basepath = basepath[:i+1]
+ elif i == 0:
+ basepath = '/'
+ break
+ else:
+ basepath = ''
path = basepath + path
if type and host: return type + '://' + host + path