"""Type stubs for the _transport_rs compiled Rust extension."""

import os
import sys
from collections.abc import Callable, Iterable, Iterator
from typing import IO, Literal

if sys.version_info >= (3, 11):
    from typing import Self
else:
    from typing_extensions import Self

def coalesce_offsets(
    offsets: list[tuple[int, int]],
    limit: int | None = None,
    fudge_factor: int | None = None,
    max_size: int | None = None,
) -> list[tuple[int, int, list[tuple[int, int]]]]: ...
def seek_and_read(
    file: IO[bytes],
    offsets: list[tuple[int, int]],
    max_readv_combine: int | None = None,
    bytes_to_read_before_seek: int | None = None,
    path: str | None = None,
) -> Iterator[tuple[int, bytes]]: ...
def sort_expand_and_combine(
    offsets: list[tuple[int, int]],
    upper_limit: int | None = None,
    recommended_page_size: int | None = None,
) -> list[tuple[int, int]]: ...
def get_test_permutations() -> list[tuple[type, type]]: ...

class _TransportBase:
    base: str

    def abspath(self, path: str) -> str: ...
    def append_bytes(self, path: str, bytes: bytes, mode: int | None = None) -> int: ...
    def append_file(
        self, path: str, file: IO[bytes], mode: int | None = None
    ) -> int: ...
    def clone(self, offset: str | None = None) -> Self: ...
    def copy(self, from_path: str, to_path: str) -> None: ...
    def copy_to(
        self,
        relpaths: Iterable[str],
        to_transport: _TransportBase,
        mode: int | None = None,
    ) -> int: ...
    def copy_tree(self, from_path: str, to_path: str) -> None: ...
    def copy_tree_to_transport(self, to_transport: _TransportBase) -> None: ...
    def create_prefix(self, mode: int | None = None) -> None: ...
    def delete(self, path: str) -> None: ...
    def delete_tree(self, path: str) -> None: ...
    def ensure_base(self, mode: int | None = None) -> bool: ...
    def external_url(self) -> str: ...
    def get(self, path: str) -> IO[bytes]: ...
    def get_bytes(self, path: str) -> bytes: ...
    def get_segment_parameters(self) -> dict[str, str]: ...
    def hardlink(self, from_path: str, to_path: str) -> None: ...
    def has(self, path: str) -> bool: ...
    def has_any(self, paths: Iterable[str]) -> bool: ...
    def is_readonly(self) -> bool: ...
    def iter_files_recursive(self) -> Iterator[str]: ...
    def list_dir(self, path: str) -> list[str]: ...
    def listable(self) -> bool: ...
    def local_abspath(self, path: str) -> str: ...
    def lock_read(self, path: str) -> object: ...
    def lock_write(self, path: str) -> object: ...
    def mkdir(self, path: str, mode: int | None = None) -> None: ...
    def move(self, from_path: str, to_path: str) -> None: ...
    def open_write_stream(self, path: str, mode: int | None = None) -> object: ...
    def put_bytes(self, path: str, data: bytes, mode: int | None = None) -> int: ...
    def put_bytes_non_atomic(
        self,
        path: str,
        data: bytes,
        mode: int | None = None,
        create_parent_dir: bool | None = None,
        dir_mode: int | None = None,
    ) -> None: ...
    def put_file(self, path: str, file: IO[bytes], mode: int | None = None) -> int: ...
    def put_file_non_atomic(
        self,
        path: str,
        file: IO[bytes],
        mode: int | None = None,
        create_parent_dir: bool | None = None,
        dir_mode: int | None = None,
    ) -> int | None: ...
    def readlink(self, path: str) -> str: ...
    def readv(
        self,
        path: str,
        offsets: list[tuple[int, int]],
        adjust_for_latency: bool | None = None,
        upper_limit: int | None = None,
    ) -> Iterator[tuple[int, bytes]]: ...
    def recommended_page_size(self) -> int: ...
    def relpath(self, path: str | None = None) -> str: ...
    def rename(self, from_path: str, to_path: str) -> None: ...
    def rmdir(self, path: str) -> None: ...
    def set_segment_parameter(self, name: str, value: str | None = None) -> None: ...
    def stat(self, path: str) -> os.stat_result: ...
    def symlink(self, from_path: str, to_path: str) -> None: ...

class _ConnectedTransportBase(Transport):
    def disconnect(self) -> None: ...
    def request(
        self,
        method: str,
        url: str,
        headers: dict[str, str] | None = None,
        body: bytes | None = None,
        follow_redirects: bool = False,
        report_activity: Callable[[int, Literal["read", "write"]], None] | None = None,
        fields: dict[str, str] | None = None,
        retries: int = 0,
        **kwargs: object,
    ) -> http.HttpResponse: ...

