2. The “driver”¶
The entry point to the package is through the DocWrapper
class below. An instance of that class controls the
necessary workflow for the EPUB generation, namely:
- gets hold of the content, possibly converts the ReSpec source on the fly to HTML
- creates a
document.Document
class around the content that holds all the necessary metadata and further references - creates the book and, if required, the folder for the content
- collects all the dependencies from the Web, and copies them to the output
- creates all the auxiliary files (package file, navigation files, etc) and copies them to the output
2.1. Module content¶
-
rp2epub.doc2epub.
CONVERTER
= 'https://labs.w3.org/spec-generator/?type=respec&url='¶ URI of the service used to convert a ReSpec source onto an HTML file on the fly. This service is used by this script to convert ReSpec sources into HTML before EPUB3 generation.
-
class
rp2epub.doc2epub.
DocWrapper
(url, is_respec=False, package=True, folder=False, temporary=False, logger=None)[source]¶ Top level entry class; receives the URI to be retrieved and generates the folders and/or the EPUB Package in the current directory (by default).
Parameters: - url (str) – location of the document source
- is_respec (boolean) – flag whether the source is a ReSpec source (ie, has to be transformed through spec generator) or not
- package (boolean) – whether a real zip file (ie, the EPUB instance) should be created or not
- folder (boolean) – whether the directory structure should be created separately or not
- temporary (boolean) – whether the zipped EPUB file should be put into a temporary filesystem location (used when the service is used through the Web)
- logger – a python logger (see the standard library module on logging) to be used all around; None means no logging
-
base
¶ Base URI for the document (used to retrieve additional resources, if needed)
-
book
¶ The book being generated; an open
zipfile.ZipFile
instance
-
book_file_name
¶ Name of the book; usually shortname + .epub, but can be a temporary file if so requested (the term “shortname” is a W3C jargon…)
-
document
¶ Wrapper around the document, containing extra meta information for packaging
-
domain
¶ Domain of the original source
-
folder
¶ Flag whether a folder, containing the package content, is created separately
-
html
¶ HTML element as parsed; an
xml.etree.ElementTree.ElementTree
instance
-
html_document
¶ Document, as parsed; an
xml.etree.ElementTree.Element
instance
-
package
¶ Flag whether an epub package is created
-
process
()[source]¶ Process the book, ie, extract whatever has to be extracted and produce the epub file.
Returns: the instance of the class itself
-
top_uri
¶ Top level (absolute) URI for the file to be processed
-
url_respec_setting
¶ Possible ReSpec configuration setting via the query part of the URI of the document