muyhomepage2 / muyhomepage2 / pagehandlers /

Full commit

import re
from muyhomepage2.pagehandlers import handler
from muyhomepage2.text import wikirst

class SoftwareHandler(handler.PageHandler):
    def content(self):
        return wikirst.format(

    def software(self):
        return SoftwareInfo(

    def template(self):
        return 'softwarepage.html'

    def extension(self, website, config):
        return None

class SoftwareInfo(object):
    def __init__(self, page): = page

    def version(self):
        ver ='software-version')
        if not ver:
            ver ='x-software-version')
        if not ver:
            ver = ''
        return ver

    def language(self):
        lang ='software-lang')
        if not lang:
            lang ='x-software-lang')
        if not lang:
            lang = ''
        return lang

    def downloads(self):
        dl = ('downloads') or '').strip()
        if not dl:
            return []
        return list(parse_reflist(dl))

    def dependencies(self):
        dp = ('dependencies') or '').strip()
        if not dp:
            return []
        return list(parse_reflist(dp))

    def sources(self):
        rcs ='software-rcs')
        if not rcs:
            return []
        if rcs in ('Hg', 'Mercurial'):
            return self._hgsources()
        raise ValueError('unexpected rcs name: %r' % rcs)

    def _hgsources(self):
        url ='software-rcs-url')
        if not url:
            return []
        return [
            ('Type <tt class="literal">hg clone %s</tt> at the command'
             ' prompt to get a copy of the development source code.') % url,
            '<a href="%s">Source Code Web View</a>' % url,

def parse_reflist(txt):
    for part in (d.strip() for d in txt.split(';')):
        if not part:
        tmatch ='(.+) <(.+)>', part.replace('\n', ' '))
        if not tmatch:
            raise ValueError('invalid section: %r' % part)
        label =
        url =
        yield (url, label)