# Path: src/amcrest/config.py
# KEEPALIVE_COUNT = 5
# 
# KEEPALIVE_IDLE = 20
# 
# KEEPALIVE_INTERVAL = 10
# 
# MAX_RETRY_HTTP_CONNECTION = 3
# 
# TIMEOUT_HTTP_PROTOCOL = 6.05
# 
# Path: src/amcrest/exceptions.py
# class CommError(AmcrestError):
#     """A communication error occurred."""
# 
# class LoginError(AmcrestError):
#     """A login error occurred."""
# 
# Path: src/amcrest/utils.py
# def clean_url(url: str) -> str:
#     host = re.sub(r"^http[s]?://", "", url, flags=re.IGNORECASE)
#     host = re.sub(r"/$", "", host)
#     return host
# 
# def pretty(value: str, delimiter: str = "=") -> str:
#     """Format string key=value."""
#     return value.strip().rpartition(delimiter)[2]


import asyncio
import logging
import re
import socket
import threading
import httpx
import requests
from contextlib import asynccontextmanager
from typing import AsyncIterator, Optional, Tuple, Union
from requests.adapters import HTTPAdapter
from urllib3.connection import HTTPConnection
from .config import (
    KEEPALIVE_COUNT,
    KEEPALIVE_IDLE,
    KEEPALIVE_INTERVAL,
    MAX_RETRY_HTTP_CONNECTION,
    TIMEOUT_HTTP_PROTOCOL,
)
from .exceptions import CommError, LoginError
from .utils import clean_url, pretty
        self.socket_options = kwargs.pop("socket_options", None)
        super().__init__(*args, **kwargs)

    def init_poolmanager(self, *args, **kwargs) -> None:
        if self.socket_options is not None:
            kwargs["socket_options"] = self.socket_options
        super().init_poolmanager(*args, **kwargs)


class Http:
    def __init__(
        self,
        host: str,
        port: int,
        user: str,
        password: str,
        *,
        verbose: bool = True,
        protocol: str = "http",
        ssl_verify: bool = True,
        retries_connection: Optional[int] = None,
        timeout_protocol: TimeoutT = None,
    ) -> None:
        self._token_lock = threading.Lock()
        try:
            self._async_token_lock: Optional[asyncio.Lock] = asyncio.Lock()
        except RuntimeError:
            self._async_token_lock = None
        self._cmd_id_lock = threading.Lock()
        self._cmd_id = 0

# Path: src/amcrest/config.py
# KEEPALIVE_COUNT = 5
# 
# KEEPALIVE_IDLE = 20
# 
# KEEPALIVE_INTERVAL = 10
# 
# MAX_RETRY_HTTP_CONNECTION = 3
# 
# TIMEOUT_HTTP_PROTOCOL = 6.05
# 
# Path: src/amcrest/exceptions.py
# class CommError(AmcrestError):
#     """A communication error occurred."""
# 
# class LoginError(AmcrestError):
#     """A login error occurred."""
# 
# Path: src/amcrest/utils.py
# def clean_url(url: str) -> str:
#     host = re.sub(r"^http[s]?://", "", url, flags=re.IGNORECASE)
#     host = re.sub(r"/$", "", host)
#     return host
# 
# def pretty(value: str, delimiter: str = "=") -> str:
#     """Format string key=value."""
#     return value.strip().rpartition(delimiter)[2]


# Path: src/amcrest/http.py
import asyncio
import logging
import re
import socket
import threading
import httpx
import requests
from contextlib import asynccontextmanager
from typing import AsyncIterator, Optional, Tuple, Union
from requests.adapters import HTTPAdapter
from urllib3.connection import HTTPConnection
from .config import (
    KEEPALIVE_COUNT,
    KEEPALIVE_IDLE,
    KEEPALIVE_INTERVAL,
    MAX_RETRY_HTTP_CONNECTION,
    TIMEOUT_HTTP_PROTOCOL,
)
from .exceptions import CommError, LoginError
from .utils import clean_url, pretty

        self.socket_options = kwargs.pop("socket_options", None)
        super().__init__(*args, **kwargs)

    def init_poolmanager(self, *args, **kwargs) -> None:
        if self.socket_options is not None:
            kwargs["socket_options"] = self.socket_options
        super().init_poolmanager(*args, **kwargs)


class Http:
    def __init__(
        self,
        host: str,
        port: int,
        user: str,
        password: str,
        *,
        verbose: bool = True,
        protocol: str = "http",
        ssl_verify: bool = True,
        retries_connection: Optional[int] = None,
        timeout_protocol: TimeoutT = None,
    ) -> None:
        self._token_lock = threading.Lock()
        try:
            self._async_token_lock: Optional[asyncio.Lock] = asyncio.Lock()
        except RuntimeError:
            self._async_token_lock = None
        self._cmd_id_lock = threading.Lock()
        self._cmd_id = 0

        self._host = clean_url(host)