+
+class DocProvider(object):
+ """ Base class for a repository of XML files.
+ Used for generating joined files, like EPUBs
+ """
+
+ def by_slug(self, slug):
+ raise NotImplemented
+
+ def __getitem__(self, slug):
+ return self.by_slug(slug)
+
+ def by_uri(self, uri):
+ return self.by_slug(uri.rsplit('/', 1)[1])
+
+
+class DirDocProvider(DocProvider):
+ """ Serve docs from a directory of files in form <slug>.xml """
+
+ def __init__(self, dir):
+ self.dir = dir
+ self.files = {}
+
+ def by_slug(self, slug):
+ return open(os.path.join(self.dir, '%s.xml' % slug))
+
+