Beispiel #1
0
 def process(self, m):
     self.updated = True
     op, argstr = m.groups()
     op = op or self.default_op
     self.formatter.env.log.debug('Converting TracForms op: ' + str(op))
     kw = {}
     args = tuple(self.getargs(argstr, kw))
     fn = self.env.get('op:' + op.lower())
     if fn is None:
         fn = getattr(self, 'op_' + op.lower(), None)
     if fn is None:
         raise FormTooManyValuesError(str(op))
     else:
         try:
             if op[:5] == 'wikiop_':
                 self.formatter.env.log.debug('TracForms wiki value: ' +
                                              self.wiki(str(fn(*args))))
                 return self.wiki(str(fn(*args)))
             else:
                 self.formatter.env.log.debug('TracForms value: ' +
                                              to_unicode(fn(*args, **kw)))
                 return to_unicode(fn(*args, **kw))
         except FormError, e:
             return '<PRE>' + str(e) + '</PRE>'
         except Exception, e:
             return '<PRE>' + traceback.format_exc() + '</PRE>'
Beispiel #2
0
 def get_field(self, name, default=None, make_single=True):
     current = self.env.get(name, default)
     if make_single and isinstance(current, (tuple, list)):
         if len(current) == 0:
             current = default
         elif len(current) == 1:
             current = current[0]
         else:
             raise FormTooManyValuesError(str(name))
     return current
Beispiel #3
0
 def cmd_operation(_self, _name, _op, *_args, **_kw):
     if _op in ('is', 'as'):
         _op, _args = _args[0], _args[1:]
     op = getattr(_self, 'op_' + _op, None)
     if op is None:
         raise FormTooManyValuesError(str(_name))
     def partial(*_newargs, **_newkw):
         if _kw or _newkw:
             kw = dict(_kw)
             kw.update(_newkw)
         else:
             kw = {}
         return op(*(_newargs + _args), **kw)
     _self.env['op:' + _name] = partial