diff --git a/src/calibre/web/fetch/simple.py b/src/calibre/web/fetch/simple.py index 076b619ee4..9993d9a3db 100644 --- a/src/calibre/web/fetch/simple.py +++ b/src/calibre/web/fetch/simple.py @@ -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)