def open_offline(self, filename): stall() e32.ao_yield() import pychmlib try: chm_file = pychmlib.chm.chm(filename) except: appuifw.note(ERR_READING, "error") self.refresh() return try: hhc_file = chm_file.get_hhc() if hhc_file: import hhc hhc_obj = hhc.parse(hhc_file.get_content()) viewer = HHCViewer(filename, hhc_obj, chm_file.encoding) viewer.set_as_offline(chm_file) viewer.show() self.quit() else: appuifw.note(ERR_NO_HHC, "error") self.refresh() return finally: chm_file.close()
def _serve_chm(hostname, port, filename, hhc_callback=None): LOCK.acquire() try: try: chm_file = chm(filename) except Exception, e: hhc_callback(error=ERR_INVALID_CHM) return if hhc_callback: hhc_file = chm_file.get_hhc() if hhc_file: contents = hhc.parse(hhc_file.get_content()) encoding = chm_file.encoding hhc_callback(filename, contents, encoding) else: chm_file.close() hhc_callback(error=ERR_NO_HHC) return #no hhc, so what's the sense of continuing? try: _serve_chm_forever(chm_file, hostname, port) except Exception, e: # server shutting down because of error pass