File: twisted_web2_server.py

package info (click to toggle)
pastescript 3.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: python: 5,212; sh: 65; makefile: 61
file content (20 lines) | stat: -rw-r--r-- 905 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
# @@: THIS IS INCOMPLETE!

def run_twisted(wsgi_app, global_conf,
                host='127.0.0.1', port='8080'):
    host = host or None
    import twisted.web2.wsgi
    import twisted.web2.log
    import twisted.web2.channel
    import twisted.web2.server
    import twisted.internet.reactor
    wsgi_resource = twisted.web2.wsgi.WSGIResource(wsgi_app)
    resource = twisted.web2.log.LogWrapperResource(wsgi_resource)
    twisted.web2.log.DefaultCommonAccessLoggingObserver().start()
    site = twisted.web2.server.Site(resource)
    factory = twisted.web2.channel.HTTPFactory(site)
    # --- start reactor for listen port
    twisted.internet.reactor.listenTCP(int(port), factory, interface=host)
    twisted.internet.reactor.run()