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
|
from . import config
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Country",
|
"Country",
|
||||||
"StrictCountry",
|
"StrictCountry",
|
||||||
"config",
|
"config",
|
||||||
|
"EmptyCountryException",
|
||||||
]
|
]
|
||||||
|
@ -17,6 +17,10 @@ def none_if_empty(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyCountryException(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Country:
|
class Country:
|
||||||
"""
|
"""
|
||||||
This gets countries based on the ISO 3166-1 standart.
|
This gets countries based on the ISO 3166-1 standart.
|
||||||
@ -39,7 +43,7 @@ class Country:
|
|||||||
|
|
||||||
|
|
||||||
if pycountry_object is None:
|
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
|
@classmethod
|
||||||
@ -85,13 +89,9 @@ class Country:
|
|||||||
def from_fuzzy(cls, fuzzy: str) -> Country:
|
def from_fuzzy(cls, fuzzy: str) -> Country:
|
||||||
return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy))
|
return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy))
|
||||||
|
|
||||||
@property
|
|
||||||
def is_empty(self) -> bool:
|
|
||||||
return self.pycountry_object is None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
@none_if_empty
|
||||||
def name(self) -> Optional[str]:
|
def name(self) -> str:
|
||||||
return self.pycountry_object.name
|
return self.pycountry_object.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user