# SPDX-FileCopyrightText: 2024-present Artur Drogunow <artur.drogunow@zf.com>
#
# SPDX-License-Identifier: MIT

from contextlib import AbstractContextManager
from types import TracebackType
from typing import Self

__version__: str

class PipeConnection(AbstractContextManager[PipeConnection]):
    def __init__(
        self,
        handle: int,
        readable: bool = True,
        writable: bool = True,
    ) -> None: ...
    def recv_bytes(self, blocking: bool = True) -> bytes | None: ...
    def send_bytes(
        self,
        buffer: bytes,
        offset: int = 0,
        size: int | None = None,
        blocking: bool = True,
    ) -> None: ...
    def close(self) -> None: ...
    def fileno(self) -> int: ...
    @property
    def readable(self) -> bool: ...
    @property
    def writable(self) -> bool: ...
    @property
    def closed(self) -> bool: ...
    def __enter__(self) -> Self: ...
    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> bool | None: ...

def generate_pipe_address() -> str: ...
def Pipe(duplex: bool = True) -> tuple[PipeConnection, PipeConnection]: ...

class PipeListener(AbstractContextManager[PipeListener]):
    def __init__(self, address: str, backlog: int | None = None) -> None: ...
    def accept(self) -> PipeConnection: ...
    def close(self) -> None: ...
    @property
    def address(self) -> str: ...
    @property
    def last_accepted(self) -> None: ...
    def __enter__(self) -> Self: ...
    def __exit__(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        traceback: TracebackType | None,
    ) -> bool | None: ...

def PipeClient(address: str) -> PipeConnection: ...
