Ticket #6857: robustapply_jython_compatible.patch

File robustapply_jython_compatible.patch, 1.8 KB (added by Leo Soto M., 17 years ago)
  • django/dispatch/robustapply.py

    diff -r 240f77b8a01f django/dispatch/robustapply.py
    a b and subset the given arguments to match  
    55and subset the given arguments to match only
    66those which are acceptable.
    77"""
     8
     9def _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')
    817
    918def function( receiver ):
    1019    """Get function-like callable object for given receiver
    def function( receiver ):  
    1726    if hasattr(receiver, '__call__'):
    1827        # receiver is a class instance; assume it is callable.
    1928        # 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'):
    2131            receiver = receiver.__call__
    22     if hasattr( receiver, 'im_func' ):
     32    if _has_im_func_code(receiver):
    2333        # an instance-method...
    2434        return receiver, receiver.im_func.func_code, 1
    2535    elif not hasattr( receiver, 'func_code'):
    def robustApply(receiver, *arguments, **  
    3949                )
    4050            )
    4151    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
    4353        # remove unacceptable arguments.
    4454        for arg in named.keys():
    4555            if arg not in acceptable:
Back to Top