
    E^ec                         d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
Z
ddlmZ ddlmZ ddlmZmZ 	 	 	 ddededddedee         f
dZdS )zHUtility functions for handling and fetching repo archives in zip format.    N)Path)Optional)
BadZipFileZipFile)InvalidZipRepository)read_repo_password)make_sure_path_existsprompt_and_delete.Fzip_uriis_urlclone_to_dirzos.PathLike[str]no_inputpasswordc                     t          |                                          }t          |           |r|                     dd          d         }t          j                            ||          }t          j                            |          rt          ||          }nd}|rpt          j
        | dd          }t          |d          5 }	|                    d	          D ]}
|
r|	                    |
           	 d
d
d
           n# 1 swxY w Y   nt          j                            |           }	 t          |          }t!          |                                          dk    rt%          d|  d          |                                d         }|                    d          st%          d|  d          |d
d         }t)          j                    }t          j                            ||          }	 |                    |           n# t.          $ r |I	 |                    ||                    d                     n# t.          $ r t%          d          w xY w|rt%          d          d}|i	 t3          d          }|                    ||                    d                     d
}n*# t.          $ r |dz  }|dk    rt%          d          Y nw xY w|iY nw xY wn!# t4          $ r t%          d|  d          w xY w|S )a  Download and unpack a zipfile at a given URI.

    This will download the zipfile to the cookiecutter repository,
    and unpack into a temporary directory.

    :param zip_uri: The URI for the zipfile.
    :param is_url: Is the zip URI a URL or a file?
    :param clone_to_dir: The cookiecutter repository directory
        to put the archive into.
    :param no_input: Do not prompt for user input and eventually force a refresh of
        cached resources.
    :param password: The password to use when unpacking the repository.
    /   )r   Td   )streamtimeoutwbi   )
chunk_sizeNr   zZip repository z	 is emptyz' does not include a top-level directory)pathzutf-8)r   pwdz2Invalid password provided for protected repositoryz.Unable to unlock password protected repositoryzRepo password   z is not a valid zip archive:)r   
expanduserr	   rsplitosr   joinexistsr
   requestsgetopeniter_contentwriteabspathr   lennamelistr   endswithtempfilemkdtemp
extractallRuntimeErrorencoder   r   )r   r   r   r   r   
identifierzip_pathdownloadrfchunkzip_filefirst_filenameproject_name
unzip_base
unzip_pathretrys                    4lib/python3.11/site-packages/cookiecutter/zipfile.pyunzipr=      s   * %%0022L,''' , ^^C++A.
7<<j997>>(## 	(HEEEHHH 	'WT3???Ah%% '^^t^<< ' 'E ''' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 7??7++7
8$$x  ""##q((&'K'K'K'KLLL "**,,Q/&&s++ 	&R'RRR  
 &crc*%''
W\\*l;;
	Z0000 	 	 	 #''ZX__W=U=U'VVVV#   .L    *D   '#5o#F#F ++!+1I1I ,    !%'   
 A::"6 T# #  &: '!	<  
 
 
"CgCCC
 
 	


 s   1D		DD5CK- <H K- K) *I
K)I%%K)>;J:9K):$K!K) K!!K)&K- (K))K- -L)r   FN)__doc__r   r+   pathlibr   typingr   zipfiler   r   r"   cookiecutter.exceptionsr   cookiecutter.promptr   cookiecutter.utilsr	   r
   strboolr=        r<   <module>rI      s
   N N 				              ' ' ' ' ' ' ' '  8 8 8 8 8 8 2 2 2 2 2 2 G G G G G G G G (+"i iii %i 	i
 smi i i i i irH   