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/interfaces.py | 6 ++--- repoze/bfg/mapply.py | 65 +++++++++++++++++++++++---------------------- repoze/bfg/sampleapp/app.py | 4 ++- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/repoze/bfg/interfaces.py b/repoze/bfg/interfaces.py index af68410dd..a0409ba89 100644 --- a/repoze/bfg/interfaces.py +++ b/repoze/bfg/interfaces.py @@ -1,6 +1,9 @@ from zope.interface import Interface from zope.interface import Attribute +class IRequest(Interface): + """ Marker interface for a request object """ + class IResponse(Interface): status = Attribute('WSGI status code of response') headerlist = Attribute('List of response headers') @@ -36,9 +39,6 @@ class IWSGIApplicationFactory(Interface): def __call__(view, request): """ Return an object that implements IWSGIApplication """ -class IRequest(Interface): - """ Marker interface for a request object """ - class ILocation(Interface): """Objects that have a structural location""" __parent__ = Attribute("The parent in the location hierarchy") 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) diff --git a/repoze/bfg/sampleapp/app.py b/repoze/bfg/sampleapp/app.py index 84069f220..f48f72141 100644 --- a/repoze/bfg/sampleapp/app.py +++ b/repoze/bfg/sampleapp/app.py @@ -1,3 +1,5 @@ +import UserDict + from zope.interface import classProvides from zope.interface import implements from zope.interface import Interface @@ -11,7 +13,7 @@ from webob import Response class IBlogModel(Interface): id = Attribute('id') -class BlogModel: +class BlogModel(UserDict): implements(IBlogModel) def __init__(self, id): self.id = id -- cgit v1.2.3