def test_disps(): manager = Manager() server1 = BaseServer(0, channel="site1") server1.register(manager) PrefixingDispatcher(channel="site1").register(server1) Dispatcher(channel="site1").register(server1) Root1().register(manager) server2 = BaseServer(("localhost", 0), channel="site2") server2.register(manager) PrefixingDispatcher(channel="site2").register(server2) Dispatcher(channel="site2").register(server2) Root2().register(manager) DummyRoot().register(manager) manager.start() f = urlopen(server1.http.base, timeout=3) s = f.read() assert s == b"Hello from site 1!" f = urlopen(server2.http.base, timeout=3) s = f.read() assert s == b"Hello from site 2!"
def main(): opts, args = parse_options() bind = parse_bind(opts.bind) if opts.validate: application = (Application() + Root()) app = validator(application) httpd = make_server(bind[0], bind[1], app) httpd.serve_forever() raise SystemExit(0) manager = Manager() opts.debug and Debugger().register(manager) Poller = select_poller(opts.poller.lower()) Poller().register(manager) if opts.server.lower() == "base": BaseServer(bind).register(manager) HelloWorld().register(manager) else: Server(bind).register(manager) Root().register(manager) docroot = os.getcwd() if not args else args[0] Static(docroot=docroot, dirlisting=True).register(manager) opts.passwd and Authentication(passwd=opts.passwd).register(manager) opts.logging and Logger().register(manager) if opts.profile and hotshot: profiler = hotshot.Profile(".profile") profiler.start() if opts.debug: print(graph(manager, name="circuits.web")) print() print(inspect(manager)) for i in range(opts.jobs): manager.start(process=True) manager.run() if opts.profile and hotshot: profiler.stop() profiler.close() stats = hotshot.stats.load(".profile") stats.strip_dirs() stats.sort_stats("time", "calls") stats.print_stats(20)
def __init__(self): Manager.__init__(self) self += GtkDriver() self += Debugger() self.server = BaseServer(9999) self.server += wsgi.Gateway(dummy_app) self += self.server
def test_baseserver(manager, watcher): server = BaseServer(0).register(manager) MakeQuiet().register(server) watcher.wait("ready") BaseRoot().register(server) watcher.wait("registered") try: f = urlopen(server.http.base) except URLError as e: if isinstance(e.reason, gaierror): f = urlopen("http://127.0.0.1:9000") else: raise s = f.read() assert s == b"Hello World!" server.unregister() watcher.wait("unregistered")
def test_disps(manager, watcher): server1 = BaseServer(0, channel="site1").register(manager) PrefixingDispatcher(channel="site1").register(manager) Dispatcher(channel="site1").register(manager) Root1().register(manager) assert watcher.wait("ready", channel=server1.channel) server2 = BaseServer(("localhost", 0), channel="site2").register(manager) PrefixingDispatcher(channel="site2").register(manager) Dispatcher(channel="site2").register(manager) Root2().register(manager) assert watcher.wait("ready", channel=server2.channel) DummyRoot().register(manager) f = urlopen(server1.http.base, timeout=3) s = f.read() assert s == b"Hello from site 1!" f = urlopen(server2.http.base, timeout=3) s = f.read() assert s == b"Hello from site 2!"
class CircuitsWebAdapter(AdapterInterface): """ circuits.web WSGI server adapter. """ def setup(self, server_name, host, port, app_callback): from circuits.web import BaseServer from circuits.lib.web.wsgi import Gateway self._server = BaseServer(port, host) self._server += Gateway(app_callback) def start(self): self._server.start() def stop(self): self._server.stop() @classmethod def is_available(cls): try: from circuits.web import BaseServer from circuits.lib.web.wsgi import Gateway return True except ImportError: return False
def setup(self, server_name, host, port, app_callback): from circuits.web import BaseServer from circuits.lib.web.wsgi import Gateway self._server = BaseServer(port, host) self._server += Gateway(app_callback)
#!/usr/bin/env python from circuits import Component from circuits.web import BaseServer class Root(Component): def request(self, request, response): """Request Handler Using ``BaseServer`` provides no URL dispatching of any kind. Requests are handled by any event handler listening to ``Request`` events and must accept a (request, response) as arguments. """ return "Hello World!" app = BaseServer(("0.0.0.0", 8000)) Root().register(app) app.run()
def main(): opts, args = parse_options() if opts.jit and psyco: psyco.full() if ":" in opts.bind: address, port = opts.bind.split(":") port = int(port) else: address, port = opts.bind, 8000 bind = (address, port) if opts.validate: application = (wsgi.Application() + Root()) app = validator(application) httpd = make_server(address, port, app) httpd.serve_forever() raise SystemExit, 0 manager = Manager() if opts.debug: manager += Debugger() poller = opts.type.lower() if poller == "poll": Poller = Poll elif poller == "epoll": if EPoll is None: print "No epoll support available - defaulting to Select..." Poller = Select else: Poller = EPoll else: Poller = Select if opts.server.lower() == "base": manager += (BaseServer(bind, poller=Poller) + HelloWorld()) else: manager += (Server(bind, poller=Poller) + Root()) if opts.profile: if hotshot: profiler = hotshot.Profile(".profile") profiler.start() if opts.debug: print graph(manager, name="circuits.web") print print inspect(manager) if opts.mp: from circuits.core.workers import cpus for i in xrange(cpus() - 1): manager.start(process=True) manager.run() if opts.profile and hotshot: profiler.stop() profiler.close() stats = hotshot.stats.load(".profile") stats.strip_dirs() stats.sort_stats("time", "calls") stats.print_stats(20)