class Transport(_TransportBase): ...
class ConnectedTransport(_ConnectedTransportBase): ...
class TransportDecorator(_TransportBase): ...

class ReadLock:
    def unlock(self) -> None: ...

class WriteLock:
    def unlock(self) -> None: ...

class TemporaryWriteLock:
    def unlock(self) -> None: ...

class ReadvIter:
    def __iter__(self) -> ReadvIter: ...
    def __next__(self) -> tuple[int, bytes]: ...

class http:
    class HttpClient:
        def request(
            self,
            method: str,
            url: str,
            headers: dict[str, str] | None = None,
            body: bytes | None = None,
            follow_redirects: bool | None = None,
            report_activity: Callable[[int, Literal["read", "write"]], None]
            | None = None,
            **kwargs: object,
        ) -> http.HttpResponse: ...
        def set_default_follow_redirects(self, follow: bool) -> None: ...

    class HttpResponse:
        status: int
        redirected_to: str | None
        def close(self) -> None: ...
        def getheader(self, name: str, default: str | None = None) -> str | None: ...
        def getheaders(self) -> list[tuple[str, str]]: ...
        def read(self, size: int | None = None) -> bytes: ...
        def readline(self, size: int = ...) -> bytes: ...
        def readlines(self) -> list[bytes]: ...

    class HttpTransport(_ConnectedTransportBase):
        _unqualified_scheme: str
        def __new__(
            cls,
            base: str,
            ca_certs: str | None = None,
            disable_verification: bool = False,
            user_agent: str | None = None,
            **kwargs: object,
        ) -> Self: ...
        def _head(self, relpath: str) -> http.HttpResponse: ...
        def _post(self, relpath: str, body: bytes) -> tuple[int, bytes]: ...
        def _remote_path(self, relpath: str) -> str: ...
        def _clone_from(
            self, other: http.HttpTransport, offset: str | None
        ) -> None: ...
        def _set_activity_callback(
            self, callback: Callable[[int, Literal["read", "write"]], None]
        ) -> None: ...
        def _get_bytes_inner(self, relpath: str) -> bytes: ...

    class RangeFile:
        def __enter__(self) -> http.RangeFile: ...
        def __exit__(
            self, exc_type: object = None, exc_val: object = None, exc_tb: object = None
        ) -> None: ...
        def close(self) -> None: ...
        def read(self, size: int = ...) -> bytes: ...
        def read_boundary(self) -> None: ...
        def read_range_definition(self) -> None: ...
        def seek(self, offset: int, whence: int = 0) -> None: ...
        def set_boundary(self, boundary: bytes) -> None: ...
        def set_range(self, start: int, size: int) -> None: ...
        def set_range_from_header(self, content_range: str) -> None: ...
        def tell(self) -> int: ...

    class ResponseFile:
        def __enter__(self) -> http.ResponseFile: ...
        def __exit__(
            self, exc_type: object = None, exc_val: object = None, exc_tb: object = None
        ) -> None: ...
        def __iter__(self) -> Iterator[bytes]: ...
        def close(self) -> None: ...
        def read(self, size: int | None = None) -> bytes: ...
        def readline(self) -> bytes: ...
        def readlines(self, size: int | None = None) -> list[bytes]: ...
        def seek(self, offset: int, whence: int = 0) -> None: ...
        def tell(self) -> int: ...

    SSL_CA_CERTS_KNOWN_LOCATIONS: list[str]

    @staticmethod
    def clear_ca_path_cache() -> None: ...
    @staticmethod
    def default_ca_certs() -> str: ...
    @staticmethod
    def default_cert_reqs() -> int: ...
    @staticmethod
    def default_user_agent() -> str: ...
    @staticmethod
    def digest_algorithm_supported(algorithm: str) -> bool: ...
    @staticmethod
    def digest_h(algorithm: str, data: str) -> str: ...
    @staticmethod
    def digest_kd(algorithm: str, secret: str, data: str) -> str: ...
    @staticmethod
    def evaluate_proxy_bypass(host: str, no_proxy: str) -> bool: ...
    @staticmethod
    def get_ca_path(use_cache: bool = True) -> str: ...
    @staticmethod
    def get_credential_lookup() -> (
        Callable[..., tuple[str | None, str | None]] | None
    ): ...
    @staticmethod
    def get_credentials(
        protocol: str,
        host: str,
        port: int | None = None,
        path: str | None = None,
        realm: str | None = None,
    ) -> tuple[str | None, str | None]: ...
    @staticmethod
    def get_negotiate_provider() -> Callable[[str], str | None] | None: ...
    @staticmethod
    def get_new_cnonce(nonce: str, nonce_count: int) -> str: ...
    @staticmethod
    def get_token_provider() -> Callable[..., tuple[str | None, str | None]] | None: ...
    @staticmethod
    def handle_response(
        url: str, code: int, getheader: Callable[[str], str | None], data: IO[bytes]
    ) -> IO[bytes]: ...
    @staticmethod
    def parse_auth_header(header: str) -> tuple[str, dict[str, str]]: ...
    @staticmethod
    def parse_http_list(s: str) -> list[str]: ...
    @staticmethod
    def parse_keqv_list(items: list[str]) -> dict[str, str]: ...
    @staticmethod
    def set_auth_header_trace(func: Callable[[str], None] | None) -> None: ...
    @staticmethod
    def set_credential_lookup(
        func: Callable[..., tuple[str | None, str | None]] | None,
    ) -> None: ...
    @staticmethod
    def set_negotiate_provider(func: Callable[[str], str | None] | None) -> None: ...
    @staticmethod
    def set_token_provider(
        func: Callable[..., tuple[str | None, str | None]] | None,
    ) -> None: ...
    @staticmethod
    def set_user_agent(prefix: str) -> None: ...
    @staticmethod
    def splitport(host: str) -> tuple[str, int | None]: ...

