o
    vh                     @   sV   d dl mZ d dlZd dlmZ ddlmZ ddlmZm	Z	 dgZ
G dd deZdS )	    	to_threadN)tsp   )TimeStamper)TimestampRequestErrorset_tsp_headersHTTPTimeStamperc                       sF   e Zd ZdZd fdd	Zdefdd	Zd
ejdej	fddZ
  ZS )r	   z/
    Standard HTTP-based timestamp client.
    F   Nc                    s<   |r| dstd|| _|| _|| _|| _t   dS )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__ e/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pyhanko/sign/timestamps/requests_client.pyr      s   zHTTPTimeStamper.__init__returnc                 C   s   t | jpi S )zc
        Format the HTTP request headers.

        :return:
            Header dictionary.
        )r   r   )r   r   r   r   request_headers(   s   zHTTPTimeStamper.request_headersreqc                    s"    fdd}t |I d H }|S )Nc               
      sr   zt jj   jjd} W n ty$ } ztd|d }~ww | j	
ddkr2td| tj| jS )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er   r   r   r   task4   s.   

z8HTTPTimeStamper.async_request_tsa_response.<locals>.taskr   )r   r   r'   responser   r&   r   async_request_tsa_response1   s   z*HTTPTimeStamper.async_request_tsa_response)Fr
   NN)__name__
__module____qualname____doc__r   dictr   r   TimeStampReqr!   r)   __classcell__r   r   r   r   r	      s    	)asyncior   r   
asn1cryptor   apir   common_utilsr   r   __all__r	   r   r   r   r   <module>   s    