[Checkins] SVN: z3c.pt/trunk/ Use a simplified UnicodeWrite clause
for the result of _translate calls,
as the result value is guaranteed to be Unicode.
Hanno Schlichting
plone at hannosch.info
Sat Jun 14 07:38:49 EDT 2008
Log message for revision 87391:
Use a simplified UnicodeWrite clause for the result of _translate calls, as the result value is guaranteed to be Unicode.
Changed:
U z3c.pt/trunk/benchmark/benchmark/tests.py
U z3c.pt/trunk/docs/HISTORY.txt
U z3c.pt/trunk/src/z3c/pt/clauses.py
U z3c.pt/trunk/src/z3c/pt/translation.py
-=-
Modified: z3c.pt/trunk/benchmark/benchmark/tests.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/tests.py 2008-06-14 10:46:37 UTC (rev 87390)
+++ z3c.pt/trunk/benchmark/benchmark/tests.py 2008-06-14 11:38:49 UTC (rev 87391)
@@ -73,7 +73,8 @@
bigtable_i18n_z3c = z3c.pt.PageTemplate("""\
<table xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
- xmlns:tal="http://xml.zope.org/namespaces/tal">
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ i18n:domain="domain">
<tr tal:repeat="row table">
<span i18n:translate="label_default">Default</span>
<td tal:repeat="c row.values()">
@@ -115,7 +116,8 @@
bigtable_i18n_zope.pt_edit("""\
<table xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
- xmlns:tal="http://xml.zope.org/namespaces/tal">
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ i18n:domain="domain">
<tr tal:repeat="row python: options['table']">
<span i18n:translate="label_default">Default</span>
<td tal:repeat="c python: row.values()">
Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt 2008-06-14 10:46:37 UTC (rev 87390)
+++ z3c.pt/trunk/docs/HISTORY.txt 2008-06-14 11:38:49 UTC (rev 87391)
@@ -4,6 +4,9 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Use a simplified UnicodeWrite clause for the result of _translate calls,
+ as the result value is guaranteed to be Unicode.
+
- Added simple benchmark test for i18n handling.
- Added more tests for i18n attributes handling.
Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py 2008-06-14 10:46:37 UTC (rev 87390)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py 2008-06-14 11:38:49 UTC (rev 87391)
@@ -689,6 +689,56 @@
self.assign.end(stream)
stream.restore()
+class UnicodeWrite(Write):
+ """
+ >>> from z3c.pt.generation import CodeIO
+ >>> from StringIO import StringIO
+
+ Basic write:
+
+ >>> stream = CodeIO()
+ >>> _out = StringIO()
+ >>> write = Write(types.value("'New York'"))
+ >>> write.begin(stream)
+ >>> write.end(stream)
+ >>> exec stream.getvalue()
+ >>> _out.getvalue()
+ 'New York'
+
+ Unicode:
+
+ >>> stream = CodeIO()
+ >>> _out = StringIO()
+ >>> write = Write(types.value("unicode('La Pe\xc3\xb1a', 'utf-8')"))
+ >>> write.begin(stream)
+ >>> write.end(stream)
+ >>> exec stream.getvalue()
+ >>> _out.getvalue() == 'La Pe\xc3\xb1a'
+ True
+
+ Invalid:
+
+ >>> stream = CodeIO()
+ >>> _out = StringIO()
+ >>> write = Write(types.value("None"))
+ >>> write.begin(stream)
+ >>> write.end(stream)
+ >>> exec stream.getvalue()
+ >>> _out.getvalue()
+ ''
+ """
+
+ def begin(self, stream):
+ temp = stream.save()
+
+ if self.value:
+ expr = self.value
+ else:
+ self.assign.begin(stream, temp)
+ expr = temp
+
+ stream.write("_out.write(%s.encode('utf-8'))" % expr)
+
class Out(object):
"""
>>> from z3c.pt.generation import CodeIO; stream = CodeIO()
Modified: z3c.pt/trunk/src/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.py 2008-06-14 10:46:37 UTC (rev 87390)
+++ z3c.pt/trunk/src/z3c/pt/translation.py 2008-06-14 11:38:49 UTC (rev 87391)
@@ -196,7 +196,7 @@
# fallback to default rendition;
result = types.value('_result')
condition = types.value('_result is not _marker')
- _.append(clauses.Condition(condition, [clauses.Write(result)]))
+ _.append(clauses.Condition(condition, [clauses.UnicodeWrite(result)]))
subclauses = []
if self.text:
More information about the Checkins
mailing list