Beispiel #1
0
    def __init__(self, input, log, input_encoding=None):
        CHMFile.__init__(self)
        if isinstance(input, unicode_type):
            input = input.encode(filesystem_encoding)
        if not self.LoadCHM(input):
            raise CHMError("Unable to open CHM file '%s'" % (input, ))
        self.log = log
        self.input_encoding = input_encoding
        self.chm_encoding = self.get_encoding() or 'cp1252'
        self._sourcechm = input
        self._contents = None
        self._playorder = 0
        self._metadata = False
        self._extracted = False
        self.re_encoded_files = set()
        if self.home:
            self.home = as_unicode(self.home, self.chm_encoding)
        if self.topics:
            self.topics = as_unicode(self.topics, self.chm_encoding)

        # location of '.hhc' file, which is the CHM TOC.
        if self.topics is None:
            self.root, ext = os.path.splitext(self.home.lstrip('/'))
            self.hhc_path = self.root + ".hhc"
        else:
            self.root, ext = os.path.splitext(self.topics.lstrip('/'))
            self.hhc_path = self.root + ".hhc"
Beispiel #2
0
 def ResolveObject(self, path):
     opath = path
     if not isinstance(path, bytes):
         path = path.encode(self.chm_encoding)
     ans = CHMFile.ResolveObject(self, path)
     if ans[0] != chmlib.CHM_RESOLVE_SUCCESS and not isinstance(
             opath, bytes):
         path = opath.encode('utf-8')
         ans = CHMFile.ResolveObject(self, path)
     return ans
Beispiel #3
0
    def __init__(self, input, log, input_encoding=None):
        CHMFile.__init__(self)
        if isinstance(input, unicode):
            input = input.encode(filesystem_encoding)
        if not self.LoadCHM(input):
            raise CHMError("Unable to open CHM file '%s'"%(input,))
        self.log = log
        self.input_encoding = input_encoding
        self._sourcechm = input
        self._contents = None
        self._playorder = 0
        self._metadata = False
        self._extracted = False

        # location of '.hhc' file, which is the CHM TOC.
        if self.topics is None:
            self.root, ext = os.path.splitext(self.home.lstrip('/'))
            self.hhc_path = self.root + ".hhc"
        else:
            self.root, ext = os.path.splitext(self.topics.lstrip('/'))
            self.hhc_path = self.root + ".hhc"
Beispiel #4
0
 def ResolveObject(self, path):
     if not isinstance(path, bytes):
         path = path.encode(self.chm_encoding)
     return CHMFile.ResolveObject(self, path)