MCPcopy Create free account
hub / github.com/mlco2/codecarbon / _check_external

Function _check_external

scripts/check_docs_links.py:150–169  ·  view source on GitHub ↗
(session: requests.Session, url: str)

Source from the content-addressed store, hash-verified

148
149
150def _check_external(session: requests.Session, url: str) -> tuple[bool, str]:
151 if url.startswith("http://localhost") or url.startswith("http://127.0.0.1"):
152 return True, "skip-localhost"
153 for pat in IGNORE_EXTERNAL_GLOBS:
154 if _matches_glob(url, pat):
155 return True, "ignored-glob"
156 try:
157 r = session.head(url, allow_redirects=True, timeout=REQUEST_TIMEOUT)
158 if r.status_code in (405, 501):
159 r = session.get(
160 url, allow_redirects=True, timeout=REQUEST_TIMEOUT, stream=True
161 )
162 r.close()
163 if r.status_code == 403 and _is_github_host(url):
164 return True, "skip-github-403"
165 if 200 <= r.status_code < 400:
166 return True, str(r.status_code)
167 return False, f"HTTP {r.status_code}"
168 except requests.RequestException as e:
169 return False, str(e)
170
171
172def collect_checks(site_root: Path) -> list[tuple[Path, str, str, str]]:

Callers 1

check_oneFunction · 0.85

Calls 2

_matches_globFunction · 0.85
_is_github_hostFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…