diff -r 240f77b8a01f django/dispatch/robustapply.py
a
|
b
|
and subset the given arguments to match
|
5 | 5 | and subset the given arguments to match only |
6 | 6 | those which are acceptable. |
7 | 7 | """ |
| 8 | |
| 9 | def _has_im_func_code(obj): |
| 10 | """ |
| 11 | Checks if `obj` has an `im_func` attribute containing its own `func_code` |
| 12 | |
| 13 | Checking for im_func alone is not correct, because on Jython, |
| 14 | `reflectedfunction`s have an im_func attribute without func_code. |
| 15 | """ |
| 16 | return hasattr(obj, 'im_func') and hasattr(obj.im_func, 'func_code') |
8 | 17 | |
9 | 18 | def function( receiver ): |
10 | 19 | """Get function-like callable object for given receiver |
… |
… |
def function( receiver ):
|
17 | 26 | if hasattr(receiver, '__call__'): |
18 | 27 | # receiver is a class instance; assume it is callable. |
19 | 28 | # Reassign receiver to the actual method that will be called. |
20 | | if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'): |
| 29 | if _has_im_func_code(receiver.__call__) \ |
| 30 | or hasattr(receiver.__call__, 'im_code'): |
21 | 31 | receiver = receiver.__call__ |
22 | | if hasattr( receiver, 'im_func' ): |
| 32 | if _has_im_func_code(receiver): |
23 | 33 | # an instance-method... |
24 | 34 | return receiver, receiver.im_func.func_code, 1 |
25 | 35 | elif not hasattr( receiver, 'func_code'): |
… |
… |
def robustApply(receiver, *arguments, **
|
39 | 49 | ) |
40 | 50 | ) |
41 | 51 | if not (codeObject.co_flags & 8): |
42 | | # fc does not have a **kwds type parameter, therefore |
| 52 | # fc does not have a **kwds type parameter, therefore |
43 | 53 | # remove unacceptable arguments. |
44 | 54 | for arg in named.keys(): |
45 | 55 | if arg not in acceptable: |