
    Wwg                     \    d dl Z d dlmZ d dlmZ ddlmZ ddlmZm	Z	 dgZ
 G d de      Zy)	    N)tsp	to_thread   )TimeStamper)TimestampRequestErrorset_tsp_headersHTTPTimeStamperc                   h     e Zd ZdZd fd	ZdefdZdej                  dej                  fdZ
 xZS )r
   z/
    Standard HTTP-based timestamp client.
    c                     |r|j                  d      st        d      || _        || _        || _        || _        t        |           y)ax  
        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:
            Value of HTTP ``Authorization`` header
        :param headers:
            Other headers to include.
        zhttps:zTimestamp URL is not HTTPS.N)
startswith
ValueErrorurltimeoutauthheaderssuper__init__)selfr   httpsr   r   r   	__class__s         ^/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/timestamps/requests_client.pyr   zHTTPTimeStamper.__init__   sF     1:;;	    returnc                 4    t        | j                  xs i       S )zc
        Format the HTTP request headers.

        :return:
            Header dictionary.
        )r	   r   )r   s    r   request_headerszHTTPTimeStamper.request_headers'   s     t||1r22r   reqc                 H    K    fd}t        |       d {   }|S 7 w)Nc                     	 t        j                  j                  j                         j	                         j
                  j                        } | j                  j                  d      dk7  rt        d|       t        j                  j                  | j                        S # t        $ r}t        d      |d }~ww xY w)N)r   r   r   z,Error in communication with timestamp serverzContent-Typezapplication/timestamp-replyz'Timestamp server response is malformed.)requestspostr   dumpr   r   r   IOErrorr   r   getr   TimeStampResploadcontent)raw_reser   r   s     r   taskz8HTTPTimeStamper.async_request_tsa_response.<locals>.task3   s    "--HHHHJ 002 LL ##N301 ,=w  $$))'//::  +Bs   AB* *	C3B??Cr   )r   r   r*   responses   ``  r   async_request_tsa_responsez*HTTPTimeStamper.async_request_tsa_response0   s$     	;. #4( )s   " ")F   NN)__name__
__module____qualname____doc__r   dictr   r   TimeStampReqr%   r,   __classcell__)r   s   @r   r
   r
      s:    .3 3##			r   )r    
asn1cryptor   %pyhanko_certvalidator._asyncio_compatr   apir   common_utilsr   r	   __all__r
    r   r   <module>r;      s*      ;  @
@k @r   