"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/cgi/PageTemplates/TALES.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

TALES.py  (roundup-1.6.1):TALES.py  (roundup-2.0.0)
skipping to change at line 26 skipping to change at line 26
# 2. implemented ustr as str (removes import from DocumentTemplate) # 2. implemented ustr as str (removes import from DocumentTemplate)
# 3. removed import and use of Unauthorized from zExceptions # 3. removed import and use of Unauthorized from zExceptions
"""TALES """TALES
An implementation of a generic TALES engine An implementation of a generic TALES engine
""" """
import re, sys import re, sys
from roundup.cgi import ZTUtils from roundup.cgi import ZTUtils
from weakref import ref from weakref import ref
from MultiMapping import MultiMapping from .MultiMapping import MultiMapping
from GlobalTranslationService import getGlobalTranslationService from .GlobalTranslationService import getGlobalTranslationService
ustr = str ustr = str
StringType = type('') StringType = type('')
NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*" NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*"
_parse_expr = re.compile(r"(%s):" % NAME_RE).match _parse_expr = re.compile(r"(%s):" % NAME_RE).match
_valid_name = re.compile('%s$' % NAME_RE).match _valid_name = re.compile('%s$' % NAME_RE).match
class TALESError(BaseException): class TALESError(BaseException):
skipping to change at line 112 skipping to change at line 112
''' '''
Iterator = Iterator Iterator = Iterator
def __init__(self, Iterator=None): def __init__(self, Iterator=None):
self.types = {} self.types = {}
if Iterator is not None: if Iterator is not None:
self.Iterator = Iterator self.Iterator = Iterator
def registerType(self, name, handler): def registerType(self, name, handler):
if not _valid_name(name): if not _valid_name(name):
raise RegistrationError, 'Invalid Expression type "%s".' % name raise RegistrationError('Invalid Expression type "%s".' % name)
types = self.types types = self.types
if types.has_key(name): if name in types:
raise RegistrationError, ( raise RegistrationError(
'Multiple registrations for Expression type "%s".' % 'Multiple registrations for Expression type "%s".' %
name) name)
types[name] = handler types[name] = handler
def getTypes(self): def getTypes(self):
return self.types return self.types
def compile(self, expression): def compile(self, expression):
m = _parse_expr(expression) m = _parse_expr(expression)
if m: if m:
type = m.group(1) type = m.group(1)
expr = expression[m.end():] expr = expression[m.end():]
else: else:
type = "standard" type = "standard"
expr = expression expr = expression
try: try:
handler = self.types[type] handler = self.types[type]
except KeyError: except KeyError:
raise CompilerError, ( raise CompilerError(
'Unrecognized expression type "%s".' % type) 'Unrecognized expression type "%s".' % type)
return handler(type, expr, self) return handler(type, expr, self)
def getContext(self, contexts=None, **kwcontexts): def getContext(self, contexts=None, **kwcontexts):
if contexts is not None: if contexts is not None:
if kwcontexts: if kwcontexts:
kwcontexts.update(contexts) kwcontexts.update(contexts)
else: else:
kwcontexts = contexts kwcontexts = contexts
return Context(self, kwcontexts) return Context(self, kwcontexts)
skipping to change at line 231 skipping to change at line 231
TALESTracebackSupplement, self, expression) TALESTracebackSupplement, self, expression)
return expression(self) return expression(self)
evaluateValue = evaluate evaluateValue = evaluate
evaluateBoolean = evaluate evaluateBoolean = evaluate
def evaluateText(self, expr): def evaluateText(self, expr):
text = self.evaluate(expr) text = self.evaluate(expr)
if text is Default or text is None: if text is Default or text is None:
return text return text
if isinstance(text, unicode): if isinstance(text, type(u'')):
return text return text
else: else:
return ustr(text) return ustr(text)
def evaluateStructure(self, expr): def evaluateStructure(self, expr):
return self.evaluate(expr) return self.evaluate(expr)
evaluateStructure = evaluate evaluateStructure = evaluate
def evaluateMacro(self, expr): def evaluateMacro(self, expr):
# XXX Should return None or a macro definition # XXX Should return None or a macro definition
skipping to change at line 283 skipping to change at line 283
self.column = context.position[1] self.column = context.position[1]
self.expression = repr(expression) self.expression = repr(expression)
def getInfo(self, as_html=0): def getInfo(self, as_html=0):
import pprint import pprint
data = self.context.contexts.copy() data = self.context.contexts.copy()
s = pprint.pformat(data) s = pprint.pformat(data)
if not as_html: if not as_html:
return ' - Names:\n %s' % s.replace('\n', '\n ') return ' - Names:\n %s' % s.replace('\n', '\n ')
else: else:
from cgi import escape from roundup.anypy.html import html_escape
return '<b>Names:</b><pre>%s</pre>' % (escape(s)) return '<b>Names:</b><pre>%s</pre>' % (html_escape(s))
class SimpleExpr: class SimpleExpr:
'''Simple example of an expression type handler''' '''Simple example of an expression type handler'''
def __init__(self, name, expr, engine): def __init__(self, name, expr, engine):
self._name = name self._name = name
self._expr = expr self._expr = expr
def __call__(self, econtext): def __call__(self, econtext):
return self._name, self._expr return self._name, self._expr
def __repr__(self): def __repr__(self):
return '<SimpleExpr %s %s>' % (self._name, `self._expr`) return '<SimpleExpr %s %s>' % (self._name, repr(self._expr))
 End of changes. 7 change blocks. 
9 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)