client.cpython-311.pyc•22.7 kB
�
�$�g�G � � � d Z ddlZddlZddlmZ ddlmZmZmZmZm Z m
Z
ddlZddlm
Z
ddlmZ ddlmZmZ ej e� � Ze� ej � � ej sG ej � � Ze� ej d � � � � e� e� � e d
e
�� � Z G d� d
e� � Z G d� de� � Z G d� de� � Z! G d� de� � Z" G d� d� � Z# e#� � Z$dS )a)
Async HTTP client for interacting with the waktusolat.app API.
This module provides a high-level interface to the waktusolat.app API with:
- Automatic connection pooling and timeouts
- Retry logic for transient failures
- Type-safe responses using Pydantic models
- Comprehensive error handling
� N)�datetime)�List�Dict�Any�Optional�TypeVar�Type)� BaseModel� )�config)�PrayerTimes�Zonez4%(asctime)s - %(name)s - %(levelname)s - %(message)s�T)�boundc � � e Zd ZdZdS )�APIErrorzBase exception for API errors.N��__name__�
__module__�__qualname__�__doc__� � �Q/Users/aman/2) personal/mcp-server-malaysia-prayer-time/src/waktu_solat/client.pyr r $ s � � � � � �(�(��Dr r c � � e Zd ZdZdS )�ValidationErrorz#Raised when input validation fails.Nr r r r r r * s � � � � � �-�-��Dr r c � � e Zd ZdZdS )�
ResponseErrorz(Raised when the API response is invalid.Nr r r r r r 0 � � � � � � �2�2��Dr r c � � e Zd ZdZdS )�ConnectionErrorz(Raised when connection to the API fails.Nr r r r r! r! 6 r r r! c � � e Zd ZdZdd�Zdd�Zd� Zdej fd�Z de
d e
dee
ef fd
�Z
de
dee fd�Zdee fd
�Zde
dee
ef fd�ZdS )�
HTTPClientz-Async HTTP client for the waktusolat.app API.�returnNc � � t j t j t j j � � t j t j j t j j �� � �� � | _ t j j �
d� � | _ d| _ t j d| j � � st d� � �dS )z&Initialize a new HTTP client instance.��max_connections�max_keepalive_connections��timeout�limits�/� z
^https?://z,Base URL must start with http:// or https://N)�httpx�AsyncClient�Timeoutr �httpr* �Limits�pool_connections�_client�base_url�rstrip� _base_url�_retry_count�re�matchr ��selfs r �__init__zHTTPClient.__init__? s� � �49�4E��M�&�+�"5�6�6��<� &�� <�*0�+�*F�� � �5
� 5
� 5
��� %�k�2�9�9�#�>�>���!"��� �x�
�t�~�6�6� R�!�"P�Q�Q�Q� R� Rr c � �
K � | S )zSetup the async context.r r; s r �
__aenter__zHTTPClient.__aenter__O s � � � ��r c � � K � | j r� t � d� � | j � � � � d{V �� n4# t $ r'}t � d|� �� � Y d}~nd}~ww xY wt � d� � d| _ dS # t � d� � d| _ w xY wdS )zCleanup the async context.zClosing HTTP client connectionNzError closing HTTP client: zHTTP client connection closed)r4 �logger�debug�aclose� Exception�error)r<