Exemplo n.º 1
0
def originalurl(s):
    gcfg = git()
    urlkeys = filter(lambda x: x.startswith('url.'), gcfg.keys())
    if not urlkeys:
        return s # no alias
    # (url, alias)
    for urlkey in urlkeys:
        alias = gcfg[urlkey]
        url = util.regex_extract(ur'^url\.(.+)\.insteadof', urlkey)
        if url and s.startswith(alias):
            return s.replace(alias, url, 1)
    return s # not aliased?
Exemplo n.º 2
0
def templatetodic(s, mapping={}):
    s = util.rmcomment(s)
    lines = s.split(u'\n')
    d = {}
    name = None
    for line in lines:
        content = util.regex_extract(ur'^:(.+?):(.*)', line)
        if content:
            name = content[0].replace(u' ', u'_').lower()
            name = mapping.get(name, name)
            d[name] = content[1].strip(u' ')
        elif name is not None: # 継続行とみなす
            d[name] += u'\n' + line.rstrip(u' ')
    for k, v in d.items():
        d[k] = v.strip('\n')
        if len(d[k]) == 0: # stringであることを暗に
            del d[k]
    return d