Commit a538bdcd authored by Sidnei da Silva's avatar Sidnei da Silva

- Convert another string exception to normal exception

parent 620e5d16
...@@ -42,7 +42,9 @@ LIMITED_BUILTINS = 1 ...@@ -42,7 +42,9 @@ LIMITED_BUILTINS = 1
str=__builtins__['str'] # Waaaaa, waaaaaaaa needed for pickling waaaaa str=__builtins__['str'] # Waaaaa, waaaaaaaa needed for pickling waaaaa
ParseError='Document Template Parse Error' class ParseError(Exception):
"""Document Template Parse Error"""
from zExceptions import Unauthorized as ValidationError from zExceptions import Unauthorized as ValidationError
def int_param(params,md,name,default=0, st=type('')): def int_param(params,md,name,default=0, st=type('')):
...@@ -248,37 +250,37 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1): ...@@ -248,37 +250,37 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
if v[:1]=='"' and v[-1:]=='"' and len(v) > 1: # expr shorthand if v[:1]=='"' and v[-1:]=='"' and len(v) > 1: # expr shorthand
if used(attr): if used(attr):
raise ParseError, ('%s and expr given' % attr, tag) raise ParseError('%s and expr given' % attr, tag)
if expr: if expr:
if used('expr'): if used('expr'):
raise ParseError, ('two exprs given', tag) raise ParseError('two exprs given', tag)
v=v[1:-1] v=v[1:-1]
try: expr=Eval(v) try: expr=Eval(v)
except SyntaxError, v: except SyntaxError, v:
raise ParseError, ( raise ParseError(
'<strong>Expression (Python) Syntax error</strong>:' '<strong>Expression (Python) Syntax error</strong>:'
'\n<pre>\n%s\n</pre>\n' % v[0], '\n<pre>\n%s\n</pre>\n' % v[0],
tag) tag)
return v, expr return v, expr
else: raise ParseError, ( else: raise ParseError(
'The "..." shorthand for expr was used in a tag ' 'The "..." shorthand for expr was used in a tag '
'that doesn\'t support expr attributes.', 'that doesn\'t support expr attributes.',
tag) tag)
else: # name shorthand else: # name shorthand
if used(attr): if used(attr):
raise ParseError, ('Two %s values were given' % attr, tag) raise ParseError('Two %s values were given' % attr, tag)
if expr: if expr:
if used('expr'): if used('expr'):
# raise 'Waaaaaa', 'waaa' # raise 'Waaaaaa', 'waaa'
raise ParseError, ('%s and expr given' % attr, tag) raise ParseError('%s and expr given' % attr, tag)
return params[''],None return params[''],None
return params[''] return params['']
elif used(attr): elif used(attr):
if expr: if expr:
if used('expr'): if used('expr'):
raise ParseError, ('%s and expr given' % attr, tag) raise ParseError('%s and expr given' % attr, tag)
return params[attr],None return params[attr],None
return params[attr] return params[attr]
elif expr and used('expr'): elif expr and used('expr'):
...@@ -286,7 +288,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1): ...@@ -286,7 +288,7 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
expr=Eval(name) expr=Eval(name)
return name, expr return name, expr
raise ParseError, ('No %s given' % attr, tag) raise ParseError('No %s given' % attr, tag)
Expr_doc=""" Expr_doc="""
...@@ -399,11 +401,11 @@ def parse_params(text, ...@@ -399,11 +401,11 @@ def parse_params(text,
l=len(mo_unp.group(1)) l=len(mo_unp.group(1))
if result: if result:
if parms.has_key(name): if parms.has_key(name):
if parms[name] is None: raise ParseError, ( if parms[name] is None: raise ParseError(
'Attribute %s requires a value' % name, tag) 'Attribute %s requires a value' % name, tag)
result[name]=parms[name] result[name]=parms[name]
else: raise ParseError, ( else: raise ParseError(
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
else: else:
result['']=name result['']=name
...@@ -411,22 +413,22 @@ def parse_params(text, ...@@ -411,22 +413,22 @@ def parse_params(text,
elif mo_unq: elif mo_unq:
name=mo_unq.group(2) name=mo_unq.group(2)
l=len(mo_unq.group(1)) l=len(mo_unq.group(1))
if result: raise ParseError, ( if result: raise ParseError(
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
else: result['']=name else: result['']=name
return parse_params(text[l:],result,**parms) return parse_params(text[l:],result,**parms)
else: else:
if not text or not text.strip(): return result if not text or not text.strip(): return result
raise ParseError, ('invalid parameter: "%s"' % text, tag) raise ParseError('invalid parameter: "%s"' % text, tag)
if not parms.has_key(name): if not parms.has_key(name):
raise ParseError, ( raise ParseError(
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
if result.has_key(name): if result.has_key(name):
p=parms[name] p=parms[name]
if type(p) is not ListType or p: if type(p) is not ListType or p:
raise ParseError, ( raise ParseError(
'Duplicate values for attribute "%s"' % name, tag) 'Duplicate values for attribute "%s"' % name, tag)
result[name]=value result[name]=value
......
...@@ -78,10 +78,10 @@ class SQLVar: ...@@ -78,10 +78,10 @@ class SQLVar:
self.args=args self.args=args
if not args.has_key('type'): if not args.has_key('type'):
raise ParseError, ('the type attribute is required', 'dtvar') raise ParseError('the type attribute is required', 'dtvar')
t=args['type'] t=args['type']
if not valid_type(t): if not valid_type(t):
raise ParseError, ('invalid type, %s' % t, 'dtvar') raise ParseError('invalid type, %s' % t, 'dtvar')
def render(self, md): def render(self, md):
name=self.__name__ name=self.__name__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment