
    Wwg                         d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ 	 d dlZ G d d	e	      Zy# e$ rZ ed      edZ[ww xY w)
    )OptionalUnion)cmstsp)LazySession)TimeStamperTimestampRequestError)set_tsp_headersNz?Install pyHanko with the [async_http] optional dependency groupc                        e Zd Z	 	 	 	 d
deej
                  ef   deej                     f fdZ	de
fdZdej
                  fdZdej                  f fdZdej"                  dej$                  fd	Z xZS )AIOHttpTimeStampersessionauthc                     |r|j                  d      st        d      || _        || _        || _        || _        || _        t        | !          y)a  
        Initialise the timestamp client.

        :param url:
            URL where the server listens for timestamp requests.
        :param https:
            Enforce HTTPS.
        :param timeout:
            Timeout (in seconds)
        :param auth:
            `aiohttp.BasicAuth` object with authentication credentials.
        :param headers:
            Other headers to include.
        zhttps:zTimestamp URL is not HTTPS.N)	
startswith
ValueErrorurltimeoutr   headers_sessionsuper__init__)selfr   r   httpsr   r   r   	__class__s          ]/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/timestamps/aiohttp_client.pyr   zAIOHttpTimeStamper.__init__   sM    . 1:;;	    returnc                 <   K   t        | j                  xs i       S w)z
        Format the HTTP request headers.
        Subclasses can override this to perform their own header generation
        logic.

        :return:
            Header dictionary.
        )r
   r   )r   s    r   async_request_headersz(AIOHttpTimeStamper.async_request_headers2   s      t||1r22s   c                 z   K   | j                   }t        |t              r|j                          d {   S |S 7 wN)r   
isinstancer   get_session)r   r   s     r   r#   zAIOHttpTimeStamper.get_session=   s5     --g{+ ,,...N /s   0;9;c                 @   K   t         |   ||       d {   S 7 wr!   )r   async_timestamp)r   message_digestmd_algorithmr   s      r   r%   z"AIOHttpTimeStamper.async_timestampD   s!      W,^\JJJJs   reqc                   K   | j                          d {   }t        j                  | j                        }| j	                          d {   }	 |j                  | j                  ||j                         | j                  d|      4 d {   }|j                          d {   }|j                  j                  d      }|dk7  r=d| d}t        j                  |j                  |j                  ||j                        d d d       d {    t"        j$                  j'                        S 7 $7 7 7 7 ,# 1 d {  7  sw Y   <xY w# t        j                  $ r}	t!        d	      |	d }	~	ww xY ww)
N)totalT)r   r   datar   raise_for_statusr   zContent-Typezapplication/timestamp-replyz?Bad content type. Expected application/timestamp-reply,but got .)messager   z(Error while contacting timestamp service)r#   aiohttpClientTimeoutr   r   postr   dumpr   readr   getContentTypeErrorrequest_infohistoryClientErrorr	   r   TimeStampRespload)
r   r(   r   
cl_timeoutr   responseresponse_datactmsges
             r   async_request_tsa_responsez-AIOHttpTimeStamper.async_request_tsa_responseI   st     ((****>
2244	||HHXXZYY!%" $    &.mmo 5%%)).966??Ad!E  "22 -- (( # ( 0 0	  2   %%m44= + 5 !6   * "" 	':	s   FD:7FD=F=E D?E E)E*A!EE EE  F=F?E EE EEEE E>-E99E>>F)F   NN)__name__
__module____qualname__r   r/   ClientSessionr   r   	BasicAuthr   dictr   r#   r   ContentInfor%   r   TimeStampReqr9   rA   __classcell__)r   s   @r   r   r      s    
 ,0 w,,k9: w(()@	3T 	37#8#8 K	K
!5##!5			!5r   r   )typingr   r   
asn1cryptor   r   4pyhanko_certvalidator.fetchers.aiohttp_fetchers.utilr   pyhanko.sign.timestampsr   r	   $pyhanko.sign.timestamps.common_utilsr
   r/   ImportError_er    r   r   <module>rT      sO    "  L F @Y5 Y5  
Is   6 A		AA	