[Zope-Checkins] CVS: Packages/Shared/DC/ZRDB - sqlgroup.py:1.9.68.2
Tres Seaver
tseaver at palladion.com
Fri Sep 16 10:25:15 EDT 2005
Update of /cvs-repository/Packages/Shared/DC/ZRDB
In directory cvs.zope.org:/tmp/cvs-serv7670/lib/python/Shared/DC/ZRDB
Modified Files:
Tag: Zope-2_7-branch
sqlgroup.py
Log Message:
- Collector #1118: Added syntax to dtml-sqlgroup to support flexible
generation of 'UPDATE' statements.
=== Packages/Shared/DC/ZRDB/sqlgroup.py 1.9.68.1 => 1.9.68.2 ===
--- Packages/Shared/DC/ZRDB/sqlgroup.py:1.9.68.1 Mon Nov 17 17:34:16 2003
+++ Packages/Shared/DC/ZRDB/sqlgroup.py Fri Sep 16 10:24:44 2005
@@ -11,7 +11,7 @@
#
##############################################################################
-'''Inserting optional tests with 'sqlgroup'
+"""Inserting optional tests with 'sqlgroup'
It is sometimes useful to make inputs to an SQL statement
optinal. Doing so can be difficult, because not only must the
@@ -59,7 +59,9 @@
other than whitespace characters. If it does, then it is inserted
with the appropriate boolean operator, as indicated by use of an
'and' or 'or' tag, otherwise, no text is inserted.
-'''
+
+$Id$
+"""
############################################################################
# Copyright
@@ -69,44 +71,66 @@
# rights reserved.
#
############################################################################
-__rcs_id__='$Id$'
-__version__='$Revision$'[11:-2]
from DocumentTemplate.DT_Util import parse_params
-str=__builtins__['str']
+str = __builtins__['str']
from string import strip, join
import sys
+_TNAME_MAPPING = {'comma': ','}
+
class SQLGroup:
- blockContinuations='and','or'
- name='sqlgroup'
- required=None
- where=None
+
+ blockContinuations = 'and', 'or', 'comma'
+ name = 'sqlgroup'
+ required = None
+ where = None
+ set = None
+ noparens = None
def __init__(self, blocks):
- self.blocks=blocks
+ self.blocks = blocks
tname, args, section = blocks[0]
- self.__name__="%s %s" % (tname, args)
- args = parse_params(args, required=1, where=1)
- if args.has_key(''): args[args['']]=1
- if args.has_key('required'): self.required=args['required']
- if args.has_key('where'): self.where=args['where']
+ self.__name__ = "%s %s" % (tname, args)
+ args = parse_params(args, required=1, where=1, set=1, noparens=1)
+ if args.has_key(''):
+ args[args['']] = 1
+ if args.has_key('required'):
+ self.required = args['required']
+ if args.has_key('where'):
+ self.where = args['where']
+ if args.has_key('set'):
+ self.set = args['set']
+ if args.has_key('noparens'):
+ self.noparens = args['noparens']
def render(self,md):
- r=[]
+ r = []
for tname, args, section in self.blocks:
- __traceback_info__=tname
- s=strip(section(None, md))
+ __traceback_info__ = tname
+ s = strip(section(None, md))
if s:
- if r: r.append(tname)
- r.append("%s\n" % s)
+ if r:
+ r.append(_TNAME_MAPPING.get(tname, tname))
+ if self.noparens:
+ r.append("%s" % s)
+ else:
+ r.append("%s\n" % s)
if r:
- if len(r) > 1: r="(%s)\n" % join(r,' ')
- else: r=r[0]
- if self.where: r="where\n"+r
+ if len(r) > 1:
+ if self.noparens:
+ r = "%s\n" % join(r,' ')
+ else:
+ r = "(%s)\n" % join(r,' ')
+ else:
+ r = r[0]
+ if self.set:
+ r = "set\n" + r
+ if self.where:
+ r = "where\n" + r
return r
if self.required:
@@ -114,4 +138,4 @@
return ''
- __call__=render
+ __call__ = render
More information about the Zope-Checkins
mailing list