[mod_python] Patch - **args with Publisher

Jonathan Gardner jgardn at alumni.washington.edu
Fri Jan 11 07:14:33 EST 2002


I expected to be able to get all the script args with a piece of code like 
this:

def scriptname(req, **args):
	...

but instead I got none of them at all.

Here is the patch that does what I expect. If I need to submit this 
differently, let me know.

*** publisher.py	Mon Jul  9 21:54:40 2001
--- /usr/local/lib/python2.0/site-packages/mod_python/publisher.py	Fri Jan 11 
07:08:51 2002
***************
*** 150,155 ****
--- 150,157 ----
          # and for that we need to get a list of them. There
          # are a few options for callable objects here:
  
+         # Whether or not there is a **args argument in the function list.
+         has_keyarg = 0
          if str(type(object)) == "<type 'instance'>":
              # instances are callable when they have __call__()
              object = object.__call__
***************
*** 158,172 ****
              # function
              fc = object.func_code
              expected = fc.co_varnames[0:fc.co_argcount]
          elif hasattr(object, 'im_func'):
              # method
              fc = object.im_func.func_code
              expected = fc.co_varnames[1:fc.co_argcount]
  
          # remove unexpected args
!         for name in args.keys():
!             if name not in expected:
!                 del args[name]
  
          result = apply(object, (), args)
  
--- 160,177 ----
              # function
              fc = object.func_code
              expected = fc.co_varnames[0:fc.co_argcount]
+             has_keyarg = fc.co_flags & 0x08
          elif hasattr(object, 'im_func'):
              # method
              fc = object.im_func.func_code
              expected = fc.co_varnames[1:fc.co_argcount]
+             has_keyarg = fc.co_flags & 0x08
  
          # remove unexpected args
!         if not has_keyarg:
!             for name in args.keys():
!                 if name not in expected:
!                     del args[name]
  
          result = apply(object, (), args)



More information about the Mod_python mailing list