summaryrefslogtreecommitdiff
path: root/django/dispatch/robustapply.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2006-07-21 20:48:17 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2006-07-21 20:48:17 +0000
commit1687b025dc2a03e9ef111b8fd3db63fce48b77b7 (patch)
treefd2ad4dcabc6adc57d5290e6a66be16661558ea9 /django/dispatch/robustapply.py
parenta926046ba633ac38d3306b6bc10677a670929786 (diff)
Part 3 of pedant day: replaced all tabs in Django with spaces. Python the way Guido intended it, baby!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3415 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/dispatch/robustapply.py')
-rw-r--r--django/dispatch/robustapply.py70
1 files changed, 34 insertions, 36 deletions
diff --git a/django/dispatch/robustapply.py b/django/dispatch/robustapply.py
index 0350e60cfc..14ba2b51ac 100644
--- a/django/dispatch/robustapply.py
+++ b/django/dispatch/robustapply.py
@@ -7,43 +7,41 @@ those which are acceptable.
"""
def function( receiver ):
- """Get function-like callable object for given receiver
+ """Get function-like callable object for given receiver
- returns (function_or_method, codeObject, fromMethod)
+ returns (function_or_method, codeObject, fromMethod)
- If fromMethod is true, then the callable already
- has its first argument bound
- """
- if hasattr(receiver, '__call__'):
- # receiver is a class instance; assume it is callable.
- # Reassign receiver to the actual method that will be called.
- if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'):
- receiver = receiver.__call__
- if hasattr( receiver, 'im_func' ):
- # an instance-method...
- return receiver, receiver.im_func.func_code, 1
- elif not hasattr( receiver, 'func_code'):
- raise ValueError('unknown reciever type %s %s'%(receiver, type(receiver)))
- return receiver, receiver.func_code, 0
+ If fromMethod is true, then the callable already
+ has its first argument bound
+ """
+ if hasattr(receiver, '__call__'):
+ # receiver is a class instance; assume it is callable.
+ # Reassign receiver to the actual method that will be called.
+ if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'):
+ receiver = receiver.__call__
+ if hasattr( receiver, 'im_func' ):
+ # an instance-method...
+ return receiver, receiver.im_func.func_code, 1
+ elif not hasattr( receiver, 'func_code'):
+ raise ValueError('unknown reciever type %s %s'%(receiver, type(receiver)))
+ return receiver, receiver.func_code, 0
def robustApply(receiver, *arguments, **named):
- """Call receiver with arguments and an appropriate subset of named
- """
- receiver, codeObject, startIndex = function( receiver )
- acceptable = codeObject.co_varnames[startIndex+len(arguments):codeObject.co_argcount]
- for name in codeObject.co_varnames[startIndex:startIndex+len(arguments)]:
- if named.has_key( name ):
- raise TypeError(
- """Argument %r specified both positionally and as a keyword for calling %r"""% (
- name, receiver,
- )
- )
- if not (codeObject.co_flags & 8):
- # fc does not have a **kwds type parameter, therefore
- # remove unacceptable arguments.
- for arg in named.keys():
- if arg not in acceptable:
- del named[arg]
- return receiver(*arguments, **named)
-
- \ No newline at end of file
+ """Call receiver with arguments and an appropriate subset of named
+ """
+ receiver, codeObject, startIndex = function( receiver )
+ acceptable = codeObject.co_varnames[startIndex+len(arguments):codeObject.co_argcount]
+ for name in codeObject.co_varnames[startIndex:startIndex+len(arguments)]:
+ if named.has_key( name ):
+ raise TypeError(
+ """Argument %r specified both positionally and as a keyword for calling %r"""% (
+ name, receiver,
+ )
+ )
+ if not (codeObject.co_flags & 8):
+ # fc does not have a **kwds type parameter, therefore
+ # remove unacceptable arguments.
+ for arg in named.keys():
+ if arg not in acceptable:
+ del named[arg]
+ return receiver(*arguments, **named)