human-input-validator 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/PKG-INFO +1 -1
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/pyproject.toml +1 -1
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/validators.py +10 -3
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator.egg-info/PKG-INFO +1 -1
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/README.md +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/setup.cfg +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/__init__.py +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/py.typed +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator.egg-info/SOURCES.txt +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator.egg-info/dependency_links.txt +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator.egg-info/requires.txt +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator.egg-info/top_level.txt +0 -0
- {human_input_validator-0.1.1 → human_input_validator-0.1.2}/tests/test_validators.py +0 -0
{human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/validators.py
RENAMED
|
@@ -54,12 +54,19 @@ def email(value: str) -> str:
|
|
|
54
54
|
_FUZZY_MATCH_CUTOFF = 0.8
|
|
55
55
|
|
|
56
56
|
|
|
57
|
+
def _display_name(entry: object) -> str:
|
|
58
|
+
"""Prefer the short common name (e.g. 'Tanzania') over the formal ISO name."""
|
|
59
|
+
common_name: str | None = getattr(entry, "common_name", None)
|
|
60
|
+
name: str = getattr(entry, "name")
|
|
61
|
+
return common_name or name
|
|
62
|
+
|
|
63
|
+
|
|
57
64
|
def country(value: str) -> str:
|
|
58
|
-
"""Return the
|
|
65
|
+
"""Return the common name of an ISO 3166-1 country, given its name or code in any supported language."""
|
|
59
66
|
normalized = value.strip()
|
|
60
67
|
try:
|
|
61
68
|
result = pycountry.countries.lookup(normalized)
|
|
62
|
-
return result
|
|
69
|
+
return _display_name(result)
|
|
63
70
|
except LookupError:
|
|
64
71
|
pass
|
|
65
72
|
|
|
@@ -77,7 +84,7 @@ def country(value: str) -> str:
|
|
|
77
84
|
result = pycountry.countries.get(alpha_2=alpha_2)
|
|
78
85
|
if result is None:
|
|
79
86
|
raise ValidationError("Please enter a valid country")
|
|
80
|
-
return result
|
|
87
|
+
return _display_name(result)
|
|
81
88
|
|
|
82
89
|
|
|
83
90
|
def username(value: str, max_length: int = 12) -> str:
|
|
File without changes
|
|
File without changes
|
{human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/__init__.py
RENAMED
|
File without changes
|
{human_input_validator-0.1.1 → human_input_validator-0.1.2}/src/human_input_validator/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|