DecoratorTools

Class, function, and metaclass decorators -- even in Python 2.3 (now with source debugging for generated code)!
Download

DecoratorTools Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Python License
  • Price:
  • FREE
  • Publisher Name:
  • Phillip J. Eby

DecoratorTools Tags


DecoratorTools Description

Class, function, and metaclass decorators -- even in Python 2.3 (now with source debugging for generated code)! Want to use decorators, but still need to support Python 2.3? Wish you could have class decorators, decorate arbitrary assignments, or match decorated function signatures to their original functions? Want to get metaclass features without creating metaclasses? How about synchronized methods?DecoratorTools is a Python module that gets you all of this and more. Some quick examples:# Method decorator examplefrom peak.util.decorators import decorateclass Demo1(object): decorate(classmethod) # equivalent to @classmethod def example(cls): print "hello from", cls# Class decorator examplefrom peak.util.decorators import decorate_classdef my_class_decorator(): def decorator(cls): print "decorating", cls return cls decorate_class(decorator)class Demo2: my_class_decorator()# "decorating < class Demo2 >" will be printed when execution gets hereInstalling DecoratorTools (using "easy_install DecoratorTools" or "setup.py install") gives you access to the peak.util.decorators module. The tools in this module have been bundled for years inside of PEAK, PyProtocols, RuleDispatch, and the zope.interface package, so they have been widely used and tested. (Unit tests are also included, of course.)This standalone version is backward-compatible with the bundled versions, so you can mix and match decorators from this package with those provided by zope.interface, TurboGears, etc. Requirements: · Python


DecoratorTools Related Software