This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Cask is Injector-enabled, Python application microframework modelled after Flask.

It’s purpose is to make the amount of boilerplate you need to write when developing your application smaller. Here’s a simple example:

>>> from cask import Cask
>>> from injector import inject
>>>
>>> def configure(binder):
...     binder.bind(str, to='ABC')
...
>>> @Cask.run_main(modules=[configure])
... @inject(s=str)
... def main(s):
...     print(s)
...
ABC

Cask.run_main (it works both as class and instance method, see below) does the if __name__ == '__main__' check for you. So this

>>> app = Cask()
>>> @app.run_main
... def main():
...     print(111)
...
111

is shorter version of

>>> app = Cask()
>>> @app.main
... def main():
...     print(222)
...
>>> if __name__ == '__main__':
...     app.run()
...
222

Construction

Cask constructor and Cask.run_main class method accept the following optional keyword arguments:

  • modules - iterable of Injector modules, defaults to empty sequence
  • injector- instance of Injector to configure and use, by default new instance will be created for you

Hooks

Cask instance provides the following decorators allowing you to register hooks (note that you can inject into registered functions):

  • Cask.before_main - should expect no parameters, if non-None value is returned application execution main function won’t be executed

  • Cask.after_main - should expect single result parameter and return processed result (modified or not)

  • Cask.exception_handler(ExceptionCLass) - will handle exception raised during the application execution, should expect single argument called e and containing exception value:

    >>> app = Cask()
    >>> @app.exception_handler(Exception)
    ... def handle(e):
    ...     print('got exception %s' % (e,))
    ...
    >>> @app.run_main
    ... def main():
    ...     raise Exception(123)
    ...
    got exception 123
    
  • Cask.main - main function should expect no arguments and may return something

You can, of course, register more than one callable for hooks other than main.

Note

Only first matching exception_handler hook will be called, if any.

Execution

This is what happens when you run Cask-based application:

  1. Injector is configured using provided modules
  2. before_main hooks are called
  3. If before_main hooks didn’t return value different than None, main hook is executed
  4. after_main hooks are called
Release History

Release History

0.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cask-0.1.1.tar.gz (3.6 kB) Copy SHA256 Checksum SHA256 Source Aug 21, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting