Fetch and return the content at `path_or_url` from either a local path or a remote URL. Return the content as bytes is `as_text` is False.
(path_or_url, as_text=True)
| 1867 | |
| 1868 | |
| 1869 | def get_file_content(path_or_url, as_text=True): |
| 1870 | """ |
| 1871 | Fetch and return the content at `path_or_url` from either a local path or a |
| 1872 | remote URL. Return the content as bytes is `as_text` is False. |
| 1873 | """ |
| 1874 | if path_or_url.startswith("https://"): |
| 1875 | if TRACE_DEEP: |
| 1876 | print(f"Fetching: {path_or_url}") |
| 1877 | _headers, content = get_remote_file_content(url=path_or_url, as_text=as_text) |
| 1878 | return content |
| 1879 | |
| 1880 | elif path_or_url.startswith("file://") or ( |
| 1881 | path_or_url.startswith("/") and os.path.exists(path_or_url) |
| 1882 | ): |
| 1883 | return get_local_file_content(path=path_or_url, as_text=as_text) |
| 1884 | |
| 1885 | else: |
| 1886 | raise Exception(f"Unsupported URL scheme: {path_or_url}") |
| 1887 | |
| 1888 | |
| 1889 | def get_local_file_content(path, as_text=True): |
no test coverage detected