Beispiel #1
0
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
Beispiel #2
0
    value = match_obj.group(1)
    return param.replace(value, value.replace('"',"""))

def parse(html):
    html = _sanitize(html)
    parser = HHCParser()
    parser.feed(html)
    parser.close()
    return parser.root_context

if __name__ == "__main__":
    import sys
    from pychmlib.chm import chm
    filenames = sys.argv[1:]
    if filenames:
        chm_file = chm(filenames.pop())
        hhc_file_contents = chm_file.get_hhc().get_content()
        contents = parse(hhc_file_contents)
        def recur_print(content, spaces=0):
            if spaces > 0:
                tab = " " * spaces
                print tab + content.name
                if content.local:
                    print tab + "(" +content.local + ")"
            if content.is_inner_node:
                for i in content.children:
                    recur_print(i, spaces + 2)
        recur_print(contents) 
        chm_file.close()
    else:
        print "Please provide a CHM file as parameter"