Fetch content at ``path_or_url`` URL or path and save this to ``dest_dir/filername``. Return the fetched content. Raise an Exception on errors. Treats the content as text if as_text is True otherwise as treat as binary.
(
path_or_url,
dest_dir,
filename,
as_text=True,
)
| 1949 | |
| 1950 | |
| 1951 | def fetch_and_save( |
| 1952 | path_or_url, |
| 1953 | dest_dir, |
| 1954 | filename, |
| 1955 | as_text=True, |
| 1956 | ): |
| 1957 | """ |
| 1958 | Fetch content at ``path_or_url`` URL or path and save this to |
| 1959 | ``dest_dir/filername``. Return the fetched content. Raise an Exception on |
| 1960 | errors. Treats the content as text if as_text is True otherwise as treat as |
| 1961 | binary. |
| 1962 | """ |
| 1963 | content = CACHE.get( |
| 1964 | path_or_url=path_or_url, |
| 1965 | as_text=as_text, |
| 1966 | ) |
| 1967 | output = os.path.join(dest_dir, filename) |
| 1968 | wmode = "w" if as_text else "wb" |
| 1969 | with open(output, wmode) as fo: |
| 1970 | fo.write(content) |
| 1971 | return content |
| 1972 | |
| 1973 | |
| 1974 | ################################################################################ |
no test coverage detected