2 """Class representing a single source of multiple mangas."""
4 def byname(self, prefix):
5 """Returns an iterable object of all mangas in this library
6 whose names (case-insensitively) begin with the given
9 All libraries should implement this."""
10 raise NotImplementedError()
13 """Return an iterator of all known mangas in this library.
15 Not all libraries need implement this."""
16 raise NotImplementedError("manga.lib.library iterator")
18 class pagetree(object):
19 """Base class for objects in the tree of pages and pagelists.
21 All pagetree objects should contain an attribute `stack', contains
22 a list of pairs. The last pair in the list should be the pagetree
23 object which yielded this pagetree object, along with the index
24 which yielded it. Every non-last pair should be the same
25 information for the pair following it. The only objects with empty
26 `stack' lists should be `manga' objects."""
29 class pagelist(pagetree):
30 """Class representing a list of either pages, or nested
31 pagelists. Might be, for instance, a volume or a chapter.
33 All pagelists should contain an attribute `name', containing some
34 human-readable Unicode representation of the pagelist."""
37 """Return the number of (direct) sub-nodes in this pagelist.
39 All pagelists need to implement this."""
40 raise NotImplementedError()
42 def __getitem__(self, idx):
43 """Return the direct sub-node of the given index in this
44 pagelist. Sub-node indexes are always zero-based and
45 contiguous, regardless of any gaps in the underlying medium,
46 which should be indicated instead by way of the `name'
49 All pagelists need to implement this."""
50 raise NotImplementedError()
52 class manga(pagelist):
53 """Class reprenting a single manga. Includes the pagelist class,
54 and all constraints valid for it."""
58 """Class representing a single page of a manga. Pages make up the
59 leaf nodes of a pagelist tree.
61 All pages should contain an attribute `manga', referring back to
62 the containing manga instance."""
65 """Open a stream for the image this page represents. The
66 returned object should be an imgstream class.
68 All pages need to implement this."""
69 raise NotImplementedError()
71 class imgstream(object):
72 """An open image I/O stream for a manga page. Generally, it should
73 be file-like. This base class implements the resource-manager
74 interface for use in `with' statements, calling close() on itself
75 when exiting the with-scope.
77 All imgstreams should contain an attribute `ctype', being the
78 Content-Type of the image being read by the stream."""
83 def __exit__(self, *exc_info):
87 """Close this stream."""
88 raise NotImplementedError()
90 def read(self, sz = None):
91 """Read SZ bytes from the stream, or the entire rest of the
92 stream of SZ is not given."""
93 raise NotImplementedError()
96 def __init__(self, ob):
97 self.cur = self.descend(ob)
99 def descend(self, ob):
100 while isinstance(ob, pagelist):
102 if not isinstance(ob, page):
103 raise TypeError("object in page tree was unexpectedly not a pagetree")
107 for n, i in reversed(self.cur.stack):
109 self.cur = self.descend(n[i + 1])
111 raise StopIteration()
114 for n, i in reversed(self.cur,stack):
116 self.cur = self.descend(n[i - 1])
118 raise StopIteration()