o
    .&ßaJr  ã                	   @   s¸  d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZ e e¡Zd	Zed
ddeƒ d�ZdZdddddddddœZe d¡Ze d¡Ze d¡Ze d¡Z dd„ Z!dd„ Z"G dd„ de j#ƒZ$G dd„ de%ƒZ&G dd „ d ej'ƒZ(d!d"„ Z)d#d$„ Z*d%d&„ Z+d'd(„ Z,dYd)d*„Z-dZd,d-„Z.G d.d/„ d/e/ƒZ0d0d1„ Z1ej2j3fd2d3„Z4d4d5„ Z5G d6d7„ d7e%ƒZ6d8d9„ Z7G d:d;„ d;e/ƒZ8G d<d=„ d=e	d=g d>¢ƒƒZ9e9Z:G d?d@„ d@e/ƒZ;G dAdB„ dBeƒZ<G dCdD„ dDeƒZ=G dEdF„ dFe=ƒZ>G dGdH„ dHe>ƒZ?G dIdJ„ dJe?ƒZ@G dKdL„ dLe>ƒZAG dMdN„ dNeƒZBG dOdP„ dPeBƒZCG dQdR„ dReBƒZDG dSdT„ dTe=ƒZEG dUdV„ dVeƒZFG dWdX„ dXe/ƒZGdS )[é    N)Údatetime)Ú
namedtupleÚdeque)Úparse)ÚtzlocalÚtzutc)ÚBaseSubscriber)Úbytes_print)Úqueue)ÚKiBÚMiBÚGiBÚTiBÚPiBÚEiBi²  é   )Útzinfol        é   i   i   @l        )ÚkbÚmbÚgbÚtbÚkibÚmibÚgibÚtibzT^(?P<bucket>arn:(aws).*:s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[:/][^/]+)/?(?P<key>.*)$z�^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$z‹^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]bucket[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$zs^(?P<bucket>arn:(aws).*:s3-object-lambda:[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$c                 C   sv   d}t | ƒ}|dkrdS ||k rd| S ttƒD ] \}}||d  }t|| | ƒ|k r8d|| | |f   S qdS )aŸ  Convert a size in bytes into a human readable format.

    For example::

        >>> human_readable_size(1)
        '1 Byte'
        >>> human_readable_size(10)
        '10 Bytes'
        >>> human_readable_size(1024)
        '1.0 KiB'
        >>> human_readable_size(1024 * 1024)
        '1.0 MiB'

    :param value: The size in bytes.
    :return: The size in a human readable format based on base-2 units.

    r   r   z1 Bytez%d Bytesé   z%.1f %sN)ÚfloatÚ	enumerateÚHUMANIZE_SUFFIXESÚround)ÚvalueÚbaseÚ	bytes_intÚiÚsuffixÚunit© r'   ú@/usr/lib/python3/dist-packages/awscli/customizations/s3/utils.pyÚhuman_readable_sizeC   s   ÿþr)   c                 C   sš   |   ¡ } | dd… dkr| dd…   ¡ }n| dd…   ¡ }t| ƒdko&|tv }|s<zt| ƒW S  ty;   td|  ƒ‚w t| }t| dt|ƒ … ƒ| S )a  Converts a human readable size to bytes.

    :param value: A string such as "10MB".  If a suffix is not included,
        then the value is assumed to be an integer representing the size
        in bytes.
    :returns: The converted value in bytes as an integer

    éþÿÿÿNÚibéýÿÿÿr   zInvalid size value: %s)ÚlowerÚlenÚSIZE_SUFFIXÚintÚ
