0001# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
0002# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
0003# @@: THIS IS INCOMPLETE!
0004
0005def run_twisted(wsgi_app, global_conf,
0006                host='127.0.0.1', port='8080'):
0007    host = host or None
0008    import twisted.web2.wsgi
0009    import twisted.web2.log
0010    import twisted.web2.channel
0011    import twisted.web2.server
0012    import twisted.internet.reactor
0013    wsgi_resource = twisted.web2.wsgi.WSGIResource(wsgi_app)
0014    resource = twisted.web2.log.LogWrapperResource(wsgi_resource)
0015    twisted.web2.log.DefaultCommonAccessLoggingObserver().start()
0016    site = twisted.web2.server.Site(resource)
0017    factory = twisted.web2.channel.HTTPFactory(site)
0018    # --- start reactor for listen port
0019    twisted.internet.reactor.listenTCP(int(port), factory, interface=host)
0020    twisted.internet.reactor.run()