def METHOD_NAME(url, directory=None, temp_directory=None, extension=None):
    import urllib2
    import tempfile
    try:
        response = urllib2.urlopen(url)
        filename = os.path.basename(urllib2.urlparse.urlparse(response.url).path)
    except Exception, e:
        return (e, None, None)
    if extension and not filename.endswith("%s" % extension):
        return (ValueError("The requested filename does not have the correct extension (%s)" % extension), None, None)
    if directory is None:
        directory = tempfile.mkdtemp(dir=temp_directory)
    if os.path.exists(os.path.join(directory, filename)):
        return (ValueError("The requested filename already exists in the target directory."), None, None)
    try:
        subprocess.check_call("wget -P %s %s" % (directory, url), shell=True)
        return (None, filename, directory)
    except subprocess.CalledProcessError, e:
        return (e, None, None)