Added basic WSGI support, probably doesn't work

This commit is contained in:
pbsds committed 2014-01-27 21:03:02 +01:00
1 parent 1e62e84da2
commit 03bc539840
1 file changed
+25 -7
+25 -7
View File
@@ -1,6 +1,15 @@
#Settings:
useWSGI = False#not fully tested and WILL NOT support multible instances/workers
port = 8080
#import:
print "Importing modules..."
from twisted.web import server#filehost from twisted.web import server#filehost
from twisted.internet import reactor from twisted.internet import reactor
import sys, time, os if useWSGI: from twisted.application import internet, service
import sys, time, os, atexit
#Logging #Logging
class Log: class Log:
@@ -9,6 +18,8 @@ class Log:
self.files = [] self.files = []
def write(self, data): def write(self, data):
for i in self.files: i.write(data) for i in self.files: i.write(data)
def flush(self):#ipython needs this
pass
def __init__(self): def __init__(self):
minutes, seconds = map(int, time.strftime("%M %S").split(" ")) minutes, seconds = map(int, time.strftime("%M %S").split(" "))
minutes = 59 - minutes minutes = 59 - minutes
@@ -79,7 +90,7 @@ hatena.ServerLog = Log
print "Setting up hatena site structure..." print "Setting up hatena site structure..."
site = server.Site(hatena.Setup()) site = server.Site(hatena.Setup())
#make the hatena server accept proxy coneections: #make the hatena server accept proxy connections:
print "Setting up proxy hack..." print "Setting up proxy hack..."
silent = True silent = True
old_lineReceived = site.protocol.lineReceived old_lineReceived = site.protocol.lineReceived
@@ -96,8 +107,15 @@ site.protocol.lineReceived = lineReceived
#run! #run!
print "Server start!\n" print "Server start!\n"
reactor.listenTCP(8080, site)#Hey listen!~ if useWSGI:
reactor.run() application = service.Application('web')
sc = service.IServiceCollection(application)
#dunn internet.TCPServer(port, site).setServiceParent(sc)
Log.write("Server shutdown", True)
atexit.register(Log.write, String="Server shutdown", Silent=True)
else:
reactor.listenTCP(port, site)#Hey listen!~
reactor.run()
#dunn
Log.write("Server shutdown", True)