txMysql / txmysql / server.py

#-*- test-case-name: txmysql.test.test_server -*-
"""
Defines the Txmysql Server

"""
from twisted.application import internet, service
from twisted.internet import defer, reactor
from twisted.python import log
from twisted.web import server

from txmysql.web import root


class TxmysqlServer(service.MultiService):
    def __init__(self, port):
        service.MultiService.__init__(self)
        webServerFactory = server.Site(root.Root())
        webServer = internet.TCPServer(port, webServerFactory)
        webServer.setName("Txmysql")
        webServer.setServiceParent(self)

    def _cbStarted(self, result):
        service.MultiService.startService(self)        
        return result

    def _ebError(self, failure):
        log.err("failure starting service:", failure)
        return failure

    def startupHook(self, deferred):
        """Include additional startup steps here

        """
        deferred.callback(True)

    def startService(self):
        d = defer.Deferred()
        d.addCallback(self._cbStarted)
        d.addErrback(self._ebError)
        reactor.callWhenRunning(self.startupHook, d)
        return d

    def stopService(self):
        log.msg("Shutting down service:")
        return service.MultiService.stopService(self)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.