Skip to content

Commit

Permalink
Early return on get_src_ip_country
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkst-tom committed Jul 24, 2024
1 parent 19e4e07 commit ab44bdf
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions canarytokens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ def get_src_ip_continent(geo_data: dict) -> str:
str: A two character code representing a continent
"""
country = geo_data.get("country")
if country is not None:
# AQ is the ISO 3166-2 code for Antarctica, and is returned from IPinfo,
# but it's not included in pycountry_convert.
if country == "AQ":
return "AN"
try:
return pycountry_convert.country_alpha2_to_continent_code(country)
except KeyError:
return "NO_CONTINENT"
else:
if country is None:
return "NO_CONTINENT"
# AQ is the ISO 3166-2 code for Antarctica, and is returned from IPinfo,
# but it's not included in pycountry_convert.
if country == "AQ":
return "AN"
try:
return pycountry_convert.country_alpha2_to_continent_code(country)
except KeyError:
return "NO_CONTINENT"

0 comments on commit ab44bdf

Please sign in to comment.