def makeService(config): if config['logfile']: logObserver = log.FileAccessLoggingObserver(config['logfile']) else: logObserver = log.DefaultCommonAccessLoggingObserver() if config['root']: if config['indexes']: config['root'].indexNames = config['indexes'] root = log.LogWrapperResource(config['root']) s = Web2Service(logObserver) site = server.Site(root) chan = channel.HTTPFactory(site) if config['https']: from twisted.internet.ssl import DefaultOpenSSLContextFactory i = internet.SSLServer( int(config['https']), chan, DefaultOpenSSLContextFactory(config['privkey'], config['certificate'])) i.setServiceParent(s) strports.service(config['port'], chan).setServiceParent(s) return s
def XMLRPCServerFactoryFromTaskController(taskController): """Adapt a TaskController to a XMLRPCServerFactory.""" s = server.Site(IXMLRPCTaskController(taskController)) return channel.HTTPFactory(s, betweenRequestsTimeOut=BETWEEN_REQUESTS_TIMEOUT)
def HTTPServerFactoryFromTaskController(multiengine): """Adapt an ITaskController to a HTTPServerFactory.""" s = server.Site(IHTTPTaskRoot(multiengine)) return channel.HTTPFactory(s)
def HTTPServerFactoryFromMultiEngine(multiengine): """Adapt an IMultiEngine to a HTTPServerFactory.""" s = server.Site(IHTTPMultiEngineRoot(multiengine)) return channel.HTTPFactory(s)
def HTTPServerFactoryFromNotebookController(nbc): """Adapt an INotebookController to a HTTPServerFactory.""" s = server.Site(IHTTPNotebookServer(nbc)) return channel.HTTPFactory(s)
def XMLRPCServerFactoryFromMultiEngine(multiengine): """Adapt a MultiEngine to a XMLRPCServerFactory.""" s = server.Site(IXMLRPCMultiEngine(multiengine)) cf = channel.HTTPFactory(s, betweenRequestsTimeOut=BETWEEN_REQUESTS_TIMEOUT) return cf
# files (this defaults to ['/etc/mime.types']). for location in mimetype_locations: if os.path.exists(location): contentTypes.update(mimetypes.read_mime_types(location)) return contentTypes def getTypeAndEncoding(filename, types, encodings, defaultType): p, ext = os.path.splitext(filename) ext = ext.lower() if encodings.has_key(ext): enc = encodings[ext] ext = os.path.splitext(p)[1].lower() else: enc = None type = types.get(ext, defaultType) return type, enc ## # Test code ## if __name__ == '__builtin__': # Running from twistd -y from twisted.application import service, strports from ipython1.external.twisted.web2 import server res = File('/') application = service.Application("demo") s = strports.service('8080', server.Site(res)) s.setServiceParent(application)