web.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:driveboardapp 作者: nortd 项目源码 文件源码
def start(browser=False, debug=False):
    """ Start a bottle web server.
        Derived from WSGIRefServer.run()
        to have control over the main loop.
    """
    global DEBUG
    DEBUG = debug

    class FixedHandler(wsgiref.simple_server.WSGIRequestHandler):
        def address_string(self): # Prevent reverse DNS lookups please.
            return self.client_address[0]
        def log_request(*args, **kw):
            if debug:
                return wsgiref.simple_server.WSGIRequestHandler.log_request(*args, **kw)

    S.server = wsgiref.simple_server.make_server(
        conf['network_host'],
        conf['network_port'],
        bottle.default_app(),
        wsgiref.simple_server.WSGIServer,
        FixedHandler
    )
    S.server.timeout = 0.01
    S.server.quiet = not debug
    if debug:
        bottle.debug(True)
    print "Internal storage root is: " + conf['rootdir']
    print "Persistent storage root is: " + conf['stordir']
    print "-----------------------------------------------------------------------------"
    print "Starting server at http://%s:%d/" % ('127.0.0.1', conf['network_port'])
    print "-----------------------------------------------------------------------------"
    driveboard.connect_withfind()
    # open web-browser
    if browser:
        try:
            webbrowser.open_new_tab('http://127.0.0.1:'+str(conf['network_port']))
        except webbrowser.Error:
            print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    # start server
    print "INFO: Starting web server thread."
    S.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号