def get_name_and_version(filename):
    """Guess name and version of a package given its ``filename``."""
    idx = filename.rfind('.tar.gz')
    if idx == -1:
        idx = filename.rfind('.zip')
        if idx == -1:
            idx = filename.rfind('.tar.bz2')
            if idx == -1:
                idx = filename.rfind('.')
    name, version = filename[:idx].rsplit('-', 1)
    return {'name': name, 'version': version}