Compare commits

..

No commits in common. "4964d5a49420a4777e3b4c42c6f808f0a7d11f1e" and "d956ea6b2446734bbf68e1d0d476440a72addc8c" have entirely different histories.

3 changed files with 9 additions and 6 deletions

View File

@ -13,7 +13,7 @@ pip install pycountry-wrapper
## Usage ## Usage
```python ```python
from pycountry_wrapper import Country from pycountry_wrapper import Country, CountryDoesNotExist
germany = Country.from_alpha_2("DE") germany = Country.from_alpha_2("DE")
print(germany) print(germany)
@ -21,8 +21,8 @@ print(germany.name)
try: try:
does_not_exist = Country.from_alpha_2("EN") does_not_exist = Country.from_alpha_2("EN")
except ValueError: except CountryDoesNotExist:
# if the country wasn't found, a ValueError is raised # if the country wasn't found, this exception is thrown
pass pass
``` ```

View File

@ -1,2 +1,2 @@
__version__ = "0.0.3" __version__ = "0.0.2"
__name__ = "pycountry_wrapper" __name__ = "pycountry_wrapper"

View File

@ -1,6 +1,9 @@
from __future__ import annotations from __future__ import annotations
import pycountry import pycountry
class CountryDoesNotExist(Exception): 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.
@ -9,7 +12,7 @@ class Country:
- Country.from_alpha_2("DE") - Country.from_alpha_2("DE")
- Country.from_alpha_3("DEU") - Country.from_alpha_3("DEU")
If the country couldn't be found, it raises a ValueError. If the country couldn't be found, it raises the pycountry_wrapper.CountryDoesNotExist exception.
""" """
def __new__(cls, country: str = None, pycountry_object = None, silent: bool = False): def __new__(cls, country: str = None, pycountry_object = None, silent: bool = False):
@ -25,7 +28,7 @@ class Country:
if pycountry_object is None: if pycountry_object is None:
if silent: if silent:
return None return None
raise ValueError(f"Country {country} couldn't be found") raise CountryDoesNotExist()
self.pycountry_object = pycountry_object self.pycountry_object = pycountry_object
return self return self