3
warnings.warn("nevow.zomnesrv is deprecated.", category=DeprecationWarning)
9
from twisted.internet import protocol
10
from twisted.protocols import basic
11
from twisted.python import log
14
IN_KEY = 'STDIN_FILENAME='
15
IN_KEY_LEN = len(IN_KEY)
18
class ZomneProtocol(basic.NetstringReceiver):
19
def connectionMade(self):
22
def stringReceived(self, data):
23
key, value = data.split('=', 1)
24
self.environ[key] = value
25
if data.startswith(IN_KEY):
26
filenm = data[IN_KEY_LEN:]
27
self.stdin = open(filenm).read()
30
self.environ['wsgi.version'] = (1,0)
31
self.environ['wsgi.multithread'] = False
32
self.environ['wsgi.multiprocess'] = False
33
if self.environ.get('HTTPS','off') in ('on','1'):
34
self.environ['wsgi.url_scheme'] = 'https'
36
self.environ['wsgi.url_scheme'] = 'http'
38
# print "ENV", self.environ
39
result = self.factory.application(self.environ, self.start_response)
43
## We got everything, let's render the request
44
self.transport.loseConnection()
46
self.factory.log('%s - - %s "%s" %d %s "%s" "%s"' % (
47
self.environ['REMOTE_ADDR'],
48
time.strftime("[%d/%b/%Y:%H:%M:%S +0000]", time.gmtime()),
50
self.environ['REQUEST_METHOD'],
51
self.environ['REQUEST_URI'],
52
self.environ['SERVER_PROTOCOL']),
54
self.sentLength or "-",
55
self.environ.get('HTTP_REFERER', ''),
56
self.environ.get('HTTP_USER_AGENT', '')))
59
def write(self, what):
60
self.sentLength += len(what)
61
self.transport.write(what)
63
def start_response(self, status, headers, exc_info=None):
64
self.responseCode = int(status.split()[0])
65
self.transport.write("Status: %s\r\n" % (status, ))
66
for key, value in headers:
67
self.transport.write("%s: %s\r\n" % (key, value))
68
self.transport.write("\r\n")
72
class NotificationProtocol(protocol.Protocol):
73
def connectionMade(self):
74
self.transport.loseConnection()
77
class NotificationFactory(protocol.ClientFactory):
78
protocol = NotificationProtocol
81
class ZomneFactory(protocol.Factory):
82
def __init__(self, root, logfile=None, prefixURL=None):
83
"""`prefixURL` is used by WSGI apps. wsgi.py stores it in appRootURL.
84
It is the HTTP url for the nevow.cgi script"""
85
if logfile is not None:
86
self.log = open(logfile, 'a')
88
self.application = wsgi.createWSGIApplication(root, prefixURL)
90
self.application = wsgi.createWSGIApplication(root)
92
protocol = ZomneProtocol
94
def startFactory(self):
95
"""Tell the other end that we are done starting up.
97
# Import reactor here to avoid installing default at startup
98
from twisted.internet import reactor
99
reactor.connectUNIX('zomne_startup_complete.socket', NotificationFactory())