diff options
author | Guido van Rossum <guido@python.org> | 1998-02-05 16:22:27 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-02-05 16:22:27 (GMT) |
commit | 03710d2a4024a03bf7d16a3dad32117ea7910151 (patch) | |
tree | 951ff70a41e39fe4377c1ecf64b9ddd57db9cf87 /Lib | |
parent | c5d8fed26106d398fc3c0e27fa4c2364f4c40c40 (diff) | |
download | cpython-03710d2a4024a03bf7d16a3dad32117ea7910151.zip cpython-03710d2a4024a03bf7d16a3dad32117ea7910151.tar.gz cpython-03710d2a4024a03bf7d16a3dad32117ea7910151.tar.bz2 |
Two suggested features by Sjoerd:
- use the tempcache in the open() method, too.
- use the "unwrap"ped url as key for the tempcache.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/urllib.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index 35ba479..5363f3c 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -134,6 +134,10 @@ class URLopener: # Use URLopener().open(file) instead of open(file, 'r') def open(self, fullurl, data=None): fullurl = unwrap(fullurl) + if self.tempcache and self.tempcache.has_key(fullurl): + filename, headers = self.tempcache[fullurl] + fp = open(filename, 'rb') + return addinfourl(fp, headers, fullurl) type, url = splittype(fullurl) if not type: type = 'file' self.openedurl = '%s:%s' % (type, url) @@ -168,14 +172,11 @@ class URLopener: # retrieve(url) returns (filename, None) for a local object # or (tempfilename, headers) for a remote object def retrieve(self, url, filename=None): + url = unwrap(url) + self.openedurl = url if self.tempcache and self.tempcache.has_key(url): return self.tempcache[url] - url1 = unwrap(url) - self.openedurl = url1 - if self.tempcache and self.tempcache.has_key(url1): - self.tempcache[url] = self.tempcache[url1] - return self.tempcache[url1] - type, url1 = splittype(url1) + type, url1 = splittype(url) if not filename and (not type or type == 'file'): try: fp = self.open_local_file(url1) |