#17 login/login_required validator parameter doesn't work

closed-fixed
nobody
None
5
2007-02-02
2006-11-08
Anonymous
No

rkopelman@mainframe.ca

At least with Python 2.3.4, it is not possible to
override the 'validator' parameter for the login and
login_required tags.

Attempting a very simple test

[[\ def validate(login, password):
return 1
]]
<spy:login_required validator="validate"/>

will result in the following error:

Spyce exception
File: /path/to/spyce/file.spy

Message:
TypeError: eval() argument 2 must be dict, not None

Stack: /usr/share/spyce/spyceCompile.py:1520, in

_evalWithImport:
eval(prefix, env)

<string>:55, in spyceProcess:
None
=================================

There appear to be two components to this problem.

#1) spyceCompile.py:_evalWithImport() is not being
passed an environment that includes the current page.
In fact, it is not being passed any environment, which
leads to the following:

#2) _evalWithImport() defaults its 'env' param to
'None' rather than an empty dictionary. This results
in the preceding exception when 'None' is passed to
eval(). This problem prevents ANY validator function
from being set, not just local ones, as it dies trying
to import foreign modules as well.

Discussion

  • Jonathan Ellis
    Jonathan Ellis
    2007-02-02

    Logged In: YES
    user_id=657828
    Originator: NO

    Hmm, for some reason it just didn't occur to me that someone would want to declare a validator inline. :)

    I added locals() as the env, so you can define a validator as a class chunk:

    [[!
    def validate(login, password):
    return 1
    ]]
    <spy:login_required validator="self.validate"/>

    (As with handlers, it's not really possible to make it work with local functions, as opposed to instance methods.)

    I applied this in the spyce-2.2 branch (rev. 1295), but you could easily apply it locally if you want.

     
  • Jonathan Ellis
    Jonathan Ellis
    2007-02-02

    • status: open --> closed-fixed
     
  • Jonathan Ellis
    Jonathan Ellis
    2007-02-02

    Logged In: YES
    user_id=657828
    Originator: NO

    oops, that should read

    [[!
    def validate(self, login, password):
    return 1
    ]]
    <spy:login_required validator="self.validate"/>