1- """
2- Errors
3- ======
4-
5- """
1+ """Typed errors thrown by this library."""
62
73import ipaddress
8-
94from typing import Optional , Union
105
116
@@ -19,26 +14,12 @@ class GeoIP2Error(RuntimeError):
1914
2015
2116class AddressNotFoundError (GeoIP2Error ):
22- """The address you were looking up was not found.
23-
24- .. attribute:: ip_address
25-
26- The IP address used in the lookup. This is only available for database
27- lookups.
28-
29- :type: str
30-
31- .. attribute:: network
32-
33- The network associated with the error. In particular, this is the
34- largest network where no address would be found. This is only
35- available for database lookups.
36-
37- :type: ipaddress.IPv4Network or ipaddress.IPv6Network
38-
39- """
17+ """The address you were looking up was not found."""
4018
4119 ip_address : Optional [str ]
20+ """The IP address used in the lookup. This is only available for database
21+ lookups.
22+ """
4223 _prefix_len : Optional [int ]
4324
4425 def __init__ (
@@ -53,10 +34,16 @@ def __init__(
5334
5435 @property
5536 def network (self ) -> Optional [Union [ipaddress .IPv4Network , ipaddress .IPv6Network ]]:
56- """The network for the error."""
37+ """The network associated with the error.
38+
39+ In particular, this is the largest network where no address would be
40+ found. This is only available for database lookups.
41+ """
5742 if self .ip_address is None or self ._prefix_len is None :
5843 return None
59- return ipaddress .ip_network (f"{ self .ip_address } /{ self ._prefix_len } " , False )
44+ return ipaddress .ip_network (
45+ f"{ self .ip_address } /{ self ._prefix_len } " , strict = False
46+ )
6047
6148
6249class AuthenticationError (GeoIP2Error ):
@@ -69,12 +56,15 @@ class HTTPError(GeoIP2Error):
6956 This class represents an HTTP transport error. It extends
7057 :py:exc:`GeoIP2Error` and adds attributes of its own.
7158
72- :ivar http_status: The HTTP status code returned
73- :ivar uri: The URI queried
74- :ivar decoded_content: The decoded response content
75-
7659 """
7760
61+ http_status : Optional [int ]
62+ """The HTTP status code returned"""
63+ uri : Optional [str ]
64+ """The URI queried"""
65+ decoded_content : Optional [str ]
66+ """The decoded response content"""
67+
7868 def __init__ (
7969 self ,
8070 message : str ,
0 commit comments