MCPcopy
hub / github.com/django/django / _query

Method _query

django/contrib/gis/geoip2.py:144–162  ·  view source on GitHub ↗
(self, query, *, require_city=False)

Source from the content-addressed store, hash-verified

142 return "Country" in self._metadata.database_type
143
144 def _query(self, query, *, require_city=False):
145 if not isinstance(query, (str, ipaddress.IPv4Address, ipaddress.IPv6Address)):
146 raise TypeError(
147 "GeoIP query must be a string or instance of IPv4Address or "
148 "IPv6Address, not type %s" % type(query).__name__,
149 )
150
151 if require_city and not self.is_city:
152 raise GeoIP2Exception(f"Invalid GeoIP city data file: {self._path}")
153
154 if isinstance(query, str):
155 try:
156 validate_ipv46_address(query)
157 except ValidationError:
158 # GeoIP2 only takes IP addresses, so try to resolve a hostname.
159 query = socket.gethostbyname(query)
160
161 function = self._reader.city if self.is_city else self._reader.country
162 return function(query)
163
164 def city(self, query):
165 """

Callers 2

cityMethod · 0.95
countryMethod · 0.95

Calls 3

validate_ipv46_addressFunction · 0.90
GeoIP2ExceptionClass · 0.85
functionFunction · 0.85

Tested by

no test coverage detected