You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-dev@quetz.apache.org by "Graham Dumpleton (JIRA)" <ji...@apache.org> on 2005/01/28 10:33:17 UTC

[jira] Created: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Builtin functions not callable with mod_python.publisher.
---------------------------------------------------------

         Key: MODPYTHON-13
         URL: http://issues.apache.org/jira/browse/MODPYTHON-13
     Project: mod_python
        Type: Bug
    Versions: 3.1.3    
    Reporter: Graham Dumpleton


Create a handler file containing:

  _dict = { "a": 1 }
  keys = _dict.keys

Where this file is called "builtin.py", access "builtin.py/keys".

This yields the error:

  Mod_python error: "PythonHandler mod_python.publisher"

  Traceback (most recent call last):

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
      result = object(req)

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
      result = util.apply_fs_data(object, req.form, req=req)

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
      if not (fc.co_flags & 0x08):

  UnboundLocalError: local variable 'fc' referenced before assignment

To fix this, mod_python.util needs to be modified in apply_fs_data(). The
modified section of code is:

    fc = None

    expected = [] 
    if hasattr(object, "func_code"):
        # 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]
    elif type(object) is ClassType:
        # class
        fc = object.__init__.im_func.func_code
        expected = fc.co_varnames[1:fc.co_argcount]
    
    # remove unexpected args unless co_flags & 0x08,
    # meaning function accepts **kw syntax
    if not fc:
        args = {}
    elif not (fc.co_flags & 0x08):
        for name in args.keys():
            if name not in expected:
                del args[name]

Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
out "args" altogether.

This change then correctly yields:

  ['a']




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Work started: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Nicolas Lehuen (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=history ]
     
Work on MODPYTHON-13 started by Nicolas Lehuen

> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Nicolas Lehuen (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=history ]
     
Nicolas Lehuen resolved MODPYTHON-13:
-------------------------------------

     Resolution: Fixed
    Fix Version: 3.1.4

Fixed and checked in.

> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen
>      Fix For: 3.1.4

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Nicolas Lehuen (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=history ]

Nicolas Lehuen reassigned MODPYTHON-13:
---------------------------------------

    Assign To: Nicolas Lehuen

> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Nicolas Lehuen (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=comments#action_59111 ]
     
Nicolas Lehuen commented on MODPYTHON-13:
-----------------------------------------

You can easily modify the current behaviour by adding a special cas efor BuiltinFunctionType in the rules :

 # those are the exceptions to the previous rules
 tp_rules.update({
     # Those are not traversable nor publishable
     ModuleType          : (False, False),
     ClassType           : (False, False),
     TypeType            : (False, False),
+    BuiltinFunctionType : (False, False),
    
     # XXX Generators should be publishable, see
     # http://issues.apache.org/jira/browse/MODPYTHON-15
     # Until they are, it is not interesting to publish them
     GeneratorType       : (False, False),
    
     # Old-style instances are traversable
     InstanceType        : (True, True),
 })


> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen
>      Fix For: 3.1.4

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=comments#action_59102 ]
     
Graham Dumpleton commented on MODPYTHON-13:
-------------------------------------------

I am actually thinking that allow calling of builtin methods is not a good idea after all. The thing is that only calls against builtin methods that take no arguments can be called if one does this. This is because callable objects must use named parameters, or keyword argument lists to be executable by a GET/POST form though mod_python. Thus, it seems to be silly to have an exception just for no parameter builtin methods. It thus might make sense to disallow calling of all builtin methods and make someone wrap them in a actual scripted Python function to call any of them, whether they have arguments or not.

> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen
>      Fix For: 3.1.4

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Closed: (MODPYTHON-13) Builtin functions not callable with mod_python.publisher.

Posted by "Graham Dumpleton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/MODPYTHON-13?page=all ]
     
Graham Dumpleton closed MODPYTHON-13:
-------------------------------------


> Builtin functions not callable with mod_python.publisher.
> ---------------------------------------------------------
>
>          Key: MODPYTHON-13
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-13
>      Project: mod_python
>         Type: Bug
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>     Assignee: Nicolas Lehuen
>      Fix For: 3.2.7

>
> Create a handler file containing:
>   _dict = { "a": 1 }
>   keys = _dict.keys
> Where this file is called "builtin.py", access "builtin.py/keys".
> This yields the error:
>   Mod_python error: "PythonHandler mod_python.publisher"
>   Traceback (most recent call last):
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 308, in HandlerDispatch
>       result = object(req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
>       result = util.apply_fs_data(object, req.form, req=req)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/util.py", line 356, in apply_fs_data
>       if not (fc.co_flags & 0x08):
>   UnboundLocalError: local variable 'fc' referenced before assignment
> To fix this, mod_python.util needs to be modified in apply_fs_data(). The
> modified section of code is:
>     fc = None
>     expected = [] 
>     if hasattr(object, "func_code"):
>         # 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]
>     elif type(object) is ClassType:
>         # class
>         fc = object.__init__.im_func.func_code
>         expected = fc.co_varnames[1:fc.co_argcount]
>     
>     # remove unexpected args unless co_flags & 0x08,
>     # meaning function accepts **kw syntax
>     if not fc:
>         args = {}
>     elif not (fc.co_flags & 0x08):
>         for name in args.keys():
>             if name not in expected:
>                 del args[name]
> Ie., give "fc" a default value, and if it is not able to be set in if clauses, wipe
> out "args" altogether.
> This change then correctly yields:
>   ['a']

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira