def haxelib_download_url(name, version, baseurl='https://lib.haxe.org/p'):
    """
    Return an haxelib package tarball download URL given a namespace, name, version
    and a base registry URL.

    For example:
    >>> assert haxelib_download_url('format', '3.4.1') == u'https://lib.haxe.org/p/format/3.4.1/download/'
    """
    if name and version:
        baseurl = baseurl.rstrip('/')
        return '{baseurl}/{name}/{version}/download/'.format(**locals())
