o
    Ü!d²  ã                   @   s`   d dl mZ d dlmZ d dlmZ ddddddœZG d	d
„ d
eƒZG dd„ de	ƒZ
dd„ ZdS )é    )ÚTransferConfig)Úhuman_readable_to_bytes)Úsixi  € é
   iè  N)Úmultipart_thresholdÚmultipart_chunksizeÚmax_concurrent_requestsÚmax_queue_sizeÚmax_bandwidthc                   @   s   e Zd ZdS )ÚInvalidConfigErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   úKusr/lib/python3.10/site-packages/awscli/customizations/s3/transferconfig.pyr      s    r   c                   @   sV   e Zd Zg d¢ZddgZdgZedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚRuntimeConfig)r   r   r   r	   r
   r   r   r
   c                   C   s   t  ¡ S ©N)ÚDEFAULTSÚcopyr   r   r   r   Údefaults)   s   zRuntimeConfig.defaultsc                 K   s8   t  ¡ }|r| |¡ |  |¡ |  |¡ |  |¡ |S )aj  Create and convert a runtime config dictionary.

        This method will merge and convert S3 runtime configuration
        data into a single dictionary that can then be passed to classes
        that use this runtime config.

        :param kwargs:  Any key in the ``DEFAULTS`` dict.
        :return: A dictionary of the merged and converted values.

        )r   r   ÚupdateÚ_convert_human_readable_sizesÚ_convert_human_readable_ratesÚ_validate_config)ÚselfÚkwargsÚruntime_configr   r   r   Úbuild_config-   s   



zRuntimeConfig.build_configc                 C   s:   | j D ]}| |¡}|d urt|tjƒst|ƒ||< qd S r   )ÚHUMAN_READABLE_SIZESÚgetÚ
isinstancer   Úinteger_typesr   ©r   r   ÚattrÚvaluer   r   r   r   @   s   

€ýz+RuntimeConfig._convert_human_readable_sizesc                 C   sX   | j D ]&}| |¡}|d ur)t|tjƒs)| d¡std| ƒ‚t|d d… ƒ||< qd S )NzB/sznInvalid rate: %s. The value must be expressed as a rate in terms of bytes per seconds (e.g. 10MB/s or 800KB/s)éþÿÿÿ)ÚHUMAN_READABLE_RATESr   r    r   r!   Úendswithr   r   r"   r   r   r   r   F   s   


þÿ€øz+RuntimeConfig._convert_human_readable_ratesc              	   C   sj   | j D ]/}| |¡}|d ur2zt|ƒ||< || dks!|  ||¡ W q ty1   |  ||¡ Y qw qd S )Nr   )ÚPOSITIVE_INTEGERSr   ÚintÚ_error_positive_valueÚ
ValueErrorr"   r   r   r   r   Q   s   

€ÿûþzRuntimeConfig._validate_configc                 C   s   t d||f ƒ‚)Nz+Value for %s must be a positive integer: %s)r   )r   Únamer$   r   r   r   r*   \   s   
ÿz#RuntimeConfig._error_positive_valueN)r   r   r   r(   r   r&   Ústaticmethodr   r   r   r   r   r*   r   r   r   r   r   !   s    
r   c                 C   sJ   ddddddœ}i }|   ¡ D ]\}}||vrq|||| < qtdi |¤ŽS )	zø
    Creates an equivalent s3transfer TransferConfig

    :type runtime_config: dict
    :argument runtime_config: A valid RuntimeConfig-generated dict.

    :returns: A TransferConfig with the same configuration as the runtime
        config.
    Zmax_request_concurrencyZmax_request_queue_sizer   r   r
   )r   r	   r   r   r
   Nr   )Úitemsr   )r   Ztranslation_mapr   Úkeyr$   r   r   r   Ú*create_transfer_config_from_runtime_configa   s   ûr0   )Zs3transfer.managerr   Zawscli.customizations.s3.utilsr   Zawscli.compatr   r   Ú	Exceptionr   Úobjectr   r0   r   r   r   r   Ú<module>   s   û	@