From 9e3d92d7e8980fc24256ac90fe7792c27c27faf1 Mon Sep 17 00:00:00 2001 From: Godefroid Chapelle Date: Mon, 11 Jun 2007 16:02:37 +0000 Subject: extension module does compile; but cannot be imported --- src/zope/tal/_talinterpreter/__init__.py | 3 ++- src/zope/tal/_talinterpreter/applevel.py | 30 +++++++++++++---------------- src/zope/tal/_talinterpreter/interplevel.py | 10 +++++++--- src/zope/tal/talinterpreter.py | 10 ++++++---- src/zope/tal/talpypy/test/__init__.py | 1 + src/zope/tal/talutils.py | 11 +++++++++++ 6 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 src/zope/tal/talutils.py diff --git a/src/zope/tal/_talinterpreter/__init__.py b/src/zope/tal/_talinterpreter/__init__.py index 53f5afb..3df4862 100644 --- a/src/zope/tal/_talinterpreter/__init__.py +++ b/src/zope/tal/_talinterpreter/__init__.py @@ -4,11 +4,12 @@ class Module(MixedModule): """interpreter module.""" interpleveldefs = { - 'normalize' : 'interplevel.normalize', + '_normalize' : 'interplevel._normalize', } appleveldefs = { 'TALInterpreter' : 'applevel.TALInterpreter', + 'normalize' : 'applevel.normalize', } diff --git a/src/zope/tal/_talinterpreter/applevel.py b/src/zope/tal/_talinterpreter/applevel.py index ae6c1ae..d2b300c 100644 --- a/src/zope/tal/_talinterpreter/applevel.py +++ b/src/zope/tal/_talinterpreter/applevel.py @@ -1,3 +1,4 @@ +"""NOT_RPYTHON""" ############################################################################## # # Copyright (c) 2001, 2002 Zope Corporation and Contributors. @@ -11,15 +12,11 @@ # FOR A PARTICULAR PURPOSE. # ############################################################################## -"""Interpreter for a pre-compiled TAL program. -$Id$ -""" import cgi import sys -from zope.i18nmessageid import Message from zope.tal.taldefs import quote, TAL_VERSION, METALError from zope.tal.taldefs import isCurrentVersion from zope.tal.taldefs import getProgramVersion, getProgramMode @@ -28,10 +25,8 @@ from zope.tal.alttalgenerator import AltTALGenerator import _talinterpreter -# Avoid constructing this tuple over and over -I18nMessageTypes = (Message,) - -TypesToTranslate = I18nMessageTypes + (str, unicode) +from zope.tal.talutils import isI18nMessageTypes +from zope.tal.talutils import isTypesToTranslate BOOLEAN_HTML_ATTRS = frozenset([ # List of Boolean attributes in HTML that should be rendered in @@ -47,7 +42,8 @@ BOOLEAN_HTML_ATTRS = frozenset([ _nulljoin = ''.join _spacejoin = ' '.join - +def normalize(value): + return _talinterpreter._normalize(value) class MacroStackItem(object): def __init__(self, macroName, slots, definingName, extending, entering, i18nContext): @@ -443,7 +439,7 @@ class TALInterpreter(object): translated = self.translate(msgid or value, value) if translated is not None: value = translated - elif isinstance(value, I18nMessageTypes): + elif isI18nMessageTypes(value): translated = self.translate(value) if translated is not None: value = translated @@ -573,7 +569,7 @@ class TALInterpreter(object): if text is self.Default: self.interpret(stuff[1]) return - if isinstance(text, I18nMessageTypes): + if isI18nMessageTypes(text): # Translate this now. text = self.translate(text) self._writeText(text) @@ -585,7 +581,7 @@ class TALInterpreter(object): if text is self.Default: self.interpret(stuff[1]) else: - if isinstance(text, TypesToTranslate): + if isTypesToTranslate(text): text = self.translate(text) self._writeText(text) @@ -605,7 +601,7 @@ class TALInterpreter(object): if self.html and self._currentTag == "pre": value = tmpstream.getvalue() else: - value = _talinterpreter.normalize(tmpstream.getvalue()) + value = normalize(tmpstream.getvalue()) finally: self.restoreState(state) else: @@ -620,7 +616,7 @@ class TALInterpreter(object): value = self.engine.evaluate(expression) # evaluate() does not do any I18n, so we do it here. - if isinstance(value, I18nMessageTypes): + if isI18nMessageTypes(value): # Translate this now. value = self.translate(value) @@ -668,7 +664,7 @@ class TALInterpreter(object): if self.html and currentTag == "pre": msgid = default else: - msgid = _talinterpreter.normalize(default) + msgid = normalize(default) self.i18nStack.pop() # See if there is was an i18n:data for msgid if len(stuff) > 2: @@ -695,7 +691,7 @@ class TALInterpreter(object): if structure is self.Default: self.interpret(block) return - if isinstance(structure, I18nMessageTypes): + if isI18nMessageTypes(structure): text = self.translate(structure) else: text = unicode(structure) @@ -715,7 +711,7 @@ class TALInterpreter(object): if structure is self.Default: self.interpret(block) else: - if not isinstance(structure, TypesToTranslate): + if not isTypesToTranslate(structure): structure = unicode(structure) text = self.translate(structure) if not (repldict or self.strictinsert): diff --git a/src/zope/tal/_talinterpreter/interplevel.py b/src/zope/tal/_talinterpreter/interplevel.py index e942d9a..a1acd16 100644 --- a/src/zope/tal/_talinterpreter/interplevel.py +++ b/src/zope/tal/_talinterpreter/interplevel.py @@ -1,10 +1,14 @@ from pypy.interpreter.baseobjspace import ObjSpace -def normalize(space, text): + +def _normalize(space, text): # Now we need to normalize the whitespace in implicit message ids and # implicit $name substitution values by stripping leading and trailing # whitespace, and folding all internal whitespace to a single space. - result = ' '.join(text.split()) + text = text.replace('\n', ' ') + text = text.replace('\t', ' ') + parts = [part for part in text.split(' ') if part] + result = ' '.join(parts) return space.wrap(result) -normalize.unwrap_spec = [ObjSpace, str] +_normalize.unwrap_spec = [ObjSpace, str] diff --git a/src/zope/tal/talinterpreter.py b/src/zope/tal/talinterpreter.py index ab181f7..acf4aab 100644 --- a/src/zope/tal/talinterpreter.py +++ b/src/zope/tal/talinterpreter.py @@ -1,8 +1,10 @@ try: from pypy.interpreter.mixedmodule import testmodule - _talinterpreter = testmodule('_talinterpreter', 'zope.tal') + rptalinterpreter = testmodule('rptalinterpreter', 'zope.tal') except ImportError: - import _talinterpreter + import rptalinterpreter + + +normalize = rptalinterpreter.normalize +TALInterpreter = rptalinterpreter.TALInterpreter -normalize = _talinterpreter.normalize -TALInterpreter = _talinterpreter.TALInterpreter diff --git a/src/zope/tal/talpypy/test/__init__.py b/src/zope/tal/talpypy/test/__init__.py index 674a75a..d26f273 100644 --- a/src/zope/tal/talpypy/test/__init__.py +++ b/src/zope/tal/talpypy/test/__init__.py @@ -9,4 +9,5 @@ class Module(MixedModule): } appleveldefs = { + 'appfunc' : 'appzpt.appfunc', } diff --git a/src/zope/tal/talutils.py b/src/zope/tal/talutils.py new file mode 100644 index 0000000..7a76ebc --- /dev/null +++ b/src/zope/tal/talutils.py @@ -0,0 +1,11 @@ +from zope.i18nmessageid import Message + +I18nMessageTypes = (Message,) +TypesToTranslate = I18nMessageTypes + (str, unicode) + +def isI18nMessageTypes(value): + return isinstance(value, I18nMessageTypes) + +def isTypesToTranslate(value): + return isinstance(value, TypesToTranslate) + -- cgit v1.2.1