1. Konstantine Rybnikov
  2. fat-po-editor

Source

fat-po-editor / fat / fat_po_editor / lib / watch.py

# -*- coding: utf-8 -*-

class watch_me(object):
    """ Decorator to debug function
    TODO (if you need) extend it with functionality
    to accept lambda's for args, kw or ret_val filtering,
    and maybe limit/offset.
    """
    def __init__(self, limit=None):
        self.limit = limit
    
    def __call__(self, f):
        def new_f(*args, **kw):
            ret_val = f(*args, **kw)
            
            print((u"%(func)s(args=%(args)s, kw=%(kw)s) -> "
                   u"%(ret_val)s") % dict(
                    func=f.__name__,
                    args=args,
                    kw=kw,
                    ret_val=ret_val
                    )
                  )

            return ret_val
            
        return new_f