Mercurial > fife-parpg
comparison engine/extensions/pychan/tools.py @ 350:7ea98190a75e
Allow objects with an __call__ attribute used as event callbacks.
Tested in pychan demo.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 04 Sep 2009 06:40:50 +0000 |
parents | 48c99636453e |
children | dfd48d49c044 |
comparison
equal
deleted
inserted
replaced
349:493f7492f0ba | 350:7ea98190a75e |
---|---|
38 This is useful to pass information to callbacks without enforcing a particular signature. | 38 This is useful to pass information to callbacks without enforcing a particular signature. |
39 """ | 39 """ |
40 if hasattr(func,'im_func'): | 40 if hasattr(func,'im_func'): |
41 code = func.im_func.func_code | 41 code = func.im_func.func_code |
42 varnames = code.co_varnames[1:code.co_argcount]#ditch bound instance | 42 varnames = code.co_varnames[1:code.co_argcount]#ditch bound instance |
43 else: | 43 elif hasattr(func,'func_code'): |
44 code = func.func_code | 44 code = func.func_code |
45 varnames = code.co_varnames[0:code.co_argcount] | 45 varnames = code.co_varnames[0:code.co_argcount] |
46 elif hasattr(func,'__call__'): | |
47 func = func.__call__ | |
48 if hasattr(func,'im_func'): | |
49 code = func.im_func.func_code | |
50 varnames = code.co_varnames[1:code.co_argcount]#ditch bound instance | |
51 elif hasattr(func,'func_code'): | |
52 code = func.func_code | |
53 varnames = code.co_varnames[0:code.co_argcount] | |
46 | 54 |
47 #http://docs.python.org/lib/inspect-types.html | 55 #http://docs.python.org/lib/inspect-types.html |
48 if code.co_flags & 8: | 56 if code.co_flags & 8: |
49 return func(*args,**kwargs) | 57 return func(*args,**kwargs) |
50 for name,value in kwargs.items(): | 58 for name,value in kwargs.items(): |