ValueError)r!   r%   Úhas_size_identifierÚ
multiplierr'   r'   r(   Úhuman_readable_to_bytesc   s   	ÿ
ÿr4   c                   @   s   e Zd ZdZddd„ZdS )ÚAppendFiltera¢  
    This class is used as an action when parsing the parameters.
    Specifically it is used for actions corresponding to exclude
    and include filters.  What it does is that it appends a list
    consisting of the name of the parameter and its value onto
    a list containing these [parameter, value] lists.  In this
    case, the name of the parameter will either be --include or
    --exclude and the value will be the rule to apply.  This will
    format all of the rules inputted into the command line
    in a way compatible with the Filter class.  Note that rules that
    appear later in the command line take preference over rulers that
    appear earlier.
    Nc                 C   sD   t || jƒ}|r| ||d g¡ n||d gg}t|| j|ƒ d S ©Nr   )ÚgetattrÚdestÚappendÚsetattr)ÚselfÚparserÚ	namespaceÚvaluesÚoption_stringÚfilter_listr'   r'   r(   Ú__call__Œ   s
   zAppendFilter.__call__©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rA   r'   r'   r'   r(   r5   ~   s    r5   c                   @   ó   e Zd ZdS )ÚCreateDirectoryErrorN©rC   rD   rE   r'   r'   r'   r(   rH   •   ó    rH   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚStablePriorityQueuea…  Priority queue that maintains FIFO order for same priority items.

    This class was written to handle the tasks created in
    awscli.customizations.s3.tasks, but it's possible to use this
    class outside of that context.  In order for this to be the case,
    the following conditions should be met:

        * Objects that are queued should have a PRIORITY attribute.
          This should be an integer value not to exceed the max_priority
          value passed into the ``__init__``.  Objects with lower
          priority numbers are retrieved before objects with higher
          priority numbers.
        * A relatively small max_priority should be chosen.  ``get()``
          calls are O(max_priority).

    Any object that does not have a ``PRIORITY`` attribute or whose
    priority exceeds ``max_priority`` will be queued at the highest
    (least important) priority available.

    r   é   c                 C   s2   t jj| |d� dd„ t|d ƒD ƒ| _|| _d S )N)Úmaxsizec                 S   s   g | ]}t g ƒ‘qS r'   )r   )Ú.0r$   r'   r'   r(   Ú
<listcomp>°   s    z0StablePriorityQueue.__init__.<locals>.<listcomp>r   )r
   ÚQueueÚ__init__ÚrangeÚ
prioritiesÚdefault_priority)r;   rM   Úmax_priorityr'   r'   r(   rQ   ®   s   
zStablePriorityQueue.__init__c                 C   s    d}| j D ]}|t|ƒ7 }q|S r6   )rS   r.   )r;   ÚsizeÚbucketr'   r'   r(   Ú_qsize³   s   
zStablePriorityQueue._qsizec                 C   s*   t t|d| jƒ| jƒ}| j|  |¡ d S )NÚPRIORITY)Úminr7   rT   rS   r9   )r;   ÚitemÚpriorityr'   r'   r(   Ú_put¹   s   ÿzStablePriorityQueue._putc                 C   s    | j D ]
}|sq| ¡   S d S rB   )rS   Úpopleft)r;   rW   r'   r'   r(   Ú_get¾   s
   
ýzStablePriorityQueue._getN)r   rL   )rC   rD   rE   rF   rQ   rX   r]   r_   r'   r'   r'   r(   rK   ™   s    
rK   c                 C   s(   t  | ¡r	tdƒ‚t | ¡rtdƒ‚d S )NzRs3 commands do not support S3 Object Lambda resources. Use s3api commands instead.zOs3 commands do not support Outpost Bucket ARNs. Use s3control commands instead.)Ú%_S3_OBJECT_LAMBDA_TO_BUCKET_KEY_REGEXÚmatchr1   Ú*_S3_OUTPOST_BUCKET_ARN_TO_BUCKET_KEY_REGEX©Ús3_pathr'   r'   r(   Úblock_unsupported_resourcesÅ   s   
ÿ
ÿÿre   c                 C   s€   t | ƒ t | ¡}|r| d¡| d¡fS t | ¡}|r&| d¡| d¡fS |  dd¡}|d }d}t|ƒdkr<|d }||fS )z°
    This is a helper function that given an s3 path such that the path is of
    the form: bucket/key
    It will return the bucket and the key represented by the s3 path
    rW   Úkeyú/r   r   Ú )re   Ú#_S3_ACCESSPOINT_TO_BUCKET_KEY_REGEXra   ÚgroupÚ_S3_OUTPOST_TO_BUCKET_KEY_REGEXÚsplitr.   )rd   ra   Ús3_componentsrW   Ús3_keyr'   r'   r(   Úfind_bucket_keyÙ   s   

