Package tp :: Package client :: Module decorator
[show private | hide private]
[frames | no frames]

Module tp.client.decorator

Function Summary
  decorator(caller, func)
General purpose decorator factory: takes a caller function as input and returns a decorator with the same attributes.
  getinfo(func)
Returns an info dictionary containing:...
  update_wrapper(wrapper, wrapped, create)
An improvement over functools.update_wrapper.
  _decorator(caller, func)

Function Details

decorator(caller, func=None)

General purpose decorator factory: takes a caller function as
input and returns a decorator with the same attributes.
A caller function is any function like this::

 def caller(func, *args, **kw):
     # do something
     return func(*args, **kw)

Here is an example of usage:

>>> @decorator
... def chatty(f, *args, **kw):
...     print "Calling %r" % f.__name__
...     return f(*args, **kw)

>>> chatty.__name__
'chatty'

>>> @chatty
... def f(): pass
...
>>> f()
Calling 'f'

For sake of convenience, the decorator factory can also be called with
two arguments. In this casem ``decorator(caller, func)`` is just a
shortcut for ``decorator(caller)(func)``.

getinfo(func)

Returns an info dictionary containing:
- name (the name of the function : str)
- argnames (the names of the arguments : list)
- defaults (the values of the default arguments : tuple)
- signature (the signature : str)
- doc (the docstring : str)
- module (the module name : str)
- dict (the function __dict__ : str)

>>> def f(self, x=1, y=2, *args, **kw): pass

>>> info = getinfo(f)

>>> info["name"]
'f'
>>> info["argnames"]
['self', 'x', 'y', 'args', 'kw']

>>> info["defaults"]
(1, 2)

>>> info["signature"]
'self, x, y, *args, **kw'

update_wrapper(wrapper, wrapped, create=False)

An improvement over functools.update_wrapper. By default it works the
same, but if the 'create' flag is set, generates a copy of the wrapper
with the right signature and update the copy, not the original.
Moreovoer, 'wrapped' can be a dictionary with keys 'name', 'doc', 'module',
'dict', 'defaults'.

Generated by Epydoc 2.1 on Fri Jan 1 08:00:28 2010 http://epydoc.sf.net