Revised stubs for geoip2 third party library (#3317)

This commit is contained in:
Vasily Zakharov
2019-10-10 05:28:42 +03:00
committed by Jelle Zijlstra
parent f0ccb325aa
commit 57384ce033
17 changed files with 368 additions and 41 deletions
View File
+22
View File
@@ -0,0 +1,22 @@
from types import TracebackType
from typing import Optional, Sequence, Text, Type
from maxminddb.reader import Metadata
from geoip2.models import AnonymousIP, ASN, City, ConnectionType, Country, Domain, Enterprise, ISP
_Locales = Optional[Sequence[Text]]
class Reader:
def __init__(self, filename: Text, locales: _Locales = ..., mode: int = ...) -> None: ...
def __enter__(self) -> Reader: ...
def __exit__(self, exc_type: Optional[Type[BaseException]] = ..., exc_val: Optional[BaseException] = ..., exc_tb: Optional[TracebackType] = ...) -> None: ...
def country(self, ip_address: Text) -> Country: ...
def city(self, ip_address: Text) -> City: ...
def anonymous_ip(self, ip_address: Text) -> AnonymousIP: ...
def asn(self, ip_address: Text) -> ASN: ...
def connection_type(self, ip_address: Text) -> ConnectionType: ...
def domain(self, ip_address: Text) -> Domain: ...
def enterprise(self, ip_address: Text) -> Enterprise: ...
def isp(self, ip_address: Text) -> ISP: ...
def metadata(self) -> Metadata: ...
def close(self) -> None: ...
+18
View File
@@ -0,0 +1,18 @@
from typing import Optional, Text
class GeoIP2Error(RuntimeError): ...
class AddressNotFoundError(GeoIP2Error): ...
class AuthenticationError(GeoIP2Error): ...
class HTTPError(GeoIP2Error):
http_status: Optional[int]
uri: Optional[Text]
def __init__(self, message: Text, http_status: Optional[int] = ..., uri: Optional[Text] = ...) -> None: ...
class InvalidRequestError(GeoIP2Error): ...
class OutOfQueriesError(GeoIP2Error): ...
class PermissionRequiredError(GeoIP2Error): ...
+3
View File
@@ -0,0 +1,3 @@
class SimpleEquality:
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
+65
View File
@@ -0,0 +1,65 @@
from typing import Any, Mapping, Optional, Sequence, Text
from geoip2 import records
from geoip2.mixins import SimpleEquality
_Locales = Optional[Sequence[Text]]
_RawResponse = Mapping[Text, Mapping[Text, Any]]
class Country(SimpleEquality):
continent: records.Continent
country: records.Country
registered_country: records.Country
represented_country: records.RepresentedCountry
maxmind: records.MaxMind
traits: records.Traits
raw: _RawResponse
def __init__(self, raw_response: _RawResponse, locales: _Locales = ...) -> None: ...
class City(Country):
city: records.City
location: records.Location
postal: records.Postal
subdivisions: records.Subdivisions
def __init__(self, raw_response: _RawResponse, locales: _Locales = ...) -> None: ...
class Insights(City): ...
class Enterprise(City): ...
class SimpleModel(SimpleEquality): ...
class AnonymousIP(SimpleModel):
is_anonymous: bool
is_anonymous_vpn: bool
is_hosting_provider: bool
is_public_proxy: bool
is_tor_exit_node: bool
ip_address: Optional[Text]
raw: _RawResponse
def __init__(self, raw: _RawResponse) -> None: ...
class ASN(SimpleModel):
autonomous_system_number: Optional[int]
autonomous_system_organization: Optional[Text]
ip_address: Optional[Text]
raw: _RawResponse
def __init__(self, raw: _RawResponse) -> None: ...
class ConnectionType(SimpleModel):
connection_type: Optional[Text]
ip_address: Optional[Text]
raw: _RawResponse
def __init__(self, raw: _RawResponse) -> None: ...
class Domain(SimpleModel):
domain: Optional[Text]
ip_address: Optional[Text]
raw: Optional[Text]
def __init__(self, raw: _RawResponse) -> None: ...
class ISP(ASN):
isp: Optional[Text]
organization: Optional[Text]
def __init__(self, raw: _RawResponse) -> None: ...
+83
View File
@@ -0,0 +1,83 @@
from typing import Any, Mapping, Optional, Sequence, Text, Tuple
from geoip2.mixins import SimpleEquality
_Locales = Optional[Sequence[Text]]
_Names = Mapping[Text, Text]
class Record(SimpleEquality):
def __init__(self, **kwargs: Any) -> None: ...
def __setattr__(self, name: Text, value: Any) -> None: ...
class PlaceRecord(Record):
def __init__(self, locales: _Locales = ..., **kwargs: Any) -> None: ...
@property
def name(self) -> Text: ...
class City(PlaceRecord):
confidence: int
geoname_id: int
names: _Names
class Continent(PlaceRecord):
code: Text
geoname_id: int
names: _Names
class Country(PlaceRecord):
confidence: int
geoname_id: int
is_in_european_union: bool
iso_code: Text
names: _Names
def __init__(self, locales: _Locales = ..., **kwargs: Any) -> None: ...
class RepresentedCountry(Country):
type: Text
class Location(Record):
average_income: int
accuracy_radius: int
latitude: float
longitude: float
metro_code: int
population_density: int
time_zone: Text
class MaxMind(Record):
queries_remaining: int
class Postal(Record):
code: Text
confidence: int
class Subdivision(PlaceRecord):
confidence: int
geoname_id: int
iso_code: Text
names: _Names
class Subdivisions(Tuple[Subdivision]):
def __new__(cls, locales: _Locales, *subdivisions: Subdivision) -> Subdivisions: ...
def __init__(self, locales: _Locales, *subdivisions: Subdivision) -> None: ...
@property
def most_specific(self) -> Subdivision: ...
class Traits(Record):
autonomous_system_number: int
autonomous_system_organization: Text
connection_type: Text
domain: Text
ip_address: Text
is_anonymous: bool
is_anonymous_proxy: bool
is_anonymous_vpn: bool
is_hosting_provider: bool
is_legitimate_proxy: bool
is_public_proxy: bool
is_satellite_provider: bool
is_tor_exit_node: bool
isp: Text
organization: Text
user_type: Text
def __init__(self, **kwargs: Any) -> None: ...
+7
View File
@@ -0,0 +1,7 @@
from typing import Text
from maxminddb import reader
def open_database(database: Text, mode: int = ...) -> reader.Reader: ...
def Reader(database: Text) -> reader.Reader: ...
+8
View File
@@ -0,0 +1,8 @@
from ipaddress import IPv4Address, IPv6Address
from typing import Any
def compat_ip_address(address: object) -> Any: ...
def int_from_byte(x: int) -> int: ...
def int_from_bytes(x: bytes) -> int: ...
def byte_from_int(x: int) -> bytes: ...
+6
View File
@@ -0,0 +1,6 @@
MODE_AUTO: int = ...
MODE_MMAP_EXT: int = ...
MODE_MMAP: int = ...
MODE_FILE: int = ...
MODE_MEMORY: int = ...
MODE_FD: int = ...
+5
View File
@@ -0,0 +1,5 @@
from typing import Any, Tuple
class Decoder:
def __init__(self, database_buffer: bytes, pointer_base: int = ..., pointer_test: bool = ...) -> None: ...
def decode(self, offset: int) -> Tuple[Any, int]: ...
+1
View File
@@ -0,0 +1 @@
class InvalidDatabaseError(RuntimeError): ...
+33
View File
@@ -0,0 +1,33 @@
from typing import Any, Mapping, Sequence, Text
from maxminddb.errors import InvalidDatabaseError as InvalidDatabaseError
class Reader:
closed: bool = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def close(self, *args: Any, **kwargs: Any) -> Any: ...
def get(self, *args: Any, **kwargs: Any) -> Any: ...
def metadata(self, *args: Any, **kwargs: Any) -> Any: ...
def __enter__(self, *args: Any, **kwargs: Any) -> Any: ...
def __exit__(self, *args: Any, **kwargs: Any) -> Any: ...
class extension:
@property
def node_count(self) -> int: ...
@property
def record_size(self) -> int: ...
@property
def ip_version(self) -> int: ...
@property
def database_type(self) -> Text: ...
@property
def languages(self) -> Sequence[Text]: ...
@property
def binary_format_major_version(self) -> int: ...
@property
def binary_format_minor_version(self) -> int: ...
@property
def build_epoch(self) -> int: ...
@property
def description(self) -> Mapping[Text, Text]: ...
def __init__(self, **kwargs: Any) -> None: ...
+30
View File
@@ -0,0 +1,30 @@
from ipaddress import IPv4Address, IPv6Address
from types import TracebackType
from typing import Any, Mapping, Optional, Sequence, Text, Tuple, Type, Union
class Reader:
closed: bool = ...
def __init__(self, database: bytes, mode: int = ...) -> None: ...
def metadata(self) -> Metadata: ...
def get(self, ip_address: Union[Text, IPv4Address, IPv6Address]) -> Optional[Any]: ...
def get_with_prefix_len(self, ip_address: Union[Text, IPv4Address, IPv6Address]) -> Tuple[Optional[Any], int]: ...
def close(self) -> None: ...
def __enter__(self) -> Reader: ...
def __exit__(self, exc_type: Optional[Type[BaseException]] = ..., exc_val: Optional[BaseException] = ..., exc_tb: Optional[TracebackType] = ...) -> None: ...
class Metadata:
node_count: int = ...
record_size: int = ...
ip_version: int = ...
database_type: Text = ...
languages: Sequence[Text] = ...
binary_format_major_version: int = ...
binary_format_minor_version: int = ...
build_epoch: int = ...
description: Mapping[Text, Text] = ...
def __init__(self, **kwargs: Any) -> None: ...
@property
def node_byte_size(self) -> int: ...
@property
def search_tree_size(self) -> int: ...