ro   c                 C   s   |   d¡r| dd… } t| ƒS )z�Split s3 path into bucket and key prefix.

    This will also handle the s3:// prefix.

    :return: Tuple of ('bucketname', 'keyname')

    zs3://é   N)Ú
startswithro   rc   r'   r'   r(   Úsplit_s3_bucket_keyî   s   
rr   c              
   C   st   zt  | ¡}W n ty } ztd| |f ƒ‚d}~ww z
t |jtƒ ¡}W n ttt	fy4   d}Y nw |j
|fS )zƒ
    This is a helper function that given a local path return the size of
    the file in bytes and time of last modification.
    z(Could not retrieve file stat of "%s": %sN)ÚosÚstatÚIOErrorr1   r   ÚfromtimestampÚst_mtimer   ÚOSErrorÚOverflowErrorÚst_size)ÚpathÚstatsÚeÚupdate_timer'   r'   r(   Úget_file_statû   s   ÿ€ÿù
	r   c           
      C   s¼   | d }| d }|d }|d }|du r|d }dt jdœ}| d r-|t|d ƒd… }n	| || ¡d	 }| || d¡}| d
 rV|d }	|	| || || ¡7 }	|	|fS |d }	|	|fS )z•
    This is a helper function that determines the destination path and compare
    key given parameters received from the ``FileFormat`` class.
    Úsrcr8   ÚtypeNr{   rg   )Ús3ÚlocalÚdir_opéÿÿÿÿÚuse_src_name)rs   Úsepr.   rl   Úreplace)
ÚfilesÚsrc_pathr€   r8   Úsrc_typeÚ	dest_typeÚ	sep_tableÚrel_pathÚcompare_keyÚ	dest_pathr'   r'   r(   Úfind_dest_path_comp_key  s&   ÿÿr‘   Tc                 C   s2   d}|r|d |  d }|| }t |ddd�}|S )zN
    This creates a ``PrintTask`` for whenever a warning is to be thrown.
    z	warning: zSkipping file z. FT)ÚmessageÚerrorÚwarning)ÚWarningResult)r{   Úerror_messageÚ	skip_fileÚprint_stringÚwarning_messager'   r'   r(   Úcreate_warning0  s   ÿrš   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚStdoutBytesWriterzd
    This class acts as a file-like object that performs the bytes_print
    function on write.
    Nc                 C   ó
   || _ d S rB   )Ú_stdout)r;   Ústdoutr'   r'   r(   rQ   B  ó   
zStdoutBytesWriter.__init__c                 C   s   t || jƒ dS )zR
        Writes data to stdout as bytes.

        :param b: data to write
        N)r	   r�   )r;   Úbr'   r'   r(   ÚwriteE  s   zStdoutBytesWriter.writerB   )rC   rD   rE   rF   rQ   r¡   r'   r'   r'   r(   r›   =  s    
r›   c                 C   s6   zt  | ¡d W S  ty   tjd| dd� Y dS w )zpGiven a filename, guess it's content type.

    If the type cannot be guessed, a value of None is returned.
    r   z?Unable to guess content type for %s due to UnicodeDecodeError: T)Úexc_infoN)Ú	mimetypesÚ
