Parse integer headers with a safe fallback.
(headers: Mapping[str, object], key: str)
| 244 | |
| 245 | |
| 246 | def _header_int(headers: Mapping[str, object], key: str) -> int: |
| 247 | """Parse integer headers with a safe fallback.""" |
| 248 | raw = headers.get(key) |
| 249 | if raw is None: |
| 250 | return 0 |
| 251 | if isinstance(raw, int): |
| 252 | return raw |
| 253 | if isinstance(raw, str | bytes | bytearray): |
| 254 | try: |
| 255 | return int(raw) |
| 256 | except ValueError: |
| 257 | return 0 |
| 258 | try: |
| 259 | return int(str(raw)) |
| 260 | except ValueError: |
| 261 | return 0 |
| 262 | |
| 263 | |
| 264 | def get_github_last_modified(owner: str, repo: str, path: str | None = None) -> str | None: |