MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_file_content

Function get_file_content

etc/scripts/utils_thirdparty.py:1869–1886  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1867
1868
1869def 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
1889def get_local_file_content(path, as_text=True):

Callers 1

getMethod · 0.85

Calls 3

get_local_file_contentFunction · 0.85
get_remote_file_contentFunction · 0.70
existsMethod · 0.45

Tested by

no test coverage detected