U
    g                     @   s   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZ ertddlmZmZmZ G d	d
 d
eZdS )zHThis module contains an object that represents a Encrypted PassportFile.    )TYPE_CHECKINGListOptionalTuple)TelegramObject)DEFAULT_NONE)JSONDictODVInput)warn)PTBDeprecationWarning)BotFileFileCredentialsc                	       s  e Zd ZdZdZdddeeeeed ee d fddZ	de
ed
 fddZeedddZeee ed ded  d fddZeeee  ed ed eed  df dddZeeeeddee ee ee ee ee ddddZ  ZS )PassportFilea3  
    This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport
    files are in JPEG format when decrypted and don't exceed 10MB.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`file_unique_id` is equal.

    Args:
        file_id (:obj:`str`): Identifier for this file, which can be used to download
            or reuse the file.
        file_unique_id (:obj:`str`): Unique identifier for this file, which
            is supposed to be the same over time and for different bots.
            Can't be used to download or reuse the file.
        file_size (:obj:`int`): File size in bytes.
        file_date (:obj:`int`): Unix time when the file was uploaded.

            .. deprecated:: 20.6
                This argument will only accept a datetime instead of an integer in future
                major versions.

    Attributes:
        file_id (:obj:`str`): Identifier for this file, which can be used to download
            or reuse the file.
        file_unique_id (:obj:`str`): Unique identifier for this file, which
            is supposed to be the same over time and for different bots.
            Can't be used to download or reuse the file.
        file_size (:obj:`int`): File size in bytes.
    )_credentials
_file_datefile_id	file_sizefile_unique_idN
api_kwargsr   )r   r   	file_dater   credentialsr   c                   sB   t  j|d || _|| _|| _|| _|| _| jf| _|   d S )Nr   )	super__init__r   r   r   r   r   Z	_id_attrsZ_freeze)selfr   r   r   r   r   r   	__class__ C/tmp/pip-unpacked-wheel-swnnwir2/telegram/_passport/passportfile.pyr   G   s    

zPassportFile.__init__T)	recursivereturnc                    s   t  |}| j|d< |S )z8See :meth:`telegram.TelegramObject.to_dict` for details.r   )r   to_dictr   )r   r    datar   r   r   r"   `   s    
zPassportFile.to_dict)r!   c                 C   s   t tdddd | jS )z:obj:`int`: Unix time when the file was uploaded.

        .. deprecated:: 20.6
            This attribute will return a datetime instead of a integer in future major versions.
        z20.6z`The attribute `file_date` will return a datetime instead of an integer in future major versions.   )
stacklevel)r
   r   r   )r   r   r   r   r   f   s    zPassportFile.file_dater   )r#   botr   r!   c                    s*   |  |}|sdS ||d< t j||dS )a  Variant of :meth:`telegram.TelegramObject.de_json` that also takes into account
        passport credentials.

        Args:
            data (Dict[:obj:`str`, ...]): The JSON data.
            bot (:class:`telegram.Bot` | :obj:`None`): The bot associated with these object.
                May be :obj:`None`, in which case shortcut methods will not be available.

                .. versionchanged:: 21.4
                   :paramref:`bot` is now optional and defaults to :obj:`None`

                .. deprecated:: 21.4
                   This argument will be converted to an optional argument in future versions.
            credentials (:class:`telegram.FileCredentials`): The credentials

        Returns:
            :class:`telegram.PassportFile`:

        Nr   )r#   r&   )Z_parse_datar   Zde_jsonclsr#   r&   r   r   r   r   de_json_decryptedw   s
    
zPassportFile.de_json_decrypted.c                    s0   |sdS t dd  fddt|D D S )a  Variant of :meth:`telegram.TelegramObject.de_list` that also takes into account
        passport credentials.

        .. versionchanged:: 20.0

           * Returns a tuple instead of a list.
           * Filters out any :obj:`None` values

        Args:
            data (List[Dict[:obj:`str`, ...]]): The JSON data.
            bot (:class:`telegram.Bot` | :obj:`None`): The bot associated with these object.
                May be :obj:`None`, in which case shortcut methods will not be available.

                .. versionchanged:: 21.4
                   :paramref:`bot` is now optional and defaults to :obj:`None`

                .. deprecated:: 21.4
                   This argument will be converted to an optional argument in future versions.
            credentials (:class:`telegram.FileCredentials`): The credentials

        Returns:
            Tuple[:class:`telegram.PassportFile`]:

        r   c                 s   s   | ]}|d k	r|V  qd S Nr   ).0objr   r   r   	<genexpr>   s   z1PassportFile.de_list_decrypted.<locals>.<genexpr>c                 3   s$   | ]\}} | | V  qd S r*   )r)   )r+   iZpassport_filer&   r(   r   r   r   r-      s   )tuple	enumerater'   r   r/   r   de_list_decrypted   s    zPassportFile.de_list_decrypted)read_timeoutwrite_timeoutconnect_timeoutpool_timeoutr   r   )r3   r4   r5   r6   r   r!   c                   s8   |   j| j|||||dI dH }| jr4|| j |S )a  
        Wrapper over :meth:`telegram.Bot.get_file`. Will automatically assign the correct
        credentials to the returned :class:`telegram.File` if originating from
        :attr:`telegram.PassportData.decrypted_data`.

        For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`.

        Returns:
            :class:`telegram.File`

        Raises:
            :class:`telegram.error.TelegramError`

        )r   r3   r4   r5   r6   r   N)Zget_botget_filer   r   Zset_credentials)r   r3   r4   r5   r6   r   filer   r   r   r7      s    zPassportFile.get_file)N)T)__name__
__module____qualname____doc__	__slots__strintr   r   r   boolr"   propertyr   classmethodr)   r   r   r2   r   r	   floatr7   __classcell__r   r   r   r   r   !   sR      
-r   N)r<   typingr   r   r   r   Ztelegram._telegramobjectr   Ztelegram._utils.defaultvaluer   Ztelegram._utils.typesr   r	   Ztelegram._utils.warningsr
   Ztelegram.warningsr   Ztelegramr   r   r   r   r   r   r   r   <module>   s   