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 pagelist(object):
19 """Class representing a list of either pages, or nested
20 pagelists. Might be, for instance, a volume or a chapter.
22 All pagelists should contain an attribute `name', containing some
23 human-readable Unicode representation of the pagelist."""
26 """Return the number of (direct) sub-nodes in this pagelist.
28 All pagelists need to implement this."""
29 raise NotImplementedError()
31 def __getitem__(self, idx):
32 """Return the direct sub-node of the given index in this
33 pagelist. Sub-node indexes are always zero-based and
34 contiguous, regardless of any gaps in the underlying medium,
35 which should be indicated instead by way of the `name'
38 All pagelists need to implement this."""
39 raise NotImplementedError()
41 class manga(pagelist):
42 """Class reprenting a single manga. Includes the pagelist class,
43 and all constraints valid for it."""
47 """Class representing a single page of a manga. Pages make up the
48 leaf nodes of a pagelist tree.
50 All pages should contain an attribute `manga', referring back to
51 the containing manga instance."""
54 """Open a stream for the image this page represents. The
55 returned object should be an imgstream class.
57 All pages need to implement this."""
58 raise NotImplementedError()
60 class imgstream(object):
61 """An open image I/O stream for a manga page. Generally, it should
62 be file-like. This base class implements the resource-manager
63 interface for use in `with' statements, calling close() on itself
64 when exiting the with-scope.
66 All imgstreams should contain an attribute `ctype', being the
67 Content-Type of the image being read by the stream."""
72 def __exit__(self, *exc_info):
76 """Close this stream."""
77 raise NotImplementedError()
79 def read(self, sz = None):
80 """Read SZ bytes from the stream, or the entire rest of the
81 stream of SZ is not given."""
82 raise NotImplementedError()
84 class pageiter(object):
85 def __init__(self, root):
91 if len(self.nstack) == 0:
94 node = self.lstack[-1][self.nstack[-1]]
98 if len(self.nstack) > 0:
101 if isinstance(node, page):
102 nl = tuple(self.nstack)
105 elif isinstance(node, pagelist):
106 self.lstack.append(node)
107 self.nstack.append(0)