diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-07 14:16:59 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-07 14:16:59 +0000 |
| commit | 3b8c3155656c694cf9c2dd84a96d758b324f7b83 (patch) | |
| tree | 1aee479b9eb929657c747f619077d3d398ba0979 | |
| parent | c91c9c78274ab454980a0087ade15cc897f47ddc (diff) | |
| download | pyramid-3b8c3155656c694cf9c2dd84a96d758b324f7b83.tar.gz pyramid-3b8c3155656c694cf9c2dd84a96d758b324f7b83.tar.bz2 pyramid-3b8c3155656c694cf9c2dd84a96d758b324f7b83.zip | |
Clean up mapply a little.
| -rw-r--r-- | repoze/bfg/interfaces.py | 6 | ||||
| -rw-r--r-- | repoze/bfg/mapply.py | 65 | ||||
| -rw-r--r-- | 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 |
