[Zope-Checkins] CVS: Zope3/lib/python/Zope/TAL - driver.py:1.25.18.3.4.2
Barry Warsaw
barry@wooz.org
Tue, 11 Jun 2002 15:47:44 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv21845
Modified Files:
Tag: fdrake-tal-i18n-branch
driver.py
Log Message:
Some testing gunk. It turns out to be useful to have special engines
and translation services to test some combinations of i18n tal,
because I want to be able to add path and variable specifications such
as i18n:data="here/currentTime".
TimeFormatTranslation: Hard codes a translation for msgid "timefmt".
TimeEngine: Hard codes an evaluation of the expression
"here/currentTime" to return a dictionary containing "hours",
"minutes", and "ampm" keys.
ENGINES: Big ol' hard code to use the TimeEngine class instead of the
DummyEngine for two of the tests (we might add more later).
main(): Use ENGINES to decide which engine to use.
=== Zope3/lib/python/Zope/TAL/driver.py 1.25.18.3.4.1 => 1.25.18.3.4.2 ===
# Import local classes
import TALDefs
-import DummyEngine
+from DummyEngine import DummyEngine
+from DummyEngine import DummyTranslationService
FILE = "tests/input/test01.xml"
+class TimeFormatTranslation(DummyTranslationService):
+ def translate(self, domain, msgid, mapping=None, context=None,
+ target_language=None):
+ if msgid == 'timefmt':
+ return '%(minutes)s minutes after %(hours)s %(ampm)s' % mapping
+ return DummyTranslationService.translate(self, domain, msgid,
+ mapping, context,
+ target_language)
+
+class TimeEngine(DummyEngine):
+ def __init__(self, macros=None):
+ DummyEngine.__init__(self, macros)
+ self.dummyTranslationService = TimeFormatTranslation()
+
+ def evaluatePathOrVar(self, expr):
+ expr = expr.strip()
+ parts = expr.split('/')
+ if parts[0] == 'here' and parts[1] == 'currentTime':
+ return {'hours' : 6,
+ 'minutes': 59,
+ 'ampm' : 'PM',
+ }
+ return DummyEngine.evaluatePathOrVar(self, expr)
+
+# This is a disgusting hack so that we can use engines that actually know
+# something about certain object paths. TimeEngine knows about
+# here/currentTime.
+ENGINES = {'test23.html': TimeEngine,
+ 'test24.html': TimeEngine,
+ }
+
def usage(code, msg=''):
# Python 2.1 required
print >> sys.stderr, __doc__
@@ -100,7 +132,13 @@
if showcode:
showit(it)
else:
- interpretit(it, tal=(not macros), showtal=showtal,
+ # See if we need a special engine for this test
+ engine = None
+ engineClass = ENGINES.get(os.path.basename(file))
+ if engineClass is not None:
+ engine = engineClass(macros)
+ interpretit(it, engine=engine,
+ tal=(not macros), showtal=showtal,
strictinsert=strictinsert,
i18nInterpolate=i18nInterpolate)
@@ -110,7 +148,7 @@
program, macros = it
assert TALDefs.isCurrentVersion(program)
if engine is None:
- engine = DummyEngine.DummyEngine(macros)
+ engine = DummyEngine(macros)
TALInterpreter(program, macros, engine, stream, wrap=0,
tal=tal, showtal=showtal, strictinsert=strictinsert,
i18nInterpolate=i18nInterpolate)()