Files
bot-bottle/bot_bottle/util.py
T
didericis-claude 5ac6c8199c
test / unit (pull_request) Successful in 33s
test / integration (pull_request) Successful in 43s
refactor: address PR review feedback — de-privatize helpers and rename modules
- Rename _manifest_util.py → manifest_util.py (module isn't private)
- Rename _as_json_object → as_json_object, _parse_git_upstream → parse_git_upstream,
  _parse_git_gate_config → parse_git_gate_config,
  _validate_unique_git_names → validate_unique_git_names,
  _validate_egress_routes → validate_egress_routes (none are private at
  module boundary — underscore prefix was a carry-over from the old
  monolithic manifest.py where everything lived in one namespace)
- Move _is_ip_literal → util.is_ip_literal (generic, belongs in the
  top-level util module)
- Update all import sites across manifest_*.py, manifest_extends.py,
  manifest_schema.py; existing callers of manifest.py are unaffected

All 867 unit tests pass.
2026-06-03 04:32:25 +00:00

28 lines
747 B
Python

"""Cross-cutting utility helpers used by multiple modules.
Top-level (i.e. backend-agnostic) — backend-specific helpers live one
level deeper, under their backend package."""
from __future__ import annotations
import ipaddress
import os
def is_ip_literal(value: str) -> bool:
try:
ipaddress.ip_address(value)
except ValueError:
return False
return True
def expand_tilde(path: str) -> str:
"""Expand a leading '~' to $HOME. Leaves paths without a leading
tilde unchanged. Falls back to the empty string if $HOME is unset
(callers should already have checked HOME if they care)."""
if path.startswith("~"):
home = os.environ.get("HOME", "")
return home + path[1:]
return path