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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: human-input-validator
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Small validators for common human-entered data.
5
5
  Author: Snorlena
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "human-input-validator"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Small validators for common human-entered data."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -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 official name of an ISO 3166-1 country, given its name or code in any supported language."""
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.name
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.name
87
+ return _display_name(result)
81
88
 
82
89
 
83
90
  def username(value: str, max_length: int = 12) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: human-input-validator
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Small validators for common human-entered data.
5
5
  Author: Snorlena
6
6
  License-Expression: MIT