Exemplo n.º 1
0
def latest_dataset():
    """Retrive the latest CLDR dataset and provide a ZipFile interface, handling cleanup automatically.
	
	This streams the dataset into a temporary file before wrapping it in the ZipFile interface.
	"""
    spool = TemporaryFile(prefix='cldr', suffix='.zip')
    version, latest = get_latest_version_url()

    with Session() as http:
        response = http.get(latest, stream=True)

        for chunk in response.iter_content(chunk_size=4096):
            if chunk: spool.write(chunk)

    # Write out any uncommitted data, then return to the beginning.
    spool.flush()
    spool.seek(0)

    zipfile = ZipFile(spool, 'r')
    zipfile.version = version  # Expose the version number through to consumers of the ZipFile.

    yield zipfile

    zipfile.close()
    spool.close()