(self, query, *, require_city=False)
| 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 | """ |
no test coverage detected