/usr/share/pyshared/nevow/zomnesrv.py is in python-nevow 0.10.0-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | import warnings
warnings.warn("nevow.zomnesrv is deprecated.", category=DeprecationWarning)
import time
from nevow import wsgi
from twisted.internet import protocol
from twisted.protocols import basic
from twisted.python import log
IN_KEY = 'STDIN_FILENAME='
IN_KEY_LEN = len(IN_KEY)
class ZomneProtocol(basic.NetstringReceiver):
def connectionMade(self):
self.environ = {}
def stringReceived(self, data):
key, value = data.split('=', 1)
self.environ[key] = value
if data.startswith(IN_KEY):
filenm = data[IN_KEY_LEN:]
self.stdin = open(filenm).read()
# WSGI variables
self.environ['wsgi.version'] = (1,0)
self.environ['wsgi.multithread'] = False
self.environ['wsgi.multiprocess'] = False
if self.environ.get('HTTPS','off') in ('on','1'):
self.environ['wsgi.url_scheme'] = 'https'
else:
self.environ['wsgi.url_scheme'] = 'http'
# print "ENV", self.environ
result = self.factory.application(self.environ, self.start_response)
for data in result:
if data:
self.write(data)
## We got everything, let's render the request
self.transport.loseConnection()
self.factory.log('%s - - %s "%s" %d %s "%s" "%s"' % (
self.environ['REMOTE_ADDR'],
time.strftime("[%d/%b/%Y:%H:%M:%S +0000]", time.gmtime()),
'%s %s %s' % (
self.environ['REQUEST_METHOD'],
self.environ['REQUEST_URI'],
self.environ['SERVER_PROTOCOL']),
self.responseCode,
self.sentLength or "-",
self.environ.get('HTTP_REFERER', ''),
self.environ.get('HTTP_USER_AGENT', '')))
sentLength = 0
def write(self, what):
self.sentLength += len(what)
self.transport.write(what)
def start_response(self, status, headers, exc_info=None):
self.responseCode = int(status.split()[0])
self.transport.write("Status: %s\r\n" % (status, ))
for key, value in headers:
self.transport.write("%s: %s\r\n" % (key, value))
self.transport.write("\r\n")
return self.write
class NotificationProtocol(protocol.Protocol):
def connectionMade(self):
self.transport.loseConnection()
class NotificationFactory(protocol.ClientFactory):
protocol = NotificationProtocol
class ZomneFactory(protocol.Factory):
def __init__(self, root, logfile=None, prefixURL=None):
"""`prefixURL` is used by WSGI apps. wsgi.py stores it in appRootURL.
It is the HTTP url for the nevow.cgi script"""
if logfile is not None:
self.log = open(logfile, 'a')
if prefixURL:
self.application = wsgi.createWSGIApplication(root, prefixURL)
else:
self.application = wsgi.createWSGIApplication(root)
protocol = ZomneProtocol
def startFactory(self):
"""Tell the other end that we are done starting up.
"""
# Import reactor here to avoid installing default at startup
from twisted.internet import reactor
reactor.connectUNIX('zomne_startup_complete.socket', NotificationFactory())
def log(self, msg):
log.msg(msg)
|