guess_typeÚUnicodeDecodeErrorÚLOGGERÚdebug)Úfilenamer'   r'   r(   Úguess_content_typeN  s   	þÿr©   c                 C   sN   zt j | ¡\}}t j ||¡}t j ||¡W S  ty&   t j | ¡ Y S w )zÌCross platform relative path of a filename.

    If no relative path can be calculated (i.e different
    drives on Windows), then instead of raising a ValueError,
    the absolute path is returned.

    )rs   r{   rl   ÚrelpathÚjoinr1   Úabspath)r¨   ÚstartÚdirnameÚbasenameÚrelative_dirr'   r'   r(   Úrelative_pathd  s   ÿr±   c              
   C   sH   zt  | ||f¡ W dS  ty# } z|jtjkr|‚tdƒ‚d}~ww )aB  
    Set the utime of a file, and if it fails, raise a more explicit error.

    :param filename: the file to modify
    :param desired_time: the epoch timestamp to set for atime and mtime.
    :raises: SetFileUtimeError: if you do not have permission (errno 1)
    :raises: OSError: for all errors other than errno 1
    zrThe file was downloaded, but attempting to modify the utime of the file failed. Is the file owned by another user?N)rs   Úutimerx   ÚerrnoÚEPERMÚSetFileUtimeError)r¨   Údesired_timer}   r'   r'   r(   Úset_file_utimet  s   	ÿ€ür·   c                   @   rG   )rµ   NrI   r'   r'   r'   r(   rµ   ˆ  rJ   rµ   c                 C   s   t | ƒ tƒ ¡S rB   )r   Ú
astimezoner   )Údate_stringr'   r'   r(   Ú_date_parserŒ  s   rº   c                   @   s*   e Zd ZdZefdd„Z		ddd„ZdS )ÚBucketListerzList keys in a bucket.c                 C   ó   || _ || _d S rB   )Ú_clientrº   )r;   ÚclientÚdate_parserr'   r'   r(   rQ   ’  ó   
zBucketLister.__init__Nc                 c   sž   � |d|idœ}|d ur||d< |d ur|  |¡ | j d¡}|jd	i |¤Ž}|D ]#}| dg ¡}	|	D ]}
|d |
d  }|  |
d ¡|
d< ||
fV  q3q)d S )
NÚPageSize)ÚBucketÚPaginationConfigÚPrefixÚlist_objects_v2ÚContentsrg   ÚKeyÚLastModifiedr'   )Úupdater½   Úget_paginatorÚpaginateÚgetrº   )r;   rW   ÚprefixÚ	page_sizeÚ
extra_argsÚkwargsÚ	paginatorÚpagesÚpageÚcontentsÚcontentÚsource_pathr'   r'   r(   Úlist_objects–  s$   €
ÿüþzBucketLister.list_objects)NNN)rC   rD   rE   rF   rº   rQ   r×   r'   r'   r'   r(   r»   �  s    ÿr»   c                       s   e Zd Zd‡ fdd„	Z‡  ZS )Ú	PrintTaskFNc                    s   t t| ƒ | ||||¡S )aN  
        :param message: An arbitrary string associated with the entry.   This
            can be used to communicate the result of the task.
        :param error: Boolean indicating a failure.
        :param total_parts: The total number of parts for multipart transfers.
        :param warning: Boolean indicating a warning
        )ÚsuperrØ   Ú__new__)Úclsr’   r“   Útotal_partsr”   ©Ú	__class__r'   r(   rÚ   «  s   ÿzPrintTask.__new__)FNN)rC   rD   rE   rÚ   Ú__classcell__r'   r'   rÝ   r(   rØ   ©  s    rØ   )r’   r“   rÜ   r”   c                   @   s   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed d!„ ƒZed"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZd*S )+ÚRequestParamsMappera¸  A utility class that maps CLI params to request params

    Each method in the class maps to a particular operation and will set
    the request parameters depending on the operation and CLI parameters
    provided. For each of the class's methods the parameters are as follows:

    :type request_params: dict
    :param request_params: A dictionary to be filled out with the appropriate
        parameters for the specified client operation using the current CLI
        parameters

    :type cli_params: dict
    :param cli_params: A dictionary of the current CLI params that will be
        used to generate the request parameters for the specified operation

    For example, take the mapping of request parameters for PutObject::

        >>> cli_request_params = {'sse': 'AES256', 'storage_class': 'GLACIER'}
        >>> request_params = {}
        >>> RequestParamsMapper.map_put_object_params(
                request_params, cli_request_params)
        >>> print(request_params)
        {'StorageClass': 'GLACIER', 'ServerSideEncryption': 'AES256'}

    Note that existing parameters in ``request_params`` will be overridden if
    a parameter in ``cli_params`` maps to the existing parameter.
    c                 C   ó@   |   ||¡ |  ||¡ |  ||¡ |  ||¡ |  ||¡ dS )z*Map CLI params to PutObject request paramsN)Ú_set_general_object_paramsÚ_set_metadata_paramsÚ_set_sse_request_paramsÚ_set_sse_c_request_paramsÚ_set_request_payer_param©rÛ   Úrequest_paramsÚ
