From 3b8c3155656c694cf9c2dd84a96d758b324f7b83 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 7 Jul 2008 14:16:59 +0000 Subject: Clean up mapply a little. --- repoze/bfg/mapply.py | 65 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'repoze/bfg/mapply.py') diff --git a/repoze/bfg/mapply.py b/repoze/bfg/mapply.py index 421db2ce3..a27faf3ee 100644 --- a/repoze/bfg/mapply.py +++ b/repoze/bfg/mapply.py @@ -21,51 +21,52 @@ def mapply(object, if hasattr(object,'__bases__'): # the object is a class raise TypeError('Cannot publish class %s' % object) - else: - f=object - im=0 - if hasattr(f, 'im_func'): - im=1 - elif not hasattr(f,'func_defaults'): - if hasattr(f, '__call__'): - f=f.__call__ - if hasattr(f, 'im_func'): - im=1 - elif not hasattr(f,'func_defaults') and maybe: - return object - elif maybe: + + f = object + im = False + + if hasattr(f, 'im_func'): + im = True + elif not hasattr(f, 'func_defaults'): + if hasattr(f, '__call__'): + f = f.__call__ + if hasattr(f, 'im_func'): + im = True + elif not hasattr(f, 'func_defaults') and maybe: return object + elif maybe: + return object - if im: - f=f.im_func - c=f.func_code - defaults=f.func_defaults - names=c.co_varnames[1:c.co_argcount] - else: - defaults=f.func_defaults - c=f.func_code - names=c.co_varnames[:c.co_argcount] + if im: + f = f.im_func + c = f.func_code + defaults = f.func_defaults + names = c.co_varnames[1:c.co_argcount] + else: + defaults = f.func_defaults + c = f.func_code + names = c.co_varnames[:c.co_argcount] - nargs=len(names) + nargs = len(names) if positional: - positional=list(positional) + positional = list(positional) if len(positional) > nargs: raise TypeError('too many arguments') - args=positional + args = positional else: - args=[] + args = [] - get=keyword.get - nrequired=len(names) - (len(defaults or ())) + get = keyword.get + nrequired = len(names) - (len(defaults or ())) for index in range(len(args), len(names)): - name=names[index] - v=get(name, args) + name = names[index] + v = get(name, args) if v is args: if index < nrequired: raise TypeError('Argument %s was omitted' % name) else: - v=defaults[index-nrequired] + v = defaults[index-nrequired] args.append(v) - args=tuple(args) + args = tuple(args) return object(*args) -- cgit v1.2.3