Tracker: Bugs

5 login/login_required validator parameter doesn't work - ID: 1592957
Last Update: Comment added ( ellisj )

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.


Nobody/Anonymous ( nobody ) - 2006-11-08 13:29:49 PST

5

Closed

Fixed

Nobody/Anonymous

None

None

Public


Comments ( 2 )

Date: 2007-02-01 21:36:56 PST
Sender: ellisjProject Admin


oops, that should read

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


Date: 2007-02-01 21:33:57 PST
Sender: ellisjProject Admin


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.


Attached File

No Files Currently Attached

Changes ( 3 )

Field Old Value Date By
status_id Open 2007-02-01 21:33:57 PST ellisj
resolution_id None 2007-02-01 21:33:57 PST ellisj
close_date - 2007-02-01 21:33:57 PST ellisj