o
    Ü!d‹  ã                   @   s   d dl Z G dd„ deƒZdS )é    Nc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
FileFormatc                 C   st   |   |¡\}}|   |¡\}}| j| jdœ}|d }	|| ||	ƒd }|| ||	ƒ\}}
||dœ||dœ|	|
dœ}|S )a‡  
        This function formats the source and destination
        path to the proper form for a file generator.

        Note that a file is designated as an s3 file if it begins with s3://

        :param src: The path of the source
        :type src: string
        :param dest: The path of the dest
        :type dest: string
        :param parameters: A dictionary that will be formed when the arguments
            of the command line have been parsed.  For this
            function the dictionary should have the key 'dir_op'
            which is a boolean value that is true when
            the operation is being performed on a local directory/
            all objects under a common prefix in s3 or false when
            it is on a single file/object.

        :returns: A dictionary that will be passed to a file generator.
            The dictionary contains the keys src, dest, dir_op, and
            use_src_name. src is a dictionary containing the source path
            and whether its located locally or in s3. dest is a dictionary
            containing the destination path and whether its located
            locally or in s3.
        )Ús3ÚlocalÚdir_opr   )ÚpathÚtype)ÚsrcÚdestr   Úuse_src_name)Úidentify_typeÚ	s3_formatÚlocal_format)Úselfr   r	   Ú
parametersZsrc_typeZsrc_pathZ	dest_typeZ	dest_pathZformat_tabler   r
   Úfiles© r   úGusr/lib/python3.10/site-packages/awscli/customizations/s3/fileformat.pyÚformat   s   þzFileFormat.formatc                 C   s`   t j |¡}t j |¡rt j |¡s|r|t j7 }|dfS | t j¡r,|t j7 }|dfS |dfS )a¤  
        This function formats the path of local files and returns whether the
        destination will keep its own name or take the source's name along with
        the edited path.
        Formatting Rules:
            1) If a destination file is taking on a source name, it must end
               with the appropriate operating system separator

        General Options:
            1) If the operation is on a directory, the destination file will
               always use the name of the corresponding source file.
            2) If the path of the destination exists and is a directory it
               will always use the name of the source file.
            3) If the destination path ends with the appropriate operating
               system seperator but is not an existing directory, the
               appropriate directories will be made and the file will use the
               source's name.
            4) If the destination path does not end with the appropriate
               operating system seperator and is not an existing directory, the
               appropriate directories will be created and the file name will
               be of the one provided.
        TF)Úosr   ÚabspathÚexistsÚisdirÚsepÚendswith)r   r   r   Ú	full_pathr   r   r   r   =   s   

zFileFormat.local_formatc                 C   s8   |r|  d¡s|d7 }|dfS |  d¡s|dfS |dfS )aj  
        This function formats the path of source files and returns whether the
        destination will keep its own name or take the source's name along
        with the edited path.
        Formatting Rules:
            1) If a destination file is taking on a source name, it must end
               with a forward slash.
        General Options:
            1) If the operation is on objects under a common prefix,
               the destination file will always use the name of the
               corresponding source file.
            2) If the path ends with a forward slash, the appropriate prefixes
               will be formed and will use the name of the source.
            3) If the path does not end with a forward slash, the appropriate
               prefix will be formed but use the the name provided as opposed
               to the source name.
        ú/TF)r   )r   r   r   r   r   r   r   _   s   

zFileFormat.s3_formatc                 C   s"   |  d¡rd|dd… fS d|fS )zú
        It identifies whether the path is from local or s3.  Returns the
        adjusted pathname and a string stating whether the file is from local
        or s3.  If from s3 it strips off the s3:// from the beginning of the
        path
        zs3://r   é   Nr   )Ú
startswith)r   r   r   r   r   r   {   s   
zFileFormat.identify_typeN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s
    ,"r   )r   Úobjectr   r   r   r   r   Ú<module>   s   