[PEAK] dispatch -- chaining decorators
Simon Belak
simon.belak at hruska.si
Fri Dec 9 14:31:42 EST 2005
Hi,
I have a decorator I would like to use along-side generic functions but
I am having some trouble getting it to play along:
def unpickle(arg_name):
def __entangle(func):
pickle_pos = list(func.func_code.co_varnames).index(arg_name)
assert pickle_pos < func.func_code.co_argcount
def __func(*args, **kwargs):
return func(*args[:pickle_pos] + (load(args[pickle_pos]),)
+ args[pickle_pos+1:], **kwargs)
return __func
return __entangle
When I apply this decorator on an "around" function:
@unpickle("form")
@view.around("is_pickle(form)")
def unpickle_form(next_method, form, context):
next_method(form, context)
one of two things happen depending on order in which decorators were
applied. Either argument position gets wrongly calculated (around,
unpickle) or my decorator does not get called at all (unpickle, around).
I am guessing that in the first case next_method the causing me
troubles, but what about the second case? Any good wraparounds?
On a not-so-related note, can generic functions be overused? I am
currently writing a framework and just realised that nearly all exposed
functions have become generic. To me it seems that this allows perfect
flexibility and modularity as the user can plug in his code almost
anywhere. But still I cannot completely silent a voice in the back of my
mind screaming "Danger of cool things!".
Thanks,
Simon
More information about the PEAK
mailing list