[Zope-dev] dtml-sqltest has not been implemented completely
Christian Theune
ct@gocept.com
Wed, 18 Jul 2001 14:43:31 +0200
--2Z2K0IlrPCVsbNpk
Content-Type: multipart/mixed; boundary="32u276st3Jlj2kUU"
Content-Disposition: inline
--32u276st3Jlj2kUU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi all.
As I posted on the zope@zope.org list, I found that the sqltest tag wasn't
implemented as I expected from the DTML documentation.
Following things were different:
- support for expr=3D"" was supposed to be there
- the 'nb' type was expected to work
I fixed both things and used sqlvar.py as a pattern to do so.
I also updated some Exception handling and rewrote the thing
in the style of sqlvar.py as it seems to be more up2date
(sqlvar.py is from 2000/09/07, sqltest.py is from 2000/05/30).
This was in Zope 2.3.3, but wasn't fixed until Zope 2.4.0b3 yet.
I have a patch in this mail, and in the collector. If somebody at DC
would be so kind to review this thing ASAP, because it really breaks
me down to have such a big lack as I began using the sqltest currently.
Regards
PS:
The Collector ID is #2415
--=20
Christian Theune - ct@gocept.com
gocept gmbh & co.kg - schalaunische strasse 6 - 06366 koethen/anhalt
tel.+49 3496 3099112 - fax.+49 3496 3099118 mob. - 0178 48 33 981
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'=
)))
--32u276st3Jlj2kUU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sqltest.patch"
Content-Transfer-Encoding: quoted-printable
--- /home/zope2/lib/python/Shared/DC/ZRDB/sqltest.py Tue May 30 17:46:55 20=
00
+++ lib/python/Shared/DC/ZRDB/sqltest.py Wed Jul 18 14:28:55 2001
@@ -151,23 +151,30 @@
optional=3Dmultiple=3DNone
=20
def __init__(self, args):
- args =3D parse_params(args, name=3D'', type=3DNone, column=3DNone,
+ args =3D parse_params(args, name=3D'', expr=3D'', type=3DNone, col=
umn=3DNone,
multiple=3D1, optional=3D1, op=3DNone)
- self.__name__ =3D name_param(args,'sqlvar')
- has_key=3Dargs.has_key
- if not has_key('type'):
+
+ name,expr =3D name_param(args,'sqlvar',1)
+=09
+ if expr is None: expr=3Dname
+ else: expr=3Dexpr.eval
+ self.__name__, self.expr =3D name, expr
+=09
+ self.args=3Dargs
+ if not args.has_key('type'):
raise ParseError, ('the type attribute is required', 'sqltest')
- self.type=3Dt=3Dargs['type']
+ t=3Dargs['type']
if not valid_type(t):
raise ParseError, ('invalid type, %s' % t, 'sqltest')
- if has_key('optional'): self.optional=3Dargs['optional']
- if has_key('multiple'): self.multiple=3Dargs['multiple']
- if has_key('column'): self.column=3Dargs['column']
+ =20
+ if args.has_key('optional'): self.optional=3Dargs['optional']
+ if args.has_key('multiple'): self.multiple=3Dargs['multiple']
+ if args.has_key('column'): self.column=3Dargs['column']
else: self.column=3Dself.__name__
=20
# Deal with optional operator specification
op =3D '=3D' # Default
- if has_key('op'):
+ if args.has_key('op'):
op =3D args['op']
# Try to get it from the chart, otherwise use the one provided
op =3D comparison_operators.get(op, op)
@@ -175,13 +182,16 @@
=20
def render(self, md):
name=3Dself.__name__
- t=3Dself.type
- try: v =3D md[name]
- except KeyError, key:
- if str(key)=3D=3Dname and self.optional: return ''
- raise KeyError, key, sys.exc_info()[2]
+ args=3Dself.args
+ t=3Dargs['type']
+ try:
+ expr=3Dself.expr
+ if type(expr) is type(''): v=3Dmd[expr]
+ else: v=3Dexpr(md)
+ except:
+ if args.has_key('optional') and args['optional']: return ''
+ raise 'Missing Input', 'Missing input variable, <em>%s</em>' %=
name
=20
- =20
if type(v) in (ListType, TupleType):
if len(v) > 1 and not self.multiple:
raise 'Multiple Values', (
@@ -194,21 +204,36 @@
if not v and type(v) is StringType and t !=3D 'string': contin=
ue
if t=3D=3D'int':
try:
- if type(v) is StringType: atoi(v)
+ if type(v) is StringType:
+ if v[-1:]=3D=3D'L':
+ v=3Dv[:-1]
+ atoi(v)
else: v=3Dstr(int(v))
except:
+ if not v and args.has_key('optional') and args['optional']:
+ return ''
raise ValueError, (
'Invalid integer value for <em>%s</em>' % name)
elif t=3D=3D'float':
- if not v and type(v) is StringType: continue
try:
- if type(v) is StringType: atof(v)
+ if type(v) is StringType:
+ if v[-1:]=3D=3D'L':
+ v=3Dv[:-1]
+ atof(v)
else: v=3Dstr(float(v))
except:
+ if not v and args.has_key('optional') and args['optional']:
+ return ''
raise ValueError, (
'Invalid floating-point value for <em>%s</em>' % n=
ame)
else:
v=3Dstr(v)
+ if not v and t=3D=3D'nb':
+ if args.has_key('optional') and args['optional']:
+ return ''
+ else:
+ raise ValueError, (
+ 'Invalid empty string value for <em>%s</em>' % name)
v=3Dmd.getitem('sql_quote__',0)(v)
#if find(v,"\'") >=3D 0: v=3Djoin(split(v,"\'"),"''")
#v=3D"'%s'" % v
@@ -216,7 +241,8 @@
vs.append(v)
=20
if not vs:
- if self.optional: return ''
+ if args.has_key('optional') and args['optional']:
+ return ''
raise 'Missing Input', (
'No input was provided for <em>%s</em>' % name)
=20
--32u276st3Jlj2kUU--
--2Z2K0IlrPCVsbNpk
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Weitere Infos: siehe http://www.gnupg.org
iD8DBQE7VYRxdUt9X/gknwIRAuYzAJ9RXTXbxj0xkmwPVfLDDOgHyOF3ZACg3Bfc
Qd2Jlb80t93b+buYpIOGsiA=
=8k+7
-----END PGP SIGNATURE-----
--2Z2K0IlrPCVsbNpk--