|
| 1 | +from collections.abc import Sequence |
| 2 | +from ipaddress import IPv4Address, IPv6Address |
| 3 | +from typing import Final, TypedDict |
| 4 | + |
| 5 | +from _typeshed import StrPath |
| 6 | +from django.contrib.gis.geos import Point |
| 7 | +from django.utils.functional import cached_property |
| 8 | +from typing_extensions import Self, TypeAlias, deprecated |
| 9 | + |
| 10 | +HAS_GEOIP2: bool |
| 11 | +SUPPORTED_DATABASE_TYPES: set[str] |
| 12 | + |
| 13 | +_CoordType: TypeAlias = tuple[float, float] | tuple[None, None] |
| 14 | +_QueryType: TypeAlias = str | IPv4Address | IPv6Address |
| 15 | + |
| 16 | +class _CityResponse(TypedDict): |
| 17 | + accuracy_radius: int | None |
| 18 | + city: str |
| 19 | + continent_code: str |
| 20 | + continent_name: str |
| 21 | + country_code: str |
| 22 | + country_name: str |
| 23 | + is_in_european_union: bool |
| 24 | + latitude: float |
| 25 | + longitude: float |
| 26 | + metro_code: int | None |
| 27 | + postal_code: str | None |
| 28 | + region_code: str | None |
| 29 | + region_name: str | None |
| 30 | + time_zone: str | None |
| 31 | + # Kept for backward compatibility. |
| 32 | + dma_code: int | None |
| 33 | + region: str | None |
| 34 | + |
| 35 | +class _CountryResponse(TypedDict): |
| 36 | + continent_code: str |
| 37 | + continent_name: str |
| 38 | + country_code: str |
| 39 | + country_name: str |
| 40 | + is_in_european_union: bool |
| 41 | + |
| 42 | +class GeoIP2Exception(Exception): ... |
| 43 | + |
| 44 | +class GeoIP2: |
| 45 | + MODE_AUTO: Final = 0 |
| 46 | + MODE_MMAP_EXT: Final = 1 |
| 47 | + MODE_MMAP: Final = 2 |
| 48 | + MODE_FILE: Final = 4 |
| 49 | + MODE_MEMORY: Final = 8 |
| 50 | + cache_options: Final[frozenset[int]] |
| 51 | + |
| 52 | + def __init__( |
| 53 | + self, |
| 54 | + path: StrPath | None = None, |
| 55 | + cache: int = 0, |
| 56 | + country: str | None = None, |
| 57 | + city: str | None = None, |
| 58 | + ) -> None: ... |
| 59 | + def __del__(self) -> None: ... |
| 60 | + @cached_property |
| 61 | + def is_city(self) -> bool: ... |
| 62 | + @cached_property |
| 63 | + def is_country(self) -> bool: ... |
| 64 | + def city(self, query: _QueryType) -> _CityResponse: ... |
| 65 | + def country_code(self, query: _QueryType) -> str: ... |
| 66 | + def country_name(self, query: _QueryType) -> str: ... |
| 67 | + def country(self, query: _QueryType) -> _CountryResponse: ... |
| 68 | + @deprecated("coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.") |
| 69 | + def coords(self, query: _QueryType, ordering: Sequence[str] = ...) -> _CoordType: ... |
| 70 | + def lon_lat(self, query: _QueryType) -> _CoordType: ... |
| 71 | + def lat_lon(self, query: _QueryType) -> _CoordType: ... |
| 72 | + def geos(self, query: _QueryType) -> Point: ... |
| 73 | + @classmethod |
| 74 | + @deprecated("open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.") |
| 75 | + def open(cls, full_path: StrPath | None, cache: int) -> Self: ... |
0 commit comments