class memory:
    class MemoryStoreHandle: ...

    class MemoryTransport(_TransportBase):
        def __init__(
            self, url: str, _shared_store: memory.MemoryStoreHandle | None = None
        ) -> None: ...

class local:
    class LocalTransport(_TransportBase):
        @classmethod
        def from_abspath(cls, abspath: str) -> local.LocalTransport: ...

class urlutils:
    class URL:
        scheme: str
        user: str | None
        password: str | None
        quoted_password: str | None
        host: str
        port: int | None
        path: str

        @classmethod
        def from_string(cls, url: str) -> urlutils.URL: ...
        def clone(self, offset: str | None = None) -> urlutils.URL: ...
        def __str__(self) -> str: ...

    @staticmethod
    def basename(url: str, exclude_trailing_slash: bool = True) -> str: ...
    @staticmethod
    def combine_paths(base_path: str, relpath: str) -> str: ...
    @staticmethod
    def derive_to_location(base: str) -> str: ...
    @staticmethod
    def dirname(url: str, exclude_trailing_slash: bool = True) -> str: ...
    @staticmethod
    def escape(text: str, safe: str | None = None) -> str: ...
    @staticmethod
    def file_relpath(base: str, path: str) -> str: ...
    @staticmethod
    def is_url(url: str) -> bool: ...
    @staticmethod
    def join(url: str, *args: str) -> str: ...
    @staticmethod
    def join_segment_parameters(url: str, parameters: dict[str, str]) -> str: ...
    @staticmethod
    def join_segment_parameters_raw(url: str, *args: str) -> str: ...
    @staticmethod
    def joinpath(url: str, *args: str) -> str: ...
    @staticmethod
    def local_path_from_url(url: str) -> str: ...
    @staticmethod
    def local_path_to_url(path: str) -> str: ...
    @staticmethod
    def normalize_url(url: str) -> str: ...
    @staticmethod
    def parse_url(
        url: str,
    ) -> tuple[str, str | None, str | None, str, int | None, str]: ...
    @staticmethod
    def relative_url(base: str, url: str) -> str: ...
    @staticmethod
    def split(url: str, exclude_trailing_slash: bool = True) -> tuple[str, str]: ...
    @staticmethod
    def split_segment_parameters(url: str) -> tuple[str, dict[str, str]]: ...
    @staticmethod
    def split_segment_parameters_raw(url: str) -> tuple[str, list[str]]: ...
    @staticmethod
    def strip_segment_parameters(url: str) -> str: ...
    @staticmethod
    def strip_trailing_slash(url: str) -> str: ...
    @staticmethod
    def unescape(text: str) -> str: ...

    posix: object
    win32: object

class brokenrename:
    class BrokenRenameTransportDecorator(_TransportBase): ...

class fakenfs:
    class FakeNFSTransportDecorator(_TransportBase): ...

class fakevfat:
    class FakeVFATTransportDecorator(_TransportBase): ...

class log:
    class TransportLogDecorator(_TransportBase): ...

class readonly:
    class ReadonlyTransportDecorator(_TransportBase): ...

class unlistable:
    class UnlistableTransportDecorator(_TransportBase): ...

class pathfilter:
    class ChrootTransport(_TransportBase): ...
    class PathFilteringTransport(_TransportBase): ...

