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
FQN Decorators
==============

.. image:: https://secure.travis-ci.org/kpn-digital/py-fqn-decorators.svg?branch=master
:target: http://travis-ci.org/kpn-digital/py-fqn-decorators?branch=master

.. image:: https://img.shields.io/codecov/c/github/kpn-digital/py-fqn-decorators/master.svg
:target: http://codecov.io/github/kpn-digital/py-fqn-decorators?branch=master

.. image:: https://img.shields.io/pypi/v/fqn-decorators.svg
:target: https://pypi.python.org/pypi/fqn-decorators

.. image:: https://readthedocs.org/projects/fqn-decorators/badge/?version=latest
:target: http://fqn-decorators.readthedocs.org/en/latest/?badge=latest


Installation
------------
.. start_installation

At the command line::

$ pip install fqn-decorators


.. end_installation

Usage
-----
.. start_usage
.. py:currentmodule:: fqn_decorators.decorators

Introduction
------------

By extending the :class:`~Decorator` class you can create simple decorators.
Implement the :meth:`~Decorator.before` and/or :meth:`~Decorator.after` methods to perform actions before or after execution of the decorated item.
The :meth:`~Decorator.before` method can access the arguments of the decorated item by changing the :attr:`~Decorator.args` and :attr:`~Decorator.kwargs` attributes.
The :meth:`~Decorator.after` method can access or change the result using the :attr:`~Decorator.result` attribute.
The :meth:`~Decorator.exception` method can be used for do something with an Exception that has been raised.
In all three methods the :attr:`~Decorator.fqn` and :attr:`~Decorator.func` attributes are available.

Simple decorator
----------------

Create a simple decorator::

import fqn_decorators
import time

class time_it(fqn_decorators.Decorator):

def before(self):
self.start = time.time()

def after(self):
duration = time.time() - self.start
print("{0} took {1} seconds".format(self.fqn, duration))


@time_it
def my_function():
time.sleep(1)

>>>my_function()
__main__.my_function took 1.00293397903 seconds


Decorator with arguments
------------------------

It is also very easy to create a decorator with arguments.

.. note::
It is not possible to create decorators with *non-keyworded* arguments.
To create a decorator that supports non-keyworded arguments see the :ref:`Advanced Usage <usage_advanced_non_keyword_decorators>` section.

Example::

import fqn_decorators
import time

class threshold(fqn_decorators.Decorator):

def before(self):
self.start = time.time()

def after(self):
duration = time.time() - self.start
treshold = self.params.get('threshold')
if threshold and duration > threshold:
raise Exception('Execution took longer than the threshold')


@threshold(threshold=2)
def my_function():
time.sleep(3)

>>> my_function()
Exception: Execution took longer than the threshold

.. end_usage
Release History

Release History

1.0.2

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

1.0.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
fqn-decorators-1.0.2.tar.gz (14.3 kB) Copy SHA256 Checksum SHA256 Source Oct 12, 2016

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