[albatross-users] Problem with ctx.get_value
Tim Churches
tchur at optushome.com.au
Wed Aug 17 18:21:18 EST 2005
Andrew McNamara <andrewm at object-craft.com.au> wrote:
>
> >While trying to think of a way to figure out the value of the
> formfield,
> >without calling the ctx.get_value function, I tried this in the
> interactive
> >shell:
> >
> >iMac:~ sheilaking$ python2.4
> >Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
> >[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
> >OK, I was pretty sure it was just a string of the digits 0238, but I
> >changed line 113 in qaForms to the following:
> >
> >if formfield == 'year':
> > debug("ctx.locals.year=`%s`" % repr(ctx.locals.year))
> >fieldvalue = ctx.get_value(formfield)
> >
> >*note: debug is a function that simply writes out debugging statements
> to a
> >text file for me.
> >
> >Here is the output of the debug statement above:
> >
> >*** Wed Aug 17 03:45:13 2005
> >ctx.locals.year=`'0238'`
> >
> >So, it looks to me like it is simply a string of four digits, namely,
> 0238
> >and when I call ctx.get_value on the formfield "year", I get an
> exception.
>
> The above doesn't really fit with what's happening. Essentially
> ctx.get_value(name) looks like (with some irrelevent steps left out):
>
> def get_value(name):
> return eval(name, {}, self.locals.__dict__)
>
> Somehow "formfield" must be set to "0238", rather than "year".
>
> This is what should be happening:
>
> >>> locals={'year': '0238'}
> >>> eval('year', {}, locals)
> '0238'
>
> This is what it looks like is happening:
>
> >>> eval('0238', {}, locals)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<string>", line 1
> 0238
> ^
> SyntaxError: invalid token
>
Of course, apart from the fact that the entered value is being evaluated by the Python interpreter (rather large security issue there...), the actual error with 0238 is because Python interprets strings of integers starting with zero (other than just zero) as octal, and 8 is not a valid octal digit.
Two answers from the other side of the world...
Tim C
More information about the Albatross-users
mailing list