class ssh:
    class LSHSubprocessVendor:
        executable_path: str | None
        def connect_ssh(
            self, username: str, host: str, command: list[str], port: int | None = None
        ) -> ssh.SSHSubprocessConnection: ...
        def spawn_sftp(
            self, username: str, host: str, port: int | None = None
        ) -> int: ...

    class LoopbackVendor:
        def spawn_sftp(self, host: str, port: int) -> int: ...

    class OpenSSHSubprocessVendor:
        executable_path: str | None
        def connect_ssh(
            self, username: str, host: str, command: list[str], port: int | None = None
        ) -> ssh.SSHSubprocessConnection: ...
        def spawn_sftp(
            self, username: str, host: str, port: int | None = None
        ) -> int: ...

    class PLinkSubprocessVendor:
        executable_path: str | None
        def connect_ssh(
            self, username: str, host: str, command: list[str], port: int | None = None
        ) -> ssh.SSHSubprocessConnection: ...
        def spawn_sftp(
            self, username: str, host: str, port: int | None = None
        ) -> int: ...

    class RusshSSHConnection:
        def close(self) -> None: ...
        def recv(self, count: int) -> bytes: ...
        def send(self, data: bytes) -> int: ...

    class RusshVendor:
        def connect_sftp(
            self,
            username: str,
            password: str | None,
            host: str,
            port: int | None = None,
        ) -> sftp.SFTPClient: ...
        def connect_ssh(
            self,
            username: str,
            password: str | None,
            host: str,
            command: list[str],
            port: int | None = None,
        ) -> ssh.RusshSSHConnection: ...

    class SSHSubprocessConnection:
        def close(self) -> None: ...
        def detach_fd(self) -> int: ...
        def wait(self) -> int: ...

    @staticmethod
    def classify_ssh_version(version: str, progname: str) -> str: ...
    @staticmethod
    def detect_ssh_vendor(executable: str) -> object: ...

class sftp:
    class SFTPAttributes:
        st_size: int | None
        st_uid: int | None
        st_gid: int | None
        st_mode: int | None
        st_atime: float | None
        st_mtime: float | None

    class SFTPClient:
        def __init__(self, fd: int) -> None: ...
        def chmod(self, path: str, mode: int) -> None: ...
        def close(self) -> None: ...
        def extended(self, extension: str, data: bytes) -> bytes: ...
        def file(
            self, path: str, mode: str | None = None, create_mode: int | None = None
        ) -> IO[bytes]: ...
        def hardlink(self, oldpath: str, newpath: str) -> None: ...
        def listdir(self, path: str) -> list[sftp.SFTPAttributes]: ...
        def lstat(self, path: str, flags: int | None = None) -> sftp.SFTPAttributes: ...
        def mkdir(self, path: str, mode: int | None = None) -> None: ...
        def open(
            self,
            path: str,
            attr: sftp.SFTPAttributes,
            *,
            read: bool = False,
            write: bool = False,
            append: bool = False,
            create: bool = False,
            truncate: bool = False,
            excl: bool = False,
        ) -> IO[bytes]: ...
        def opendir(self, path: str) -> object: ...
        def readlink(self, path: str) -> str: ...
        def realpath(
            self,
            path: str,
            control_byte: int | None = None,
            compose_path: str | None = None,
        ) -> str: ...
        def remove(self, path: str) -> None: ...
        def rename(
            self, oldpath: str, newpath: str, flags: int | None = None
        ) -> None: ...
        def rmdir(self, path: str) -> None: ...
        def setstat(self, path: str, attr: sftp.SFTPAttributes) -> None: ...
        def stat(self, path: str, flags: int | None = None) -> sftp.SFTPAttributes: ...
        def symlink(self, oldpath: str, newpath: str) -> None: ...

    class SFTPError(Exception): ...

class webdav:
    class HttpDavTransport(_ConnectedTransportBase):
        def __new__(
            cls,
            base: str,
            ca_certs: str | None = None,
            disable_verification: bool = False,
            user_agent: str | None = None,
        ) -> Self: ...
        def _clone_from(
            self, other: webdav.HttpDavTransport, offset: str | None
        ) -> None: ...
        def _set_activity_callback(
            self, callback: Callable[[int, Literal["read", "write"]], None]
        ) -> None: ...
        def _get_bytes(self, relpath: str) -> bytes: ...
        def put_bytes(
            self, relpath: str, data: bytes, mode: int | None = None
        ) -> int: ...
        def put_bytes_non_atomic(
            self,
            relpath: str,
            data: bytes,
            mode: int | None = None,
            create_parent_dir: bool | None = None,
            dir_mode: int | None = None,
        ) -> None: ...
        def append_bytes(
            self, relpath: str, data: bytes, mode: int | None = None
        ) -> int: ...

class gio:
    def __getattr__(self, name: str) -> object: ...
