[Zope-dev] DTML sqltest tag and python expr. Bug in Zope Book?

Yves-Eric Martin yemartin@yve.net
Sat, 30 Jun 2001 15:33:49 +0900


On Thu, 28 Jun 2001 22:42:13 +0200 (CEST)
Dieter Maurer <dieter@handshake.de> wrote:

> I expect that "dtml-sqltest" does not support the "expr"
> attribute due to its "optional".
> 
> It is not easy to define the semantics of "optional" for
> arbitrary expressions.

    True, but you already found a possible answer:


> Your example seems to suggests, that you would like
> the tag to be omitted, when the expression
> raise a NameError.
> But, in fact, it is not clear whether this is anticipated
> by "optional" or a serious problem (maybe deep in the
> expression) that should be reported.

    To overcome that problem, I think it would make sense to treat the
"optional" like this: when the expression raises a NameError, if the
variable name that caused the error is an expected argument of the
ZSQLMethod, then this argument was not provided, so do not render the
sqltest tag. Otherwise, we have a real error. In a pythonish algorithm,
that would look like this:


    try:
        renderedExpr = eval(expr)
    except NameError, varName:
        if varName in ZSQLMethodArguments:
            # "optional" behavior for missing variable
            pass
        else:
            # We have a real error
            raise NameError, varName
    else:
        # render sqltest tag
        ...


Do you think that makes sense?


-- 
Yves-Eric Martin
yemartin@yve.net