Fix news download with unicode temp path

This commit is contained in:
Kovid Goyal 2012-02-23 11:53:38 +05:30
parent 4e219458b0
commit 7b6c55865c

View File

@ -201,6 +201,24 @@ class RecursiveFetcher(object):
def fetch_url(self, url):
data = None
self.log.debug('Fetching', url)
# Check for a URL pointing to the local filesystem and special case it
# for efficiency and robustness. Bypasses delay checking as it does not
# apply to local fetches. Ensures that unicode paths that are not
# representable in the filesystem_encoding work.
is_local = 0
if url.startswith('file://'):
is_local = 7
elif url.startswith('file:'):
is_local = 5
if is_local > 0:
url = url[is_local:]
with open(url, 'rb') as f:
data = response(f.read())
data.newurl = 'file:'+url # This is what mechanize does for
# local URLs
return data
delta = time.time() - self.last_fetch_at
if delta < self.delay:
time.sleep(self.delay - delta)