Skip to content

Commit

Permalink
- compatibility fixes for better unicode support in DocumentTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 25, 2019
1 parent 91b009b commit 609b30c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
3.0.7 (unreleased)
------------------

- compatibility fixes for better unicode support in DocumentTemplate


3.0.6 (2019-04-03)
------------------
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'Zope >= 4.0b5',
'Missing',
'Record',
'DocumentTemplate >= 3.0b7',
],
include_package_data=True,
zip_safe=False,
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/DC/ZRDB/sqlgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class SQLGroup:
set = None
noparens = None

def __init__(self, blocks):

def __init__(self, blocks, encoding=None):
self.encoding = encoding
self.blocks = blocks
tname, args, section = blocks[0]
self.__name__ = '%s %s' % (tname, args)
Expand Down
18 changes: 11 additions & 7 deletions src/Shared/DC/ZRDB/sqltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@
from DocumentTemplate.DT_Util import parse_params


StringTypes = six.string_types + (six.binary_type,)


class SQLTest:
name = 'sqltest'
optional = multiple = None

def __init__(self, args):
def __init__(self, args, encoding=None):
self.encoding = encoding
args = parse_params(args, name='', expr='', type=None, column=None,
multiple=1, optional=1, op=None)
name, expr = name_param(args, 'sqlvar', 1)
Expand Down Expand Up @@ -113,7 +117,7 @@ def render(self, md):
args = self.args
try:
expr = self.expr
if isinstance(expr, type('')):
if isinstance(expr, StringTypes):
v = md[expr]
else:
v = expr(md)
Expand All @@ -131,11 +135,11 @@ def render(self, md):

vs = []
for v in v:
if not v and isinstance(v, str) and t != 'string':
if not v and isinstance(v, StringTypes) and t != 'string':
continue
if t == 'int':
try:
if isinstance(v, str):
if isinstance(v, StringTypes):
if v[-1:] == 'L':
v = v[:-1]
int(v)
Expand All @@ -145,10 +149,10 @@ def render(self, md):
msg = 'Invalid integer value for <em>%s</em>' % name
raise ValueError(msg)
elif t == 'float':
if not v and isinstance(v, str):
if not v and isinstance(v, StringTypes):
continue
try:
if isinstance(v, str):
if isinstance(v, StringTypes):
float(v)
else:
v = str(float(v))
Expand All @@ -157,7 +161,7 @@ def render(self, md):
raise ValueError(msg)

else:
if not isinstance(v, (str, six.text_type)):
if not isinstance(v, StringTypes):
v = str(v)
v = md.getitem('sql_quote__', 0)(v)
# if v.find("\'") >= 0: v="''".(v.split("\'"))
Expand Down
15 changes: 8 additions & 7 deletions src/Shared/DC/ZRDB/sqlvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@
from DocumentTemplate.DT_Util import parse_params


StringType = str
StringTypes = six.string_types + (six.binary_type,)


class SQLVar:
name = 'sqlvar'

def __init__(self, args):
def __init__(self, args, encoding=None):
self.encoding = encoding
args = parse_params(args, name='', expr='', type=None, optional=1)

name, expr = name_param(args, 'sqlvar', 1)
Expand All @@ -84,14 +85,14 @@ def render(self, md):
t = args['type']
try:
expr = self.expr
if isinstance(expr, type('')):
if isinstance(expr, StringTypes):
v = md[expr]
else:
v = expr(md)
except Exception:
if 'optional' in args and args['optional']:
return 'null'
if not isinstance(expr, type('')):
if not isinstance(expr, StringTypes):
raise
raise ValueError('Missing input variable, <em>%s</em>' % name)

Expand All @@ -100,7 +101,7 @@ def render(self, md):

if t == 'int':
try:
if isinstance(v, str):
if isinstance(v, StringTypes):
if v[-1:] == 'L':
v = v[:-1]
int(v)
Expand All @@ -113,7 +114,7 @@ def render(self, md):
raise ValueError(err)
elif t == 'float':
try:
if isinstance(v, str):
if isinstance(v, StringTypes):
if v[-1:] == 'L':
v = v[:-1]
float(v)
Expand All @@ -125,7 +126,7 @@ def render(self, md):
err = 'Invalid floating-point value for <em>%s</em>' % name
raise ValueError(err)
else:
if not isinstance(v, (str, six.text_type)):
if not isinstance(v, (str, StringTypes)):
v = str(v)
if not v and t == 'nb':
if 'optional' in args and args['optional']:
Expand Down

0 comments on commit 609b30c

Please sign in to comment.