o
    &zhU                     @   s`   d dl Z d dlmZ d dlmZ d dlZd dlmZ ddlmZ ddl	m
Z
 G dd	 d	eZdS )
    N)datetime)Dict)Response   )Default)ERRORSc                   @   sf   e Zd ZdZdd Zdd Zdd Zedd	efd
dZ	de
d	e
fddZedded	efddZdS )ImageKitRequestz
    ImageKitRequest is holds the methods and attributes about server
    communications and communicates to server, used by Internal classes
    c                 C   sL   || _ || _|| _|ptjj| _|pi | _| j r| jr| js$tt	j
jd S N)private_key
public_keyurl_endpointr   DEFAULT_TRANSFORMATION_POSITIONvaluetransformation_positionoptions
ValueErrorr    MANDATORY_INITIALIZATION_MISSING)selfr
   r   r   r   r    r   N/var/www/html/kangema/venv/lib/python3.10/site-packages/imagekitio/resource.py__init__   s   

zImageKitRequest.__init__c                 C   s   ddi}| |   |S )z1Create headers dict and sets Authorization headerzAccept-Encodingzgzip, deflate)updateget_auth_headers)r   headersr   r   r   create_headers    s   zImageKitRequest.create_headersc                 C   s(   t | jd  d}dd|iS )zCreate dictionary with encoded private key
        The out put is used in request header as authorization header

        :return: dictionary of encoded private key
        :zutf-8AuthorizationzBasic {})base64	b64encoder
   encodedecodeformat)r   encoded_private_keyr   r   r   r   &   s   z ImageKitRequest.get_auth_headersNreturnc                 C   s   t j| |||||d}|S )z6Requests from ImageKit server used,by internal methods)methodurlparamsfilesdatar   )requestsrequest)r$   r%   r   r&   r'   r(   respr   r   r   r*   1   s   	zImageKitRequest.requestr   c                 C   s,   | j | j| j| jd}i | j||}|S )zt
        adds data to the options from the object, so that
        required data can be used by url builder
        )r   r
   r   r   )r   r
   r   r   r   )r   r   	attr_dictextended_optionsr   r   r   extend_url_options?   s   z"ImageKitRequest.extend_url_optionssecondsc                 C   s$   | st jjS tt  }||  S )z
        Returns either default time stamp
        or current unix time and expiry seconds to get
        signature time stamp
        )r   DEFAULT_TIMESTAMPr   intdtnow	timestamp)r/   current_timestampr   r   r   get_signature_timestampN   s   z'ImageKitRequest.get_signature_timestamp)NNNr	   )__name__
__module____qualname____doc__r   r   r   staticmethodr   r*   r   r.   r1   r6   r   r   r   r   r      s    r   )r   r   r2   typingr   r)   r   constants.defaultsr   constants.errorsr   objectr   r   r   r   r   <module>   s    