[Repoze-checkins] r1241 - in repoze.bfg/trunk/repoze/bfg: . sampleapp

Chris McDonough chrism at agendaless.com
Mon Jul 7 10:17:00 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Mon Jul  7 10:16:59 2008
New Revision: 1241

Log:
Clean up mapply a little.


Modified:
   repoze.bfg/trunk/repoze/bfg/interfaces.py
   repoze.bfg/trunk/repoze/bfg/mapply.py
   repoze.bfg/trunk/repoze/bfg/sampleapp/app.py

Modified: repoze.bfg/trunk/repoze/bfg/interfaces.py
==============================================================================
--- repoze.bfg/trunk/repoze/bfg/interfaces.py	(original)
+++ repoze.bfg/trunk/repoze/bfg/interfaces.py	Mon Jul  7 10:16:59 2008
@@ -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 @@
     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")

Modified: repoze.bfg/trunk/repoze/bfg/mapply.py
==============================================================================
--- repoze.bfg/trunk/repoze/bfg/mapply.py	(original)
+++ repoze.bfg/trunk/repoze/bfg/mapply.py	Mon Jul  7 10:16:59 2008
@@ -21,51 +21,52 @@
 
     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)

Modified: repoze.bfg/trunk/repoze/bfg/sampleapp/app.py
==============================================================================
--- repoze.bfg/trunk/repoze/bfg/sampleapp/app.py	(original)
+++ repoze.bfg/trunk/repoze/bfg/sampleapp/app.py	Mon Jul  7 10:16:59 2008
@@ -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 @@
 class IBlogModel(Interface):
     id = Attribute('id')
 
-class BlogModel:
+class BlogModel(UserDict):
     implements(IBlogModel)
     def __init__(self, id):
         self.id = id


More information about the Repoze-checkins mailing list