How to use the circuits.web.Server function in circuits

To help you get started, we’ve selected a few circuits examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circuits / circuits / tests / web / test_wsgi_gateway_multiple_apps.py View on Github external
def test(apps):
    server = Server(0)
    Gateway(apps).register(server)

    waiter = pytest.WaitEvent(server, "ready")
    server.start()
    waiter.wait()

    f = urlopen(server.http.base)
    s = f.read()
    assert s == b"Hello World!"

    f = urlopen("{0:s}/foobar/".format(server.http.base))
    s = f.read()
    assert s == b"FooBar!"

    server.stop()
github prologic / sahriswiki / sahriswiki / main.py View on Github external
environ = Environment(config)

    SignalHandler(environ).register(environ)

    manager += environ

    if config.get("sock") is not None:
        bind = config.get("sock")
    elif ":" in config.get("bind"):
        address, port = config.get("bind").split(":")
        bind = (address, int(port),)
    else:
        bind = (config.get("bind"), config.get("port"),)

    server = (
        Server(bind)
        + Sessions()
        + Root(environ)
        + CacheControl(environ)
        + ErrorHandler(environ)
    )

    if MemoryMonitor is not None:
        MemoryMonitor(channel="/memory").register(server)

    if not config.get("disable-logging"):
        server += Logger(file=config.get("accesslog", sys.stdout))

    if not config.get("disable-static"):
        server += Static(docroot=os.path.join(config.get("theme"), "htdocs"))

    if not config.get("disable-hgweb"):
github circuits / circuits / circuits / web / main.py View on Github external
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"))
github circuits / circuits / examples / web / crud.py View on Github external
return "GET({0:s}, {1:s})".format(repr(args), repr(kwargs))

    def POST(self, *args, **kwargs):
        return "POST({0:s}, {1:s})".format(repr(args), repr(kwargs))

    def PUT(self, *args, **kwargs):
        return "PUT({0:s}, {1:s})".format(repr(args), repr(kwargs))

    def DELETE(self, *args, **kwargs):
        return "DELETE({0:s}, {1:s})".format(repr(args), repr(kwargs))

    def HEAD(self, *args, **kwargs):
        return "HEAD({0:s}, {1:s})".format(repr(args), repr(kwargs))


app = Server(("0.0.0.0", 8000))
Logger().register(app)
Root().register(app)
app.run()
github prologic / sahriswiki / sahris.py View on Github external
if EPoll is None:
            warnings.warn("No epoll support available.")
            Poller = Select
        else:
            Poller = EPoll
    else:
        Poller = Select

    storage = WikiStorage(opts.data, opts.encoding)
    search = WikiSearch(opts.cache, storage)

    environ = Environment(opts, storage, search)

    manager += environ

    manager += (Poller() + Server(bind) + CacheControl(environ) + Logger()
            + Root(environ)
            + Tools(environ)
            + PluginManager(environ)
            + Static(docroot="static")
            + Gateway(hgweb(storage.repo_path), "/+hg"))

    if opts.daemon:
        manager += Daemon(opts.pidfile)

    manager.run()
github circuits / circuits / examples / web / sessions.py View on Github external
#!/usr/bin/env python
from circuits.web import Controller, Server, Sessions


class Root(Controller):

    def index(self, name="World"):
        if "name" in self.session:
            name = self.session["name"]
        self.session["name"] = name
        return "Hello %s!" % name


app = Server(("0.0.0.0", 8000))
Sessions().register(app)
Root().register(app)
app.run()
github circuits / circuits / examples / web / basecontrollers.py View on Github external
class Root(BaseController):

    @expose("index")
    def index(self):
        """Index Request Handler

        BaseController(s) do not expose methods as request handlers.
        Request Handlers _must_ be exposed explicitly using the ``@expose``
        decorator.
        """

        return "Hello World!"


app = Server(("0.0.0.0", 8000))
Root().register(app)
app.run()
github henkelis / sonospy / sonospy / brisa / core / webserver.py View on Github external
def setup(self, server_name, host, port, app_callback):
        from circuits.web import BaseServer, Server
#        from circuits.lib.web.wsgi import Gateway
        from circuits.web.wsgi import Gateway
        from circuits.web import Controller
#        self._server = BaseServer(port, host)
#        self._server = Server(port, host)
        self._server = Server((host,port))
        self._server += Gateway(app_callback)
        self._server += self.Root()
github circuits / circuits / examples / web / shadowauth.py View on Github external
request.login = username
                return

        response.headers["WWW-Authenticate"] = _httpauth.basicAuth(self.realm)

        event.stop()
        return Unauthorized(request, response)


class Root(Controller):

    def index(self):
        return "Hello, {0:s}".format(self.request.login)


app = Server(("0.0.0.0", 8000))
PasswdAuth().register(app)
Root().register(app)
app.run()