| 1 | # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) | 
|---|
| 2 | # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | 
|---|
| 3 | # @@: THIS IS INCOMPLETE! | 
|---|
| 4 |  | 
|---|
| 5 | def run_twisted(wsgi_app, global_conf, | 
|---|
| 6 | host='127.0.0.1', port='8080'): | 
|---|
| 7 | host = host or None | 
|---|
| 8 | import twisted.web2.wsgi | 
|---|
| 9 | import twisted.web2.log | 
|---|
| 10 | import twisted.web2.channel | 
|---|
| 11 | import twisted.web2.server | 
|---|
| 12 | import twisted.internet.reactor | 
|---|
| 13 | wsgi_resource = twisted.web2.wsgi.WSGIResource(wsgi_app) | 
|---|
| 14 | resource = twisted.web2.log.LogWrapperResource(wsgi_resource) | 
|---|
| 15 | twisted.web2.log.DefaultCommonAccessLoggingObserver().start() | 
|---|
| 16 | site = twisted.web2.server.Site(resource) | 
|---|
| 17 | factory = twisted.web2.channel.HTTPFactory(site) | 
|---|
| 18 | # --- start reactor for listen port | 
|---|
| 19 | twisted.internet.reactor.listenTCP(int(port), factory, interface=host) | 
|---|
| 20 | twisted.internet.reactor.run() | 
|---|