def main():
    buf = fileutil.aStringIO()
    sys.stdout = buf
    try:
        app_httpserver.main()
    finally:
        sys.stdout = sys.__stdout__

    buf.seek(0)
    fp = file('1.html','wb')
    fix_link(buf,fp)
    fp.close()

    print 'See output in 1.html'

    # what's wrong with opera?
    webbrowser.open("1.html")
    rfile = StringIO(request)
    client_soc = FileSocket(rfile, wfile)
    client_address = ("127.0.0.1", 0)
    server = DummyServer()
    AppHTTPRequestHandler(client_soc, client_address, server)


def main():
    """ Invoke AppHTTPRequestHandler from command line """

    if len(sys.argv) <= 1:
        print __test_doc__
        sys.exit(-1)

    path = sys.argv[1]
    handlePath(path, sys.stdout)


# todo: sys.stdout has mode 'w' should be 'wb'

# def test_forwardTmpl():
#    env = { 'SCRIPT_NAME' : '/admin/snoop.py' }
#    forwardTmpl(sys.stdout, env, 'tmpl/home.html', 'now')


if __name__ == "__main__":
    # must import itself; otheriwse top level script is imported as __main__
    from minds import app_httpserver

    app_httpserver.main()