(spec_path)
Fetch a new specification or use the cache if it's current.

    Arguments:

        cache_path:

            the path to a cached specification
Fetch a new specification or use the cache if it's current.
Fetch a new specification or use the cache if it s current .
def fetch_or_load(spec_path):
    """
    Fetch a new specification or use the cache if it's current.

    Arguments:

        cache_path:

            the path to a cached specification
    """

    headers = {
        "User-Agent": "python-jsonschema v{} - documentation build v{}".format(
            metadata.version("jsonschema"),
            __version__,
        ),
    }

    with suppress(FileNotFoundError):
        modified = datetime.utcfromtimestamp(os.path.getmtime(spec_path))
        date = modified.strftime("%a, %d %b %Y %I:%M:%S UTC")
        headers["If-Modified-Since"] = date

    request = urllib.request.Request(VALIDATION_SPEC, headers=headers)
    response = urllib.request.urlopen(request, cafile=certifi.where())

    if response.code == 200:
        with open(spec_path, "w+b") as spec:
            spec.writelines(response)
            spec.seek(0)
            return html.parse(spec)

    with open(spec_path) as spec:
        return html.parse(spec)
def fetch_or_load ( spec_path ) : headers = { "User-Agent" : "python-jsonschema v{} - documentation build v{}" . format ( metadata . version ( "jsonschema" ) , __version__ , ) , } with suppress ( FileNotFoundError ) : modified = datetime . utcfromtimestamp ( os . path . getmtime ( spec_path ) ) date = modified . strftime ( "%a, %d %b %Y %I:%M:%S UTC" ) headers [ "If-Modified-Since" ] = date request = urllib . request . Request ( VALIDATION_SPEC , headers = headers ) response = urllib . request . urlopen ( request , cafile = certifi . where ( ) ) if response . code == 200 : with open ( spec_path , "w+b" ) as spec : spec . writelines ( response ) spec . seek ( 0 ) return html . parse ( spec ) with open ( spec_path ) as spec : return html . parse ( spec )