Example #1
0
    def __init__(self, request, page):
        self.parser = Parser("", request)
        # Format the empty string, making it set its internal data (ugh!).
        out = cStringIO.StringIO()
        backup = sys.stdout, request.write
        sys.stdout, request.write = out, out.write
        self.parser.format(page.formatter)
        sys.stdout, request.write = backup
        self.include_re = re.compile("\[\[Include(?:\(.*?\))?\]\]")
        self.macro = macro.Macro(self.parser)

        # This is really deep and cool black magic. Basically, it creates
        # a local copy of the function macro.Include.execute that behaves
        # exactly like the original one, but with a different "Page"
        # global. This allows us to follow changes in the Include macro
        # without much trouble.
        from MoinMoin.macro.Include import execute
        func_globals = {}
        func_globals.update(execute.func_globals)

        class IncludePage(Page):
            incparser = self

            def send_page(self, request, msg=None, **keywords):
                request.write(self.incparser._parse(self.get_raw_body()))

        func_globals["Page"] = IncludePage
        self.execute = new.function(execute.func_code, func_globals,
                                    execute.func_name, execute.func_defaults)
Example #2
0
def format_wikitext(request, data, parser=None):
    request.page.formatter = request.formatter
    request.formatter.page = request.page

    if not parser:
        parser = Parser(data, request)
    else:
        parser.raw = data
    parser.request = request

    # Do not store pagelinks for values in metadata listings
    plstore = getattr(request.formatter, '_store_pagelinks', 0)
    request.formatter._store_pagelinks = 0

    parser.formatter = request.formatter
    # No line anchors of any type to table cells
    request.page.formatter.in_p = 1
    parser._line_anchordef = lambda: ''

    # Do not parse macros from revision pages. For some reason,
    # it spawns multiple requests, which are not finished properly,
    # thus littering a number of readlocks. Besides, the macros do not
    # return anything useful anyway for pages they don't recognize
    if '?action=recall' in request.page.page_name:
        parser._macro_repl = lambda x: x

    out = parser.scan(data, inhibit_p=True)

    request.formatter._store_pagelinks = plstore
    return out.strip()
Example #3
0
def do_macro(request, args, **kw):
    formatter = request.formatter
    _ = request.getText
    out = list()
    pagename = request.page.page_name

    # Note, metatable_parseargs deals with permissions
    pagelist, metakeys, styles = metatable_parseargs(request,
                                                     args,
                                                     get_all_keys=True)

    # No data -> bail out quickly, Scotty
    if not pagelist:
        out.append(formatter.linebreak() + u'<div class="metatable">' +
                   formatter.table(1))
        if kw.get('silent'):
            out.extend(t_cell(request, request.page, ["%s" % _("No matches")]))
        else:
            out.extend(
                t_cell(request, request.page,
                       ["%s '%s'" % (_("No matches for"), args)]))
        out.append(formatter.table(0) + u'</div>')
        return "".join(out)

    parser = Parser('', request)

    options = dict({'args': args}.items() + kw.items())
    divfmt = {'class': "metatable", 'data-options': quote(json.dumps(options))}
    out.append(formatter.div(1, **divfmt))
    # We're sure the user has the access to the page, so don't check
    out.extend(
        construct_table(request,
                        pagelist,
                        metakeys,
                        checkAccess=False,
                        styles=styles,
                        options=options,
                        parser=parser))

    def action_link(action, linktext, args):
        req_url = request.script_root + "/" + \
            url_escape(request.page.page_name) + \
            '?action=' + action + '&amp;args=' + url_escape(args)
        return '<a href="%s" class="meta_footer_link">[%s]</a>\n' % \
            (req_url, _(linktext))

    # If the user has no write access to this page, omit editlink
    if kw.get('editlink', True):
        out.append(action_link('MetaEdit', 'edit', args))

    out.append(action_link('metaCSV', 'csv', args))
    out.append(action_link('metaPackage', 'zip', args))
    out.append(formatter.div(0))
    return "".join(out)
Example #4
0
 def do(self, text, output):
     text = text.lstrip('\n')
     output = output.strip('\n')
     request = MinimalRequest(self.request)
     page = MinimalPage()
     formatter = Formatter(request)
     formatter.setPage(page)
     Parser(text, request).format(formatter)
     repeat = ''.join(request.result).strip('\n')
     #assert repeat == output
     out = self.do_convert_real([request, page.page_name, repeat])
     assert text == out
Example #5
0
def moin2doku(pagename, text, randomID=None):
    parser = Parser(text, request)

    formatter.setRandomID(randomID)

    # this needed for macros
    request.formatter = formatter

    p = Page(request, pagename)
    formatter.setPage(p)

    output = StringIO.StringIO()

    # wrap sys.stdout as RequestCLI has no interface to say where to output
    stdout = sys.stdout
    sys.stdout = output
    parser.format(formatter)
    sys.stdout = stdout

    return unicode(output.getvalue().decode('utf-8'))
def t_cell(macro, value):
    out = macro.request

    style = dict()
    style['class'] = 'meta_cell'

    out.write(macro.formatter.table_cell(1, attrs=style))

    value = value.strip()

    out.page.formatter = out.formatter
    parser = Parser(value, out)
    # No line anchors of any type to table cells
    out.page.formatter.in_p = 1
    parser._line_anchordef = lambda: ''

    # Using StringIO in order to strip the output
    value = StringIO.StringIO()
    out.redirect(value)
    # Produces output on a single table cell
    out.page.format(parser)
    out.redirect()

    out.write(value.getvalue().strip())
Example #7
0
class Cfg:
	_site_plugin_lists = {}
	_plugin_modules = []
	bang_meta = False
	
class Request:
	getText = None
	form = None
	cfg = Cfg()
	pragma = {}
	
	def write(self, text):
		print text,

class Page:
	hilite_re = None
	page_name = 'arst'

if __name__ == '__main__':
	req = Request()
	if len(sys.argv) == 1:
		contents = sys.stdin.read()
	else:
		contents = open(sys.argv[1]).read()
		
	p = Parser(contents, req)
	f = Formatter(req)
	f.page = Page()
	
	p.format(f)