X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Flib.py;h=849e632ffb6afd7c6f26d229f861dd9b9580145d;hb=9bdfc96815a1515db28e08d63eab05f2b925fb82;hp=8cc96cb712d9f398f0c18bda1a839fe74b953c93;hpb=36ec46b3e26fe306a16a4686f51cd76e99c35df1;p=automanga.git diff --git a/manga/lib.py b/manga/lib.py index 8cc96cb..849e632 100644 --- a/manga/lib.py +++ b/manga/lib.py @@ -158,9 +158,12 @@ class stdimgstream(imgstream): """A standard implementation of imgstream, for libraries which have no particular implementation requirements.""" - def __init__(self, url): + def __init__(self, url, referer=None): import urllib.request - req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"}) + headers = {"User-Agent": "automanga/1"} + if referer: + headers["Referer"] = referer + req = urllib.request.Request(url, headers=headers) self.bk = urllib.request.urlopen(req) ok = False try: @@ -206,9 +209,6 @@ class cursor(object): return self.cur raise StopIteration() - def __next__(self): - return self.next() - def prev(self): for n, i in reversed(self.cur.stack): if i > 0: @@ -217,7 +217,14 @@ class cursor(object): raise StopIteration() def __iter__(self): - return self + def iterator(): + yield self.cur + while True: + try: + yield self.next() + except StopIteration: + break + return iterator() loaded = {} def findlib(name):