Dolda2000 GitWeb
/
automanga.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ebc277d
)
Make the cache interface slightly more extensible.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Wed, 31 Aug 2016 20:19:55 +0000
(22:19 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Wed, 31 Aug 2016 20:19:55 +0000
(22:19 +0200)
manga/htcache.py
patch
|
blob
|
blame
|
history
diff --git
a/manga/htcache.py
b/manga/htcache.py
index
2aa594e
..
a53aa45
100644
(file)
--- a/
manga/htcache.py
+++ b/
manga/htcache.py
@@
-2,6
+2,9
@@
import os, hashlib, urllib.request, time
from . import profile
pj = os.path.join
from . import profile
pj = os.path.join
+class notfound(Exception):
+ pass
+
class cache(object):
def __init__(self, dir):
self.dir = dir
class cache(object):
def __init__(self, dir):
self.dir = dir
@@
-11,9
+14,18
@@
class cache(object):
n.update(url.encode("ascii"))
return n.hexdigest()
n.update(url.encode("ascii"))
return n.hexdigest()
- def
miss
(self, url):
+ def
open
(self, url):
req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"})
req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"})
- with urllib.request.urlopen(req) as s:
+ return urllib.request.urlopen(req)
+
+ def miss(self, url):
+ try:
+ s = self.open(url)
+ except urllib.error.HTTPError as exc:
+ if exc.code == 404:
+ raise notfound(url)
+ raise
+ with s:
if s.headers.get("content-encoding") == "gzip":
import gzip, io
return gzip.GzipFile(fileobj=io.BytesIO(s.read()), mode="r").read()
if s.headers.get("content-encoding") == "gzip":
import gzip, io
return gzip.GzipFile(fileobj=io.BytesIO(s.read()), mode="r").read()