How to use circuits - 10 common examples

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 / core / exitcodeapp.py View on Github external
#!/usr/bin/env python
import sys

from circuits import Component


class App(Component):

    def started(self, *args):
        try:
            code = int(sys.argv[1])
        except ValueError:
            code = sys.argv[1]

        raise SystemExit(code)


def main():
    App().run()


if __name__ == "__main__":
    main()
github circuits / circuits / tests / core / test_coroutine.py View on Github external
#!/usr/bin/env python
from __future__ import print_function

import pytest

from circuits import Component, Event

pytestmark = pytest.mark.skip("XXX: This test fails intermittently")


class test(Event):

    """test Event"""


class coroutine1(Event):

    """coroutine Event"""

    complete = True


class coroutine2(Event):

    """coroutine Event"""

    complete = True


class App(Component):

    returned = False
github circuits / circuits / tests / core / test_call_stop.py View on Github external
#!/usr/bin/env python

from __future__ import print_function

import pytest

from circuits import Component, Event, handler


class test(Event):
    """test Event"""

    success = True


class foo(Event):
    """foo Event"""


class App(Component):

    @handler("test", priority=1)
    def on_test(self, event):
        event.stop()
        yield

    @handler("test")
    def on_test_ignored(self):
        return "Hello World!"


@pytest.fixture
github circuits / circuits / tests / core / test_filter_order.py View on Github external
    @handler("test", filter=True)
    def on_test(self, event, *args, **kwargs):
        self.events_executed.append('test_filter')
        return True
github circuits / circuits / tests / core / test_call_wait_timeout.py View on Github external
#!/usr/bin/env python
import pytest

from circuits.core import Component, Event, TimeoutError, handler


class wait(Event):

    """wait Event"""
    success = True


class call(Event):

    """call Event"""
    success = True


class hello(Event):

    """hello Event"""
    success = True
github circuits / circuits / tests / core / test_call_wait_timeout.py View on Github external
from circuits.core import Component, Event, TimeoutError, handler


class wait(Event):

    """wait Event"""
    success = True


class call(Event):

    """call Event"""
    success = True


class hello(Event):

    """hello Event"""
    success = True


class App(Component):

    @handler('wait')
    def _on_wait(self, timeout=-1):
        result = self.fire(hello())
        try:
            yield self.wait('hello', timeout=timeout)
        except TimeoutError as e:
            yield e
        else:
            yield result
github circuits / circuits / tests / core / test_call_wait_timeout.py View on Github external
#!/usr/bin/env python
import pytest

from circuits.core import Component, Event, TimeoutError, handler


class wait(Event):

    """wait Event"""
    success = True


class call(Event):

    """call Event"""
    success = True


class hello(Event):

    """hello Event"""
    success = True


class App(Component):

    @handler('wait')
    def _on_wait(self, timeout=-1):
        result = self.fire(hello())
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