How to use dispatch - 10 common examples

To help you get started, we’ve selected a few dispatch 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 olivierverdier / dispatch / tests / test_dispatcher.py View on Github external
def receiver_1_arg(val, **kwargs):
    return val

class Callable(object):
    def __call__(self, val, **kwargs):
        return val
    
    def a(self, val, **kwargs):
        return val

class Sender(object):
    signal = Signal(providing_args=["val"])
    def send(self):
        self.signal.send(sender=self, val="test")

a_signal = Signal(providing_args=["val"])

class DispatcherTests(unittest.TestCase):
    """Test suite for dispatcher (barely started)"""

    def _testIsClean(self, signal):
        """Assert that everything has been cleaned up automatically"""
        self.assertEqual(signal.receivers, [])

        # force cleanup just in case
        signal.receivers = []
    
    def testExact(self):
        a_signal.connect(receiver_1_arg, sender=self)
        expected = [(receiver_1_arg,"test")]
        result = a_signal.send(sender=self, val="test")
        self.assertEqual(result, expected)
github olivierverdier / dispatch / tests / test_dispatcher.py View on Github external
else:
    def garbage_collect():
        gc.collect()

def receiver_1_arg(val, **kwargs):
    return val

class Callable(object):
    def __call__(self, val, **kwargs):
        return val
    
    def a(self, val, **kwargs):
        return val

class Sender(object):
    signal = Signal(providing_args=["val"])
    def send(self):
        self.signal.send(sender=self, val="test")

a_signal = Signal(providing_args=["val"])

class DispatcherTests(unittest.TestCase):
    """Test suite for dispatcher (barely started)"""

    def _testIsClean(self, signal):
        """Assert that everything has been cleaned up automatically"""
        self.assertEqual(signal.receivers, [])

        # force cleanup just in case
        signal.receivers = []
    
    def testExact(self):
github ubyssey / dispatch / apps / api / tests.py View on Github external
def test_delete_person(self):
        """
        Ensure we can delete a person.
        """
        id = self.person.id
        url = reverse('people-detail', args=(id,))
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        try:
            Person.objects.get(pk=id)
            self.fail()
        except:
            pass
github ubyssey / dispatch / dispatch / modules / auth / tests.py View on Github external
def test_user_str(self):
        self.assertEquals(self.u1.__str__(), self.EMAIL)
        p1 = Person(full_name="John Doe")
        p1.save()
        self.u1.person = p1
        self.u1.save()
        self.assertEquals(self.u1.__str__(), "John Doe")
github ubyssey / dispatch / apps / api / tests.py View on Github external
def setUp(self):
        self.user = User.objects.create(email='peterjsiemens@gmail.com')
        self.person = Person.objects.create(full_name="Jane Doe")
        self.client.force_authenticate(self.user)
github appcelerator-archive / webkit_titanium_legacy / WebKitTools / Scripts / webkitpy / thirdparty / pywebsocket / mod_pywebsocket / standalone.py View on Github external
if options.use_tls:
        if not _HAS_OPEN_SSL:
            logging.critical('To use TLS, install pyOpenSSL.')
            sys.exit(1)
        if not options.private_key or not options.certificate:
            logging.critical(
                    'To use TLS, specify private_key and certificate.')
            sys.exit(1)

    if not options.scan_dir:
        options.scan_dir = options.websock_handlers

    try:
        # Share a Dispatcher among request handlers to save time for
        # instantiation.  Dispatcher can be shared because it is thread-safe.
        options.dispatcher = dispatch.Dispatcher(options.websock_handlers,
                                                 options.scan_dir)
        if options.websock_handlers_map_file:
            _alias_handlers(options.dispatcher,
                            options.websock_handlers_map_file)
        _print_warnings_if_any(options.dispatcher)

        WebSocketRequestHandler.options = options
        WebSocketServer.options = options

        server = WebSocketServer((options.server_host, options.port),
                                 WebSocketRequestHandler)
        server.serve_forever()
    except Exception, e:
        logging.critical(str(e))
        sys.exit(1)
github CyanogenMod / android_external_webkit / WebKitTools / pywebsocket / mod_pywebsocket / standalone.py View on Github external
if options.use_tls:
        if not _HAS_OPEN_SSL:
            logging.critical('To use TLS, install pyOpenSSL.')
            sys.exit(1)
        if not options.private_key or not options.certificate:
            logging.critical(
                    'To use TLS, specify private_key and certificate.')
            sys.exit(1)

    if not options.scan_dir:
        options.scan_dir = options.websock_handlers

    try:
        # Share a Dispatcher among request handlers to save time for
        # instantiation.  Dispatcher can be shared because it is thread-safe.
        options.dispatcher = dispatch.Dispatcher(options.websock_handlers,
                                                 options.scan_dir)
        _print_warnings_if_any(options.dispatcher)

        WebSocketRequestHandler.options = options
        WebSocketServer.options = options

        server = WebSocketServer(('', options.port), WebSocketRequestHandler)
        server.serve_forever()
    except Exception, e:
        logging.critical(str(e))
        sys.exit(1)
github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save_article(self, data):

        slug = data['url'].rsplit('/',2)[1]

        try:
            Article.objects.filter(slug=slug).delete()
        except:
            pass

        try:
            author = Person.objects.get(full_name=data['author'])
        except:
            author = Person.objects.create(full_name=data['author'])

        article = Article()

        title = str(BeautifulSoup(data['title'], 'html.parser'))
        article.headline = title

        article.slug = slug
        article.snippet = data['description']
        article.seo_keyword = data['keyword']
github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save_article(self, data):

        slug = data['url'].rsplit('/',2)[1]

        try:
            Article.objects.filter(slug=slug).delete()
        except:
            pass

        try:
            author = Person.objects.get(full_name=data['author'])
        except:
            author = Person.objects.create(full_name=data['author'])

        article = Article()

        title = str(BeautifulSoup(data['title'], 'html.parser'))
        article.headline = title

        article.slug = slug
        article.snippet = data['description']
        article.seo_keyword = data['keyword']
        article.seo_description = data['description']

        date = dateutil.parser.parse(data['date'])

        article.status = Article.DRAFT
        article.is_published = True
        article.published_at = date

        try:
github ubyssey / dispatch / dispatch / apps / manager / views.py View on Github external
@staff_member_required
def user_edit(request, id):

    p = Person.objects.get(pk=id)

    if request.method == 'POST':
        form = PersonForm(request.POST, request.FILES, instance=p)
        if form.is_valid():
            form.save()
            return redirect(users)
    else:
        form = PersonForm(instance=p)

    context = {
        'title': 'Edit User',
        'person': p,
        'form': form,