Skip to main content

more.emit: pymitter integration in Morepath

This package provides Morepath integration for pymitter.

pymitter is a Python port of the extended Node.js EventEmitter 2 approach providing namespaces, wildcards and TTL.

Quick start

Install more.emit:

$ pip install -U more.emit

Extend your App class from EmitApp:

from more.pony import EmitApp

class App(EmitApp):
    pass

Now you can define signals:

from .app import App


@App.signal.on('myevent')
def handler1(arg, request):
    print(request)
    print('handler1 called with', arg)

@App.signal.on('myevent')
def handler2(arg, request):
    print('handler2 called with', arg)

You can emit the signals for example from the view:

@App.json(model=Root)
def root_view(self, request):
    request.app.signal.emit('myevent', 'foo', request)
    return {
        'name': 'Root'
    }

Example

An example for emitting signals on user creation and user update for sending a confirmation email. This example uses more.pony.

signal.py

from .app import App


@App.signal.on('user.email_updated')
def send_confirmation_email(user, request):
    mailer = request.app.service(name='mailer')
    mailer.send_confirmation_email(user, request)

view.py

@App.json(model=UserCollection, request_method='POST')
def user_collection_add(self, request):
    email = request.json['email']

    if not User.exists(email=email):
        user = self.add(email=email)

        @request.after
        def after(response):
            request.app.signal.emit('user.email_updated', user, request)
            response.status = 201

    else:
        @request.after
        def after(response):
            response.status = 409

        return {
            'validationError': 'Email already exists'
        }


@App.json(model=User, request_method='PUT')
def user_update(self, request):
    if 'email' in request.json and User.exists(email=request.json['email']):
        @request.after
        def after(response):
            response.status = 409

        return {
            'validationError': 'Email already exists'
        }

    else:
        self.update(request.json)
        if 'email' in request.json:
            self.email_confirmed = False

            @request.after
            def after(response):
                request.app.signal.emit('user.email_updated', self, request)

CHANGES

0.2 (2020-04-26)

  • Removed: Removed support for Python 2.

    You have to upgrade to Python 3 if you want to use this version.

  • Added support for Python 3.6, 3.7 and 3.8 and PyPy 3.6.

  • Make Python 3.7 the default testing environment.

  • Add integration for the Black code formatter.

0.1 (2017-04-22)

  • Initial public release.

Release files for more.emit 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for more.emit 0.2
File Size Uploaded
more.emit-0.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for more.emit 0.2
File Interpreter ABI Platform
more.emit-0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 10.0 kB

Release files / more.emit-0.2.tar.gz

Download URL more.emit-0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9b7e2920043f40c7f74ebad9a33b92a3776b87deb5ddce6dce6242a4a479f7a0
BLAKE2b-256 checksum
How to use checksums
0c9c677a479e1b23ef71e0c7faaa91428d57ce94820b057395dbfccac0337a56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Release files / more.emit-0.2-py2.py3-none-any.whl

Download URL more.emit-0.2-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
516bb67b9d698ff4f71e4b1381cef1671502390ed5a04dde8346d34eab4b8ca9
BLAKE2b-256 checksum
How to use checksums
dc8a3b181c47809f988f8d8a5bdee7a35d4b5bc4e93568c063d58c6c69a66723
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page