""" Debian bug macro

Usage::

    [[Bug(number)]]

@copyright: 2007 by Nir Soffer <nirs@freeshell.org>
@license: GNU GPL
"""
from MoinMoin.wikiutil import escape

Dependencies = [] # static

def execute(macro, args):
    if args is None or args.strip() == '':
        bug = '?' # hint for editor
    else:
        bug = args.split(',', 1)[0].strip()

    url = 'http://bugs.debian.org/' + bug
    # formatter.url does not escape the title
    title = "Debian bug #" + escape(bug, 1) 
    formatter = macro.formatter
    
    return ''.join([formatter.url(1, url, type='www', title=title),
                    formatter.text('#' + bug),
                    formatter.url(0)])
