generated from Hazel/python-project
config_default_behaviour #1
@ -1,8 +1,9 @@
|
||||
from .country import Country, StrictCountry
|
||||
from .country import Country, StrictCountry, EmptyCountryException
|
||||
from . import config
|
||||
|
||||
__all__ = [
|
||||
"Country",
|
||||
"StrictCountry",
|
||||
"config",
|
||||
"EmptyCountryException",
|
||||
]
|
||||
|
@ -17,6 +17,10 @@ def none_if_empty(func):
|
||||
return wrapper
|
||||
|
||||
|
||||
class EmptyCountryException(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class Country:
|
||||
"""
|
||||
This gets countries based on the ISO 3166-1 standart.
|
||||
@ -39,7 +43,7 @@ class Country:
|
||||
|
||||
|
||||
if pycountry_object is None:
|
||||
raise ValueError(f"Country {country} couldn't be found")
|
||||
raise EmptyCountryException(f"the country {country} was not found and config.fallback_country isn't set")
|
||||
|
||||
|
||||
@classmethod
|
||||
@ -85,13 +89,9 @@ class Country:
|
||||
def from_fuzzy(cls, fuzzy: str) -> Country:
|
||||
return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy))
|
||||
|
||||
@property
|
||||
def is_empty(self) -> bool:
|
||||
return self.pycountry_object is None
|
||||
|
||||
@property
|
||||
@none_if_empty
|
||||
def name(self) -> Optional[str]:
|
||||
def name(self) -> str:
|
||||
return self.pycountry_object.name
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user