cli_paramsr'   r'   r(   Úmap_put_object_paramsÕ  ó
   z)RequestParamsMapper.map_put_object_paramsc                 C   ó   |   ||¡ |  ||¡ dS )z*Map CLI params to GetObject request paramsN©rå   ræ   rç   r'   r'   r(   Úmap_get_object_paramsÞ  ó   z)RequestParamsMapper.map_get_object_paramsc                 C   sV   |   ||¡ |  ||¡ |  ||¡ |  |¡ |  ||¡ |  ||¡ |  ||¡ dS )z+Map CLI params to CopyObject request paramsN)râ   Ú_set_metadata_directive_paramrã   Ú!_auto_populate_metadata_directiverä   Ú)_set_sse_c_and_copy_source_request_paramsræ   rç   r'   r'   r(   Úmap_copy_object_paramsä  s   
ÿz*RequestParamsMapper.map_copy_object_paramsc                 C   rì   )z+Map CLI params to HeadObject request paramsNrí   rç   r'   r'   r(   Úmap_head_object_paramsð  rï   z*RequestParamsMapper.map_head_object_paramsc                 C   rá   )z6Map CLI params to CreateMultipartUpload request paramsN)râ   rä   rå   rã   ræ   rç   r'   r'   r(   Ú"map_create_multipart_upload_paramsö  rë   z6RequestParamsMapper.map_create_multipart_upload_paramsc                 C   rì   )z+Map CLI params to UploadPart request paramsNrí   rç   r'   r'   r(   Úmap_upload_part_paramsÿ  rï   z*RequestParamsMapper.map_upload_part_paramsc                 C   rì   )z/Map CLI params to UploadPartCopy request paramsN)rò   ræ   rç   r'   r'   r(   Úmap_upload_part_copy_params  s   ÿz/RequestParamsMapper.map_upload_part_copy_paramsc                 C   ó   |   ||¡ d S rB   ©ræ   rç   r'   r'   r(   Úmap_delete_object_params  ó   z,RequestParamsMapper.map_delete_object_paramsc                 C   rø   rB   rù   rç   r'   r'   r(   Úmap_list_objects_v2_params  rû   z.RequestParamsMapper.map_list_objects_v2_paramsc                 C   ó   |  d¡r|d |d< d S d S )NÚrequest_payerÚRequestPayer©rÌ   rç   r'   r'   r(   ræ     ó   
ÿz,RequestParamsMapper._set_request_payer_paramc              
   C   sP   ddddddddd	d
œ	}|D ]}|  |¡r|| }|| ||< q|  ||¡ d S )NÚACLÚStorageClassÚWebsiteRedirectLocationÚContentTypeÚCacheControlÚContentDispositionÚContentEncodingÚContentLanguageÚExpires)	ÚaclÚstorage_classÚwebsite_redirectÚcontent_typeÚcache_controlÚcontent_dispositionÚcontent_encodingÚcontent_languageÚexpires)rÌ   Ú_set_grant_params)rÛ   rè   ré   Úgeneral_param_translationÚcli_param_nameÚrequest_param_namer'   r'   r(   râ     s    ÷
€z.RequestParamsMapper._set_general_object_paramsc              	   C   sZ   |  d¡r)|d D ]!}z
| dd¡\}}W n ty    tdƒ‚w |||  |¡< q	d S d S )NÚgrantsú=r   z1grants should be of the form permission=principal)rÌ   rl   r1   Ú_permission_to_param)rÛ   rè   ré   ÚgrantÚ
permissionÚgranteer'   r'   r(   r  /  s   
ÿùz%RequestParamsMapper._set_grant_paramsc                 C   s8   |dkrdS |dkrdS |dkrdS |dkrdS t d	ƒ‚)
NÚreadÚ	GrantReadÚfullÚGrantFullControlÚreadaclÚGrantReadACPÚwriteaclÚGrantWriteACPz5permission must be one of: read|readacl|writeacl|full)r1   )rÛ   r  r'   r'   r(   r  :  s   z(RequestParamsMapper._permission_to_paramc                 C   rý   )NÚmetadataÚMetadatar   rç   r'   r'   r(   rã   G  r  z(RequestParamsMapper._set_metadata_paramsc                 C   s(   |  d¡r|  d¡sd|d< d S d S d S )Nr'  ÚMetadataDirectiveÚREPLACEr   )rÛ   rè   r'   r'   r(   rñ   L  s
   
ÿþz5RequestParamsMapper._auto_populate_metadata_directivec                 C   rý   )NÚmetadata_directiver(  r   rç   r'   r'   r(   rð   R  s
   
ÿÿz1RequestParamsMapper._set_metadata_directive_paramc                 C   s4   |  d¡r|d |d< |  d¡r|d |d< d S d S )NÚsseÚServerSideEncryptionÚsse_kms_key_idÚSSEKMSKeyIdr   rç   r'   r'   r(   rä   X  s
   

ÿz+RequestParamsMapper._set_sse_request_paramsc                 C   ó*   |  d¡r|d |d< |d |d< d S d S )NÚsse_cÚSSECustomerAlgorithmÚ	sse_c_keyÚSSECustomerKeyr   rç   r'   r'   r(   rå   _  s   
þz-RequestParamsMapper._set_sse_c_request_paramsc                 C   r/  )NÚsse_c_copy_sourceÚCopySourceSSECustomerAlgorithmÚsse_c_copy_source_keyÚCopySourceSSECustomerKeyr   rç   r'   r'   r(   Ú%_set_sse_c_copy_source_request_paramse  s   
ÿÿýz9RequestParamsMapper._set_sse_c_copy_source_request_paramsc                 C   s   |   ||¡ |  ||¡ d S rB   )rå   r8  rç   r'   r'   r(   rò   m  rï   z=RequestParamsMapper._set_sse_c_and_copy_source_request_paramsN)rC   rD   rE   rF   Úclassmethodrê   rî   ró   rô   rõ   rö   r÷   rú   rü   ræ   râ   r  r  rã   rñ   rð   rä   rå   r8  rò   r'   r'   r'   r(   rà   ¹  sT    



















rà   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )ÚProvideSizeSubscriberzK
    A subscriber which provides the transfer size before it's queued.
    c                 C   rœ   rB   )rV   )r;   rV   r'   r'   r(   rQ   x  rŸ   zProvideSizeSubscriber.__init__c                 K   s   |j  | j¡ d S rB   )ÚmetaÚprovide_transfer_sizerV   )r;   ÚfuturerÐ   r'   r'   r(   Ú	on_queued{  s   zProvideSizeSubscriber.on_queuedN)rC   rD   rE   rF   rQ   r?  r'   r'   r'   r(   r;  t  s    r;  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚOnDoneFilteredSubscriberzÙSubscriber that differentiates between successes and failures

    It is really a convenience class so developers do not have to have
    to constantly remember to have a general try/except around future.result()
    c              
   K   s\   d }z|  ¡  W n ty } z|}W Y d }~nd }~ww |r'|  ||¡ d S |  |¡ d S rB   )ÚresultÚ	ExceptionÚ_on_failureÚ_on_success)r;   r>  rÐ   Úfuture_exceptionr}   r'   r'   r(   Úon_doneˆ  s   €ÿz OnDoneFilteredSubscriber.on_donec                 C   ó   d S rB   r'   ©r;   r>  r'   r'   r(   rD  –  ó   z$OnDoneFilteredSubscriber._on_successc                 C   rG  rB   r'   ©r;   r>  r}   r'   r'   r(   rC  ™  rI  z$OnDoneFilteredSubscriber._on_failureN)rC   rD   rE   rF   rF  rD  rC  r'   r'   r'   r(   r@  ‚  s
    r@  c                   @   r:  )ÚDeleteSourceSubscriberz6A subscriber which deletes the source of the transfer.c              
   C   sB   z|   |¡ W d S  ty  } z| |¡ W Y d }~d S d }~ww rB   )Ú_delete_sourcerB  Úset_exceptionrJ  r'   r'   r(   rD  Ÿ  s   €ÿz"DeleteSourceSubscriber._on_successc                 C   ó   t dƒ‚)Nz_delete_source()©ÚNotImplementedErrorrH  r'   r'   r(   rL  ¥  ó   z%DeleteSourceSubscriber._delete_sourceN)rC   rD   rE   rF   rD  rL  r'   r'   r'   r(   rK  �  s    rK  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚDeleteSourceObjectSubscriberz%A subscriber which deletes an object.c                 C   rœ   rB   )r½   )r;   r¾   r'   r'   r(   rQ   «  rŸ   z%DeleteSourceObjectSubscriber.__init__c                 C   ó   |j S rB   )rW   ©r;   Ú	call_argsr'   r'   r(   Ú_get_bucket®  ó   z(DeleteSourceObjectSubscriber._get_bucketc                 C   rS  rB   )rf   rT  r'   r'   r(   Ú_get_key±  rW  z%DeleteSourceObjectSubscriber._get_keyc                 C   sN   |j j}|  |¡|  |¡dœ}|j d¡r|jd |d< | jjdi |¤Ž d S )N)rÂ   rÇ   rÿ   r'   )r<  rU  rV  rX  rÏ   rÌ   r½   Údelete_object)r;   r>  rU  Údelete_object_kwargsr'   r'   r(   rL  ´  s   þÿz+DeleteSourceObjectSubscriber._delete_sourceN)rC   rD   rE   rF   rQ   rV  rX  rL  r'   r'   r'   r(   rR  ©  s    rR  c                   @   r:  )Ú DeleteCopySourceObjectSubscriberz+A subscriber which deletes the copy source.c                 C   ó
   |j d S )NrÂ   ©Úcopy_sourcerT  r'   r'   r(   rV  Â  rŸ   z,DeleteCopySourceObjectSubscriber._get_bucketc                 C   r\  ©NrÇ   r]  rT  r'   r'   r(   rX  Å  rŸ   z)DeleteCopySourceObjectSubscriber._get_keyN)rC   rD   rE   rF   rV  rX  r'   r'   r'   r(   r[  À  s    r[  c                   @   ó   e Zd ZdZdd„ ZdS )ÚDeleteSourceFileSubscriberz"A subscriber which deletes a file.c                 C   s   t  |jjj¡ d S rB   )rs   Úremover<  rU  ÚfileobjrH  r'   r'   r(   rL  Ë  s   z)DeleteSourceFileSubscriber._delete_sourceN)rC   rD   rE   rF   rL  r'   r'   r'   r(   ra  É  ó    ra  c                   @   r:  )Ú BaseProvideContentTypeSubscriberz@A subscriber that provides content type when creating s3 objectsc                 K   s,   t |  |¡ƒ}|d ur||jjjd< d S d S )Nr  )r©   Ú_get_filenamer<  rU  rÏ   )r;   r>  rÐ   Úguessed_typer'   r'   r(   r?  Ò  s   ÿz*BaseProvideContentTypeSubscriber.on_queuedc                 C   rN  )Nz_get_filename()rO  rH  r'   r'   r(   rf  ×  rQ  z.BaseProvideContentTypeSubscriber._get_filenameN)rC   rD   rE   rF   r?  rf  r'   r'   r'   r(   re  Ï  s    re  c                   @   ó   e Zd Zdd„ ZdS )Ú"ProvideUploadContentTypeSubscriberc                 C   s
   |j jjS rB   )r<  rU  rc  rH  r'   r'   r(   rf  Ü  rŸ   z0ProvideUploadContentTypeSubscriber._get_filenameN©rC   rD   rE   rf  r'   r'   r'   r(   ri  Û  ó    ri  c                   @   rh  )Ú ProvideCopyContentTypeSubscriberc                 C   s   |j jjd S r_  )r<  rU  r^  rH  r'   r'   r(   rf  á  s   z.ProvideCopyContentTypeSubscriber._get_filenameNrj  r'   r'   r'   r(   rl  à  rk  rl  c                   @   r:  )Ú!ProvideLastModifiedTimeSubscriberz Sets utime for a downloaded filec                 C   r¼   rB   )Ú_last_modified_timeÚ_result_queue)r;   Úlast_modified_timeÚresult_queuer'   r'   r(   rQ   ç  rÀ   z*ProvideLastModifiedTimeSubscriber.__init__c              
   K   sx   |j jj}z| j ¡ }t |¡}t|t|ƒƒ W d S  t	y; } zd||f }| j
 t||ƒ¡ W Y d }~d S d }~ww )NzNSuccessfully Downloaded %s but was unable to update the last modified time. %s)r<  rU  rc  rn  Ú	timetupleÚtimeÚmktimer·   r0   rB  ro  Úputrš   )r;   r>  rÐ   r¨   Úlast_update_tupleÚmod_timestampr}   r™   r'   r'   r(   rD  ë  s   


ÿÿ €üz-ProvideLastModifiedTimeSubscriber._on_successN)rC   rD   rE   rF   rQ   rD  r'   r'   r'   r(   rm  å  s    rm  c                   @   r`  )ÚDirectoryCreatorSubscriberz4Creates a directory to download if it does not existc              
   K   sx   t j |jjj¡}zt j |¡st  |¡ W d S W d S  ty; } z|j	t	j
