def main(argv): from twisted.python import log from twisted.web.server import Site from twisted.web.static import File from twisted.internet import reactor from twisted.python import log observer = log.PythonLoggingObserver('twisted') log.startLoggingWithObserver(observer.emit, setStdout=False) static_dir = os.path.abspath('.') logging.info("registering static folder %r on /" % static_dir) root = File(static_dir) wr = TwistedWebResource(soap11_application) logging.info("registering %r on /%s" % (wr, url)) root.putChild(url, wr) site = Site(root) if port[0] == 0: port[0] = get_open_port() reactor.listenTCP(port[0], site) logging.info("listening on: %s:%d" % (host,port)) return reactor.run()
def main(argv): # logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s: %(message)s') logging.getLogger('server').setLevel(logging.INFO) # command-line arguments hostname = '127.0.0.1' port = 7788 try: opts, args = getopt.getopt(argv, "hH:P:", ["host=", "port="]) except getopt.GetoptError: print './server.py -H <hostname> -P <port>' sys.exit(2) for opt, arg in opts: if opt == '-h': print './server.py -H <hostname> -P <port>' sys.exit() elif opt in ("-H", "--host"): hostname = arg elif opt in ("-P", "--port"): if isinstance(arg, str): port = int(arg) elif isinstance(arg, int): port = arg else: port = arg # Initialize the application observer = log.PythonLoggingObserver('twisted') log.startLoggingWithObserver(observer.emit, setStdout=False) application = Application([Replica], 'spyne.datastore.replica', in_protocol=Soap11(), out_protocol=Soap11()) #wsgi_app = WsgiApplication(application) # Register the WSGI application as handler to wsgi server & run http server #resource = WSGIResource(reactor, reactor, wsgi_app) resource = TwistedWebResource(application) site = Site(resource) reactor.listenTCP(port, site, interface=hostname) logging.info('listening on: %s:%d' % (hostname, port)) logging.info('wsdl is at: http://%s:%d/?wsdl' % (hostname, port)) sys.exit(reactor.run())
def main(argv): from twisted.web.server import Site from twisted.internet import reactor from twisted.python import log observer = log.PythonLoggingObserver('twisted') log.startLoggingWithObserver(observer.emit, setStdout=False) wr = TwistedWebResource(httprpc_soap_application) site = Site(wr) reactor.listenTCP(port, site) logging.info("listening on: %s:%d" % (host, port)) return reactor.run()
def gen_resource(self): from spyne.server.twisted import TwistedWebResource from spyne.server.wsgi import WsgiApplication from spyne.util.wsgi_wrapper import WsgiMounter from twisted.internet import reactor from twisted.web.resource import Resource from twisted.web.wsgi import WSGIResource if isinstance(self.app, Resource): return self.app elif isinstance(self.app, Application): return TwistedWebResource(self.app) elif isinstance(self.app, (WsgiApplication, WsgiMounter)): return WSGIResource(reactor, reactor.getThreadPool(), self.app) raise ValueError(self.app)
def add_device(self, device): self.devices.append(device) device.parent = self if self.started: device.location = "http://%s:" + str(self.getPort()) device.icons = [ DeviceIcon( 'image/png', 32, 32, 24, device.getLocation(get_default_v4_address()) + '/pictures/icon.png') ] for service in device.services: service.control_resource = TwistedWebResource(service.app) service.event_resource = ServiceEventResource(service) service.resource = ServiceResource(service) self.upnp.addDevice(device)
def __init__(self, device): ''' Initialization of UPnP server ''' self.upnp = UPnP(device) self.devices = [device] device.parent = self self.upnp.parent = self self.site = server.Site(self.upnp) edp = endpoints.serverFromString(reactor, "tcp:0") StreamServerEndpointService.__init__(self, edp, self.site) self._choosenPort = None for service in device.services: service.control_resource = TwistedWebResource(service.app) service.event_resource = ServiceEventResource(service) service.resource = ServiceResource(service)
"""Sends multiple hello messages by waiting given number of seconds inbetween.""" times = [times] # Workaround for Python 2.7's lacking of nonlocal def _cb(response): if times[0] > 0: response.append( "Hello %s, sleeping for %d seconds for %d more time(s)." % (name, seconds, times[0])) times[0] -= 1 return deferLater(reactor, seconds, _cb, response) else: response.close() return Iterable.Push(_cb) if __name__ == '__main__': application = initialize([SomeService, SomeNonBlockingService]) resource = TwistedWebResource(application) site = Site(resource) reactor.listenTCP(port, site, interface=host) logging.info("listening on: %s:%d" % (host, port)) logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port)) sys.exit(reactor.run())
tns=SwitchPower.tns, in_protocol=Soap11(validator='lxml'), out_protocol=Soap11()) self.app.event_manager.add_listener('method_call', _map_context) class UserDefinedContext(object): def __init__(self, client): self.client = client if __name__ == '__main__': import sys from twisted.python import log from twisted.internet import reactor from spyne.server.twisted import TwistedWebResource from twisted.web.server import Site from onDemand.plugins import he # logging.basicConfig(level=logging.DEBUG) # logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG) log.startLogging(sys.stdout) client = he.HE_factory('16234266', 0) edp = he.HE_endpoint(reactor, 1, 0x04, 0) edp.connect(client) app = BinaryLight(client) resource = TwistedWebResource(app.app) site = Site(resource) reactor.listenTCP(8000, site, interface='0.0.0.0') # @UndefinedVariable reactor.run() # @UndefinedVariable