'Convert an ebook file into an exploded OEB book suitable for
display in viewers/preprocessing etc.'

def __enter__(self, processed=False, only_input_plugin=False, run_char_count=True, read_anchor_map=True, view_kepub=False, read_links=True):

    self.delete_on_exit = []
    self._tdir = TemporaryDirectory(u'_ebook_iter')
    self.base = os.path.realpath(self._tdir.__enter__())
    (self.book_format, self.pathtoopf, input_fmt) = run_extract_book(self.pathtoebook, self.base, only_input_plugin=only_input_plugin, view_kepub=view_kepub, processed=processed)
    self.opf = OPF(self.pathtoopf, os.path.dirname(self.pathtoopf))
    self.mi = self.opf.to_book_metadata()
    self.language = None
    if self.mi.languages:
        self.language = self.mi.languages[0].lower()
    ordered = ([i for i in self.opf.spine if i.is_linear] + [i for i in self.opf.spine if (not i.is_linear)])
    self.spine = []
    Spiny = partial(SpineItem, read_anchor_map=read_anchor_map, read_links=read_links, run_char_count=run_char_count, from_epub=(self.book_format == u'EPUB'))
    is_comic = (input_fmt.lower() in {u'cbc', u'cbz', u'cbr', u'cb7'})
    for i in ordered:
        spath = i.path
        mt = None
        if (i.idref is not None):
            mt = self.opf.manifest.type_for_id(i.idref)
        if (mt is None):
            mt = guess_type(spath)[0]
        try:
            self.spine.append(Spiny(spath, mime_type=mt))
            if is_comic:
                self.spine[(-1)].is_single_page = True
        except:
            self.log.warn(u'Missing    spine    item:', repr(spath))
    cover = self.opf.cover
    if (cover and (self.ebook_ext in {u'lit', u'mobi', u'prc', u'opf', u'fb2', u'azw', u'azw3', u'docx', u'htmlz'})):
        cfile = os.path.join(self.base, u'calibre_iterator_cover.html')
        rcpath = os.path.relpath(cover, self.base).replace(os.sep, u'/')
        chtml = (TITLEPAGE % prepare_string_for_xml(rcpath, True)).encode(u'utf-8')
        with open(cfile, u'wb') as f:
            f.write(chtml)
        self.spine[0:0] = [Spiny(cfile, mime_type=u'application/xhtml+xml')]
        self.delete_on_exit.append(cfile)
    if ((self.opf.path_to_html_toc is not None) and (self.opf.path_to_html_toc not in self.spine)):
        try:
            self.spine.append(Spiny(self.opf.path_to_html_toc))
        except:
            import traceback
            traceback.print_exc()
    sizes = [i.character_count for i in self.spine]
    self.pages = [math.ceil((i / float(self.CHARACTERS_PER_PAGE))) for i in sizes]
    for (p, s) in zip(self.pages, self.spine):
        s.pages = p
    start = 1
    for s in self.spine:
        s.start_page = start
        start += s.pages
        s.max_page = ((s.start_page + s.pages) - 1)
    self.toc = self.opf.toc
    if read_anchor_map:
        create_indexing_data(self.spine, self.toc)
    self.verify_links()
    self.read_bookmarks()
    return self
