o
    !dJr                  	   @   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)ZKiBZMiBZGiBZTiBZPiBZEiBi     )tzinfol           i   i   @l        )ZkbmbZgbtbZkibZmibZgibZ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baseZ	bytes_intisuffixZunit r   Busr/lib/python3.10/site-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

    NZibr   zInvalid size value: %s)lowerlenSIZE_SUFFIXint
ValueError)r   r   Zhas_size_identifierZ
multiplierr   r   r   human_readable_to_bytesc   s   	
r#   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valuesZoption_stringZfilter_listr   r   r   __call__   s
   zAppendFilter.__call__N)__name__
__module____qualname____doc__r.   r   r   r   r   r$   ~   s    r$   c                   @      e Zd ZdS )CreateDirectoryErrorNr0   r1   r2   r   r   r   r   r5          r5   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*   r:   Zmax_priorityr   r   r   r>      s   
zStablePriorityQueue.__init__c                 C   s    d}| j D ]}|t|7 }q|S r%   )r@   r   )r*   sizebucketr   r   r   _qsize   s   
zStablePriorityQueue._qsizec                 C   s*   t t|d| j| j}| j| | d S )NZPRIORITY)minr&   rA   r@   r(   )r*   itempriorityr   r   r   _put   s   zStablePriorityQueue._putc                 C   s    | j D ]
}|sq|   S d S r/   )r@   popleft)r*   rC   r   r   r   _get   s
   
zStablePriorityQueue._getN)r   r9   )r0   r1   r2   r3   r>   rD   rH   rJ   r   r   r   r   r8      s    
r8   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matchr"   *_S3_OUTPOST_BUCKET_ARN_TO_BUCKET_KEY_REGEXs3_pathr   r   r   block_unsupported_resources   s   

rP   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
    rC   key/r   r    )rP   #_S3_ACCESSPOINT_TO_BUCKET_KEY_REGEXrL   group_S3_OUTPOST_TO_BUCKET_KEY_REGEXsplitr   )rO   rL   Zs3_componentsrC   Zs3_keyr   r   r   find_bucket_key   s   

rX   c                 C   s   |  dr| dd } t| S )zSplit s3 path into bucket and key prefix.

    This will also handle the s3:// prefix.

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

    zs3://   N)
startswithrX   rN   r   r   r   split_s3_bucket_key   s   
r[   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IOErrorr"   r   fromtimestampst_mtimer   OSErrorOverflowErrorst_size)pathZstatseZupdate_timer   r   r   get_file_stat   s   
	rf   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.
    srcr'   typeNrd   rR   )Zs3localZdir_opZuse_src_name)r\   sepr   rW   replace)
filesZsrc_pathrg   r'   Zsrc_typeZ	dest_typeZ	sep_tablerel_pathZcompare_keyZ	dest_pathr   r   r   find_dest_path_comp_key  s&   ro   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)rd   Zerror_messageZ	skip_fileZprint_stringwarning_messager   r   r   create_warning0  s   ru   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 r/   )_stdout)r*   stdoutr   r   r   r>   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	   rx   )r*   br   r   r   writeE  s   zStdoutBytesWriter.writer/   )r0   r1   r2   r3   r>   r|   r   r   r   r   rv   =  s    
rv   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)	mimetypesZ
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 )zCross 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.

    )r\   rd   rW   relpathjoinr"   abspath)r   startdirnamebasenameZ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)r\   utimera   errnoEPERMSetFileUtimeError)r   Zdesired_timere   r   r   r   set_file_utimet  s   	r   c                   @   r4   )r   Nr6   r   r   r   r   r     r7   r   c                 C   s   t | t S r/   )r   
astimezoner   )Z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 r/   )_clientr   )r*   clientZdate_parserr   r   r   r>        
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 )
NZPageSize)BucketZPaginationConfigZPrefixZlist_objects_v2ZContentsrR   KeyZLastModifiedr   )updater   Zget_paginatorZpaginategetr   )r*   rC   prefixZ	page_size
extra_argskwargsZ	paginatorZpagesZpagecontentscontentsource_pathr   r   r   list_objects  s$   
zBucketLister.list_objects)NNN)r0   r1   r2   r3   r   r>   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__)clsrp   rq   total_partsrr   	__class__r   r   r     s   zPrintTask.__new__)FNN)r0   r1   r2   r   __classcell__r   r   r   r   r     s    r   )rp   rq   r   rr   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 r/   r   r   r   r   r   map_delete_object_params     z,RequestParamsMapper.map_delete_object_paramsc                 C   r   r/   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 )NZ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 )NZACLZStorageClassZWebsiteRedirectLocationContentTypeZCacheControlContentDispositionZContentEncodingZContentLanguageZExpires)	ZaclZstorage_classZwebsite_redirectcontent_typeZcache_controlcontent_dispositionZcontent_encodingZcontent_languageZexpires)r   _set_grant_params)r   r   r   Zgeneral_param_translationZcli_param_nameZ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 )NZgrants=r   z1grants should be of the form permission=principal)r   rW   r"   _permission_to_param)r   r   r   Zgrant
permissionZ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readZ	GrantReadfullZGrantFullControlZreadaclZGrantReadACPZwriteaclZGrantWriteACPz5permission must be one of: read|readacl|writeacl|full)r"   )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   MetadataDirectiveZREPLACEr   )r   r   r   r   r   r   L  s
   
