def handle_macro(self, elem, page): type = elem.get(moin_page.content_type) alt = elem.get(moin_page.alt) # TODO if not type or not type.startswith('x-moin/macro;name='): return name = type[18:] context_block = elem.tag == moin_page.part args_tree = None for item in elem: if item.tag.uri == moin_page.namespace: if item.tag.name in ('body', 'inline-body'): return if item.tag.name == 'arguments': args_tree = item args = None if args_tree: args = Arguments() for arg in args_tree: key = arg.get(moin_page.name) value = arg[0] if key: args.keyword[key] = value else: args.positional.append(value) elem_body = context_block and moin_page.body() or moin_page.inline_body() elem_error = moin_page.error() cls = plugins.importPlugin(app.cfg, 'macro', name, function='Macro') try: macro = cls() # XXX refactor all macros so they are OK without "request" ret = macro((), args, page, alt, context_block) elem_body.append(ret) except Exception, e: # we do not want that a faulty macro aborts rendering of the page # and makes the wiki UI unusable (by emitting a Server Error), # thus, in case of exceptions, we just log the problem and return # some standard text. logger.exception("Macro %s raised an exception:" % name) elem_error.append(_('<<%(macro_name)s: execution failed [%(error_msg)s] (see also the log)>>', macro_name=name, error_msg=unicode(e), ))
def handle_macro(self, elem, page): logging.debug("handle_macro elem: %r" % elem) type = elem.get(moin_page.content_type) alt = elem.get(moin_page.alt) if not type: return type = Type(type) if not (type.type == 'x-moin' and type.subtype == 'macro'): logging.debug("not a macro, skipping: %r" % (type, )) return name = type.parameters['name'] context_block = elem.tag == moin_page.part args = elem[0] if len(elem) else None elem_body = context_block and moin_page.body() or moin_page.inline_body() elem_error = moin_page.error() try: cls = plugins.importPlugin(app.cfg, 'macro', name, function='Macro') macro = cls() ret = macro((), args, page, alt, context_block) elem_body.append(ret) except PluginMissingError: elem_error.append('<<%s>> %s' % (name, _('Error: invalid macro name.'))) except Exception as e: # we do not want that a faulty macro aborts rendering of the page # and makes the wiki UI unusable (by emitting a Server Error), # thus, in case of exceptions, we just log the problem and return # some standard text. logging.exception("Macro {0} raised an exception:".format(name)) elem_error.append(_('<<%(macro_name)s: execution failed [%(error_msg)s] (see also the log)>>', macro_name=name, error_msg=unicode(e), )) if len(elem_body): elem.append(elem_body) if len(elem_error): elem.append(elem_error)
def handle_macro(self, elem, page): logging.debug("handle_macro elem: %r" % elem) type = elem.get(moin_page.content_type) alt = elem.get(moin_page.alt) if not type: return type = Type(type) if not (type.type == 'x-moin' and type.subtype == 'macro'): logging.debug("not a macro, skipping: %r" % type) return name = type.parameters['name'] context_block = elem.tag == moin_page.part args_tree = None for item in elem: if item.tag.uri == moin_page.namespace: if item.tag.name in ('body', 'inline-body'): return if item.tag.name == 'arguments': args_tree = item args = None if args_tree: args = Arguments() for arg in args_tree: key = arg.get(moin_page.name) value = arg[0] if key: args.keyword[key] = value else: args.positional.append(value) elem_body = context_block and moin_page.body() or moin_page.inline_body() elem_error = moin_page.error() try: cls = plugins.importPlugin(app.cfg, 'macro', name, function='Macro') macro = cls() ret = macro((), args, page, alt, context_block) elem_body.append(ret) except PluginMissingError: elem_error.append('<<%s>> %s' % (name, _('Error: invalid macro name.'))) except Exception as e: # we do not want that a faulty macro aborts rendering of the page # and makes the wiki UI unusable (by emitting a Server Error), # thus, in case of exceptions, we just log the problem and return # some standard text. logger.exception("Macro {0} raised an exception:".format(name)) elem_error.append(_('<<%(macro_name)s: execution failed [%(error_msg)s] (see also the log)>>', macro_name=name, error_msg=unicode(e), )) if len(elem_body): elem.append(elem_body) if len(elem_error): elem.append(elem_error)
def visit_error(self, node): self.open_moin_page_node(moin_page.error())