JPz'log Coin Coin and Plop da Plop

31Mar/091

DecoratorInjector in Python by Yannick

My friend Yannick is a huge fan of the Python programming language. As a die-hard geek, he's been coding various hacks over the years, but for some very strange reason, he never published a single of his (sometimes really nice) hacks :-)

We pushed him again and again, and I'm glad to announce that after more than a year of intense pressure, Yannick has just published the first of his hacks! Congrats Yannick, and thanks for not choosing the GPL ;-)

This first hack is called "DecoratorInjection" (notice the nice Sphinx documentation):

This is an internal DSL providing fluent interface to inject decoration, i.e. decorate methods at runtime.

Method names can be specified directly or using a method grabber, which introspect the class.

The DSL is quite pleasant to read. For example you can easily perform AOP on your Python classes using a decorator and the following declaration:

decorate(PUBLIC_METHODS).of(classes_named("DAO.*").within(somemodule)).using(tracer)

which sould be read as:

decorate the public methods of the classes whose name start with "DAO" in the module called "somemodule" using the "tracer" decorator

Nice work Yannick, and please publish more of your Python hacks! :-)

Share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Live
  • Netvibes
  • StumbleUpon
  • Technorati
  • FriendFeed
  • Wikio
  • Twitter
  • Identi.ca
  • Reddit
  • RSS
  • Slashdot

Related posts:

  1. A todo list on Google App Engine… Python
  2. nose: testing in Python made easy
  3. Python + mod_python: why use PHP again?
  4. Rails-style Ruby meta-programming
  5. Revisiting Guice and AOP with AspectJ

Comments (1) Trackbacks (0)

Leave a comment


No trackbacks yet.

JPz'log is Digg proof thanks to caching by WP Super Cache