Skip to content

Commit

Permalink
Switch to geoip2 5
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Jan 28, 2025
1 parent a4f3844 commit 58ac109
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions minfraud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@

import geoip2.models
import geoip2.records
from geoip2.mixins import SimpleEquality


class _Serializable(SimpleEquality):
class _Serializable:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and self.to_dict() == other.to_dict()

def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def to_dict(self) -> dict:
"""Returns a dict of the object suitable for serialization."""
result = {}
for key, value in self.__dict__.items():
if hasattr(value, "to_dict") and callable(value.to_dict):
if d := value.to_dict():
result[key] = d
elif hasattr(value, "raw"):
# geoip2 uses "raw" for historical reasons
if d := value.raw:
result[key] = d
elif isinstance(value, list):
ls = []
for e in value:
Expand Down Expand Up @@ -221,7 +222,7 @@ def __init__(
if risk_reasons is not None:
kwargs["risk_reasons"] = risk_reasons

super().__init__(kwargs, locales=list(locales or []))
super().__init__(locales, **kwargs)
self.location = GeoIP2Location(**(location or {}))
self.risk = risk
self.risk_reasons = [IPRiskReason(**x) for x in risk_reasons or []]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
dependencies = [
"aiohttp>=3.6.2,<4.0.0",
"email_validator>=2.0.0,<3.0.0",
"geoip2>=4.8.0,<5.0.0",
"geoip2>=5.0.1,<6.0.0",
"requests>=2.24.0,<3.0.0",
"voluptuous",
]
Expand Down

0 comments on commit 58ac109

Please sign in to comment.