ks0td||f ƒ‚W Y d }~d S d }~ww )Nz!Could not create directory %s: %s)rs   r{   r®   r<  rU  rc  ÚexistsÚmakedirsrx   r³   ÚEEXISTrH   )r;   r>  rÐ   Údr}   r'   r'   r(   r?  ú  s   ÿ
ÿÿ€ÿz$DirectoryCreatorSubscriber.on_queuedN)rC   rD   rE   rF   r?  r'   r'   r'   r(   rx  ø  rd  rx  c                   @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚNonSeekableStreama¤  Wrap a file like object as a non seekable stream.

    This class is used to wrap an existing file like object
    such that it only has a ``.read()`` method.

    There are some file like objects that aren't truly seekable
    but appear to be.  For example, on windows, sys.stdin has
    a ``seek()`` method, and calling ``seek(0)`` even appears
    to work.  However, subsequent ``.read()`` calls will just
    return an empty string.

    Consumers of these file like object have no way of knowing
    if these files are truly seekable or not, so this class
    can be used to force non-seekable behavior when you know
    for certain that a fileobj is non seekable.

    c                 C   rœ   rB   )Ú_fileobj)r;   rc  r'   r'   r(   rQ     rŸ   zNonSeekableStream.__init__Nc                 C   s   |d u r	| j  ¡ S | j  |¡S rB   )r~  r  )r;   Úamtr'   r'   r(   r    s   
zNonSeekableStream.readrB   )rC   rD   rE   rF   rQ   r  r'   r'   r'   r(   r}    s    r}  rB   )T)HÚargparseÚloggingr   r£   r³   rs   Úrers  Úcollectionsr   r   Údateutil.parserr   Údateutil.tzr   r   Ús3transfer.subscribersr   Úawscli.compatr	   r
   Ú	getLoggerrC   r¦   r   Ú
EPOCH_TIMEÚMAX_UPLOAD_SIZEr/   Úcompileri   rk   rb   r`   r)   r4   ÚActionr5   rB  rH   rP   rK   re   ro   rr   r   r‘   rš   Úobjectr›   r©   r{   Úcurdirr±   r·   rµ   rº   r»   rØ   r•   rà   r;  r@  rK  rR  r[  ra  re  ri  rl  rm  rx  r}  r'   r'   r'   r(   Ú<module>   s–   
ø
ÿÿÿÿ ,

ÿ <	