Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03710d2

Browse files
committed
Two suggested features by Sjoerd:
- use the tempcache in the open() method, too. - use the "unwrap"ped url as key for the tempcache.
1 parent c5d8fed commit 03710d2

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

Lib/urllib.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def addheader(self, *args):
134134
# Use URLopener().open(file) instead of open(file, 'r')
135135
def open(self, fullurl, data=None):
136136
fullurl = unwrap(fullurl)
137+
if self.tempcache and self.tempcache.has_key(fullurl):
138+
filename, headers = self.tempcache[fullurl]
139+
fp = open(filename, 'rb')
140+
return addinfourl(fp, headers, fullurl)
137141
type, url = splittype(fullurl)
138142
if not type: type = 'file'
139143
self.openedurl = '%s:%s' % (type, url)
@@ -168,14 +172,11 @@ def open_unknown(self, fullurl, data=None):
168172
# retrieve(url) returns (filename, None) for a local object
169173
# or (tempfilename, headers) for a remote object
170174
def retrieve(self, url, filename=None):
175+
url = unwrap(url)
176+
self.openedurl = url
171177
if self.tempcache and self.tempcache.has_key(url):
172178
return self.tempcache[url]
173-
url1 = unwrap(url)
174-
self.openedurl = url1
175-
if self.tempcache and self.tempcache.has_key(url1):
176-
self.tempcache[url] = self.tempcache[url1]
177-
return self.tempcache[url1]
178-
type, url1 = splittype(url1)
179+
type, url1 = splittype(url)
179180
if not filename and (not type or type == 'file'):
180181
try:
181182
fp = self.open_local_file(url1)

0 commit comments

Comments
 (0)