Re: Re: Problem with ctx.get_value
Tim Churches <[email protected]> Wed, 17 Aug 2005 18:21:18 +1000
| Newsgroups | gmane.comp.web.albatross.general |
|---|---|
| Message-ID | <[email protected]> |
Andrew McNamara <[email protected]> wrote: >=20 > >While trying to think of a way to figure out the value of the=20 > formfield,=20 > >without calling the ctx.get_value function, I tried this in the=20 > interactive=20 > >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=20 > >changed line 113 in qaForms to the following: > > > >if formfield =3D=3D 'year': > > debug("ctx.locals.year=3D`%s`" % repr(ctx.locals.year)) > >fieldvalue =3D ctx.get_value(formfield) > > > >*note: debug is a function that simply writes out debugging statements= =20 > to a=20 > >text file for me. > > > >Here is the output of the debug statement above: > > > >*** Wed Aug 17 03:45:13 2005 > >ctx.locals.year=3D`'0238'` > > > >So, it looks to me like it is simply a string of four digits, namely,=20 > 0238 > >and when I call ctx.get_value on the formfield "year", I get an=20 > exception. >=20 > The above doesn't really fit with what's happening. Essentially > ctx.get_value(name) looks like (with some irrelevent steps left out): >=20 > def get_value(name): > return eval(name, {}, self.locals.__dict__) >=20 > Somehow "formfield" must be set to "0238", rather than "year".=20 >=20 > This is what should be happening: >=20 > >>> locals=3D{'year': '0238'} > >>> eval('year', {}, locals) > '0238' >=20 > This is what it looks like is happening: >=20 > >>> eval('0238', {}, locals) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "<string>", line 1 > 0238 > ^ > SyntaxError: invalid token >=20 Of course, apart from the fact that the entered value is being evaluated = by the Python interpreter (rather large security issue there...), the act= ual error with 0238 is because Python interprets strings of integers star= ting with zero (other than just zero) as octal, and 8 is not a valid octa= l digit.=20 Two answers from the other side of the world... Tim C