diff options
| author | natsuoto <[email protected]> | 2026-07-11 15:59:00 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-11 15:59:00 +0530 |
| commit | 81a74f973612919ec5c4d4bccccd77b518f0a27e (patch) | |
| tree | 99186fcae1276d01048db54ab64da13cd6914487 | |
| parent | ec9b97096011257726479ccdc5bba43c69061634 (diff) | |
| download | edify-81a74f973612919ec5c4d4bccccd77b518f0a27e.tar.xz edify-81a74f973612919ec5c4d4bccccd77b518f0a27e.zip | |
feat(library/geo): 6 geo patterns (coordinate, geohash, plus, postal, place, altitude)
| -rw-r--r-- | edify/library/geo/__init__.py | 8 | ||||
| -rw-r--r-- | edify/library/geo/altitude.py | 8 | ||||
| -rw-r--r-- | edify/library/geo/coordinate.py | 11 | ||||
| -rw-r--r-- | edify/library/geo/geohash.py | 14 | ||||
| -rw-r--r-- | edify/library/geo/place.py | 8 | ||||
| -rw-r--r-- | edify/library/geo/plus.py | 10 | ||||
| -rw-r--r-- | edify/library/geo/postal.py | 21 |
7 files changed, 80 insertions, 0 deletions
diff --git a/edify/library/geo/__init__.py b/edify/library/geo/__init__.py new file mode 100644 index 0000000..624d7b6 --- /dev/null +++ b/edify/library/geo/__init__.py @@ -0,0 +1,8 @@ +from edify.library.geo.altitude import altitude +from edify.library.geo.coordinate import coordinate +from edify.library.geo.geohash import geohash +from edify.library.geo.place import place +from edify.library.geo.plus import plus +from edify.library.geo.postal import postal + +__all__ = ["altitude", "coordinate", "geohash", "place", "plus", "postal"] diff --git a/edify/library/geo/altitude.py b/edify/library/geo/altitude.py new file mode 100644 index 0000000..38b89de --- /dev/null +++ b/edify/library/geo/altitude.py @@ -0,0 +1,8 @@ +"""``altitude`` — altitude value shape (signed number, optional decimal, optional unit).""" + +from __future__ import annotations + +from edify.library._support.regex import RegexBackedPattern + +altitude = RegexBackedPattern(r"^-?\d+(?:\.\d+)?\s?(?:m|ft|km|mi)?$") +"""Callable :class:`Pattern` for a signed altitude value with optional unit.""" diff --git a/edify/library/geo/coordinate.py b/edify/library/geo/coordinate.py new file mode 100644 index 0000000..a6bf066 --- /dev/null +++ b/edify/library/geo/coordinate.py @@ -0,0 +1,11 @@ +"""``coordinate`` — latitude/longitude coordinate shape.""" + +from __future__ import annotations + +from edify.library._support.regex import RegexBackedPattern + +coordinate = RegexBackedPattern( + r"^-?(?:90(?:\.0+)?|[0-8]?\d(?:\.\d+)?)\s*,\s*" + r"-?(?:180(?:\.0+)?|(?:1[0-7]\d|[0-9]?\d)(?:\.\d+)?)$" +) +"""Callable :class:`Pattern` for the ``latitude,longitude`` coordinate shape.""" diff --git a/edify/library/geo/geohash.py b/edify/library/geo/geohash.py new file mode 100644 index 0000000..abf865b --- /dev/null +++ b/edify/library/geo/geohash.py @@ -0,0 +1,14 @@ +"""``geohash`` — geohash string shape (1–12 base32-encoded chars).""" + +from __future__ import annotations + +from edify import Pattern + +geohash = ( + Pattern() + .start_of_input() + .between(1, 12) + .any_of().range("0", "9").any_of_chars("bcdefghjkmnpqrstuvwxyz").end() + .end_of_input() +) +"""Callable :class:`Pattern` for the geohash string shape.""" diff --git a/edify/library/geo/place.py b/edify/library/geo/place.py new file mode 100644 index 0000000..8b187f3 --- /dev/null +++ b/edify/library/geo/place.py @@ -0,0 +1,8 @@ +"""``place`` — permissive place-name / locality shape.""" + +from __future__ import annotations + +from edify.library._support.regex import RegexBackedPattern + +place = RegexBackedPattern(r"^[A-Za-z][A-Za-z .,'\-]{1,99}$") +"""Callable :class:`Pattern` for a permissive place-name shape.""" diff --git a/edify/library/geo/plus.py b/edify/library/geo/plus.py new file mode 100644 index 0000000..52f8f35 --- /dev/null +++ b/edify/library/geo/plus.py @@ -0,0 +1,10 @@ +"""``plus`` — Google Plus Code (Open Location Code) shape.""" + +from __future__ import annotations + +from edify.library._support.regex import RegexBackedPattern + +plus = RegexBackedPattern( + r"^[23456789CFGHJMPQRVWX]{2,8}\+[23456789CFGHJMPQRVWX]{2,3}(?:\s+.+)?$" +) +"""Callable :class:`Pattern` for a Google Plus Code (Open Location Code).""" diff --git a/edify/library/geo/postal.py b/edify/library/geo/postal.py new file mode 100644 index 0000000..be8e869 --- /dev/null +++ b/edify/library/geo/postal.py @@ -0,0 +1,21 @@ +"""``postal`` — postal / ZIP code shape (accepts any known locale).""" + +from __future__ import annotations + +import re + +from edify.library._support.regex import RegexBackedPattern +from edify.library._support.zip import ZIP_LOCALES + +_alternatives: list[str] = [] +for _entry in ZIP_LOCALES: + _raw = _entry.get("zip") + if not _raw: + continue + _stripped = _raw.strip("^$") + _alternatives.append(f"(?:{_stripped})") + +postal = RegexBackedPattern(rf"^(?:{'|'.join(_alternatives)})$") +"""Callable :class:`Pattern` that accepts any known postal/ZIP shape by locale.""" + +del re, _alternatives, _entry, _raw, _stripped |