z5RequestParamsMapper._auto_populate_metadata_directivec                 C   r   )NZ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 )NZsseZServerSideEncryptionZsse_kms_key_idZ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 )NZsse_cZSSECustomerAlgorithmZ	sse_c_keyZSSECustomerKeyr   r   r   r   r   r   _  s   
z-RequestParamsMapper._set_sse_c_request_paramsc                 C   r   )NZsse_c_copy_sourceZCopySourceSSECustomerAlgorithmZsse_c_copy_source_keyZ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 r/   )r   r   r   r   r   r   r   m  r   z=RequestParamsMapper._set_sse_c_and_copy_source_request_paramsN)r0   r1   r2   r3   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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   rw   r/   )rB   )r*   rB   r   r   r   r>   x  rz   zProvideSizeSubscriber.__init__c                 K   s   |j | j d S r/   )metaZprovide_transfer_sizerB   )r*   futurer   r   r   r   	on_queued{  s   zProvideSizeSubscriber.on_queuedN)r0   r1   r2   r3   r>   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 )	OnDoneFilteredSubscriberzSubscriber 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 r/   )result	Exception_on_failure_on_success)r*   r   r   Zfuture_exceptionre   r   r   r   on_done  s   z OnDoneFilteredSubscriber.on_donec                 C      d S r/   r   r*   r   r   r   r   r        z$OnDoneFilteredSubscriber._on_successc                 C   r   r/   r   r*   r   re   r   r   r   r     r   z$OnDoneFilteredSubscriber._on_failureN)r0   r1   r2   r3   r   r   r   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 r/   )_delete_sourcer   Zset_exceptionr   r   r   r   r     s   z"DeleteSourceSubscriber._on_successc                 C      t d)Nz_delete_source()NotImplementedErrorr   r   r   r   r        z%DeleteSourceSubscriber._delete_sourceN)r0   r1   r2   r3   r   r   r   r   r   r   r     s    r   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   rw   r/   )r   )r*   r   r   r   r   r>     rz   z%DeleteSourceObjectSubscriber.__init__c                 C      |j S r/   )rC   r*   	call_argsr   r   r   _get_bucket     z(DeleteSourceObjectSubscriber._get_bucketc                 C   r   r/   )rQ   r   r   r   r   _get_key  r   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   r   r   r   r   r   r   Zdelete_object)r*   r   r   Zdelete_object_kwargsr   r   r   r     s   z+DeleteSourceObjectSubscriber._delete_sourceN)r0   r1   r2   r3   r>   r   r   r   r   r   r   r   r     s    r   c                   @   r   ) DeleteCopySourceObjectSubscriberz+A subscriber which deletes the copy source.c                 C   
   |j d S )Nr   copy_sourcer   r   r   r   r     rz   z,DeleteCopySourceObjectSubscriber._get_bucketc                 C   r   Nr   r   r   r   r   r   r     rz   z)DeleteCopySourceObjectSubscriber._get_keyN)r0   r1   r2   r3   r   r   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 r/   )r\   remover   r   fileobjr   r   r   r   r     s   z)DeleteSourceFileSubscriber._delete_sourceN)r0   r1   r2   r3   r   r   r   r   r   r         r   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   r   r   )r*   r   r   Zguessed_typer   r   r   r     s   z*BaseProvideContentTypeSubscriber.on_queuedc                 C   r   )Nz_get_filename()r   r   r   r   r   r    r   z.BaseProvideContentTypeSubscriber._get_filenameN)r0   r1   r2   r3   r   r  r   r   r   r   r    s    r  c                   @      e Zd Zdd ZdS )"ProvideUploadContentTypeSubscriberc                 C   s
   |j jjS r/   )r   r   r   r   r   r   r   r    rz   z0ProvideUploadContentTypeSubscriber._get_filenameNr0   r1   r2   r  r   r   r   r   r        r  c                   @   r  ) ProvideCopyContentTypeSubscriberc                 C   s   |j jjd S r   )r   r   r   r   r   r   r   r    s   z.ProvideCopyContentTypeSubscriber._get_filenameNr  r   r   r   r   r    r  r  c                   @   r   )!ProvideLastModifiedTimeSubscriberz Sets utime for a downloaded filec                 C   r   r/   )_last_modified_time_result_queue)r*   Zlast_modified_timeZresult_queuer   r   r   r>     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   r   r   r	  	timetupletimemktimer   r!   r   r
  putru   )r*   r   r   r   Zlast_update_tupleZmod_timestampre   rt   r   r   r   r     s   


 z-ProvideLastModifiedTimeSubscriber._on_successN)r0   r1   r2   r3   r>   r   r   r   r   r   r    s    r  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)r\   rd   r   r   r   r   existsmakedirsra   r   EEXISTr5   )r*   r   r   dre   r   r   r   r     s   
z$DirectoryCreatorSubscriber.on_queuedN)r0   r1   r2   r3   r   r   r   r   r   r    r   r  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   rw   r/   )_fileobj)r*   r   r   r   r   r>     rz   zNonSeekableStream.__init__Nc                 C   s   |d u r	| j  S | j |S r/   )r  r   )r*   Zamtr   r   r   r     s   
zNonSeekableStream.readr/   )r0   r1   r2   r3   r>   r   r   r   r   r   r    s    r  r/   )T)Hargparseloggingr   r~   r   r\   rer  collectionsr   r   Zdateutil.parserr   Zdateutil.tzr   r   Zs3transfer.subscribersr   Zawscli.compatr	   r
   	getLoggerr0   r   r   Z
EPOCH_TIMEZMAX_UPLOAD_SIZEr    compilerT   rV   rM   rK   r   r#   ZActionr$   r   r5   r=   r8   rP   rX   r[   rf   ro   ru   objectrv   r   rd   curdirr   r   r   r   r   r   rs   r   r   r   r   r   r   r   r  r  r  r  r  r  r   r   r   r   <module>   s   

 ,

 <	