<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def localize_shapefile(shp_href, dirs):
 """ Given a shapefile href and a set of directories, modify the shapefile name so it's correct with respect to the output and cache directories. """

    # support latest mapnik features of auto-detection
    # of image sizes and jpeg reading support...
    # http://trac.mapnik.org/ticket/508

    mapnik_requires_absolute_paths = (MAPNIK_VERSION < 601)

    shp_href = urljoin(dirs.source.rstrip('/')+'/', shp_href)
    scheme, host, path, p, q, f = urlparse(shp_href)
    
    if scheme in ('http','https'):
        msg('%s | %s' % (shp_href, dirs.cache))
        scheme, path = '', locally_cache_remote_file(shp_href, dirs.cache)
    else:
        host = None
    
    # collect drive for windows
    to_posix(systempath.realpath(path))

    if scheme not in ('file', ''):
        raise Exception("Shapefile needs to be local, not %s" % shp_href)
        
    if mapnik_requires_absolute_paths:
        path = posixpath.realpath(path)
        original = path

    path = dirs.output_path(path)
    
    if path.endswith('.zip'):
        # unzip_shapefile_into needs a path it can find
        path = posixpath.join(dirs.output, path)
        path = unzip_shapefile_into(path, dirs.cache, host)

    return dirs.output_path(path)