How to use the circuits.web.Controller 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_http.py View on Github external
def __init__(self, *args, **kwargs):
        super(Client, self).__init__(*args, **kwargs)
        self._buffer = []
        self.done = False

    def read(self, data):
        self._buffer.append(data)
        if data.find(b"\r\n") != -1:
            self.done = True

    def buffer(self):
        return b''.join(self._buffer)


class Root(Controller):

    def index(self):
        return "Hello World!"


def test(webapp):
    transport = TCPClient()
    client = Client()
    client += transport
    client.start()

    host, port, resource, secure = parse_url(webapp.server.http.base)
    client.fire(connect(host, port))
    assert pytest.wait_for(transport, "connected")

    client.fire(write(b"GET / HTTP/1.1\r\n"))
github circuits / circuits / tests / web / test_dispatcher3.py View on Github external
#!/usr/bin/env python
import pytest

from circuits.web import Controller

try:
    from httplib import HTTPConnection
except ImportError:
    from http.client import HTTPConnection  # NOQA


class Root(Controller):

    def GET(self):
        return "GET"

    def PUT(self):
        return "PUT"

    def POST(self):
        return "POST"

    def DELETE(self):
        return "DELETE"


@pytest.mark.parametrize(("method"), ["GET", "PUT", "POST", "DELETE"])
def test(webapp, method):
github circuits / circuits / tests / web / test_client.py View on Github external
#!/usr/bin/env python
from circuits.web import Controller
from circuits.web.client import Client, request


class Root(Controller):

    def index(self):
        return "Hello World!"


def test(webapp):
    client = Client()
    client.start()

    client.fire(request("GET", webapp.server.http.base))
    while client.response is None:
        pass

    client.stop()

    response = client.response
github circuits / circuits / tests / web / test_null_response.py View on Github external
from circuits.web import Controller

from .helpers import HTTPError, urlopen


class Root(Controller):

    def index(self):
        pass


def test(webapp):
    try:
        urlopen(webapp.server.http.base)
    except HTTPError as e:
        assert e.code == 404
        assert e.msg == "Not Found"
    else:
        assert False
github circuits / circuits / tests / web / test_servers.py View on Github external
def tmpfile(request):
    tmpdir = tempfile.mkdtemp()
    filename = os.path.join(tmpdir, "test.sock")

    return filename


class BaseRoot(Component):

    channel = "web"

    def request(self, request, response):
        return "Hello World!"


class Root(Controller):

    def index(self):
        return "Hello World!"


class MakeQuiet(Component):

    channel = "web"

    def ready(self, event, *args):
        event.stop()


def test_baseserver(manager, watcher):
    server = BaseServer(0).register(manager)
    MakeQuiet().register(server)
github circuits / circuits / tests / web / test_methods.py View on Github external
#!/usr/bin/env python
try:
    from httplib import HTTPConnection
except ImportError:
    from http.client import HTTPConnection  # NOQA

from circuits.web import Controller


class Root(Controller):

    def index(self):
        return "Hello World!"


def test_GET(webapp):
    connection = HTTPConnection(webapp.server.host, webapp.server.port)

    connection.request("GET", "/")
    response = connection.getresponse()
    assert response.status == 200
    assert response.reason == "OK"
    s = response.read()
    assert s == b"Hello World!"
github realXtend / tundra / src / Application / PythonScriptModule / pymodules_old / circuits / web / main.py View on Github external
opts, args = parser.parse_args()

    return opts, args

###
### Components
###

class HelloWorld(Component):

    channel = "web"

    def request(self, request, response):
        return "Hello World!"

class Root(Controller):

    def index(self):
        return "Hello World!"

###
### Main
###

def main():
    opts, args = parse_options()

    if opts.jit and psyco:
        psyco.full()

    if ":" in opts.bind:
        address, port = opts.bind.split(":")
github circuits / circuits / examples / web / virtualhosts.py View on Github external
class Root(Controller):

    def index(self):
        return "I am the main vhost"


class Foo(Controller):

    channel = "/foo"

    def index(self):
        return "I am foo."


class Bar(Controller):

    channel = "/bar"

    def index(self):
        return "I am bar."


domains = {
    "foo.localdomain:8000": "foo",
    "bar.localdomain:8000": "bar",
}


app = Server(("0.0.0.0", 8000))
VirtualHosts(domains).register(app)
Root().register(app)
github circuits / circuits / examples / web / httpauth.py View on Github external
#!/usr/bin/env python
from circuits.web import Controller, Server
from circuits.web.tools import basic_auth, check_auth


class Root(Controller):

    def index(self):
        realm = "Test"
        users = {"admin": "admin"}
        encrypt = str

        if check_auth(self.request, self.response, realm, users, encrypt):
            return "Hello %s" % self.request.login

        return basic_auth(self.request, self.response, realm, users, encrypt)


app = Server(("0.0.0.0", 8000))
Root().register(app)
app.run()
github circuits / circuits / tmp / comet.py View on Github external
def read(self, data):
        if self._state == BUFFERING:
            if self._buffer is None:
                self._buffer = StringIO()
            self._buffer.write(data)
        elif self._state == STREAMING:
            if self._buffer is not None:
                self._buffer.write(data)
                self._buffer.flush()
                data = self._buffer.getvalue()
                self._buffer = None
                self.push(Stream(self._response, data), target="http")
            else:
                self.push(Stream(self._response, data), target="http")

class Comet(Controller):

    def index(self):
        return "Hello World!"

    def ping(self, host):
        self.response.headers["Content-Type"] = "text/plain"
        self.response.stream = True
        sid = self.request.sid
        command = "ping %s" % host
        self += Command(self.request, self.response, command, channel=sid)
        return self.response

app = (Server(8000) + Sessions() + Logger() + Comet())
app.run()