
    ed                         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mZ ddlmZ 	 	 	 dd	ed
edddedee   f
dZy)zHUtility functions for handling and fetching repo archives in zip format.    N)Path)Optional)
BadZipFileZipFile)InvalidZipRepository)prompt_and_deleteread_repo_password)make_sure_path_existszip_uriis_urlclone_to_dirzos.PathLike[str]no_inputpasswordc                 :   t        |      j                         }t        |       |r| j                  dd      d   }t        j
                  j                  ||      }t        j
                  j                  |      rt        ||      }nd}|ryt        j                  | dd      }t        |d      5 }	|j                  d	      D ]  }
|
s|	j                  |
        	 d
d
d
       nt        j
                  j                  |       }	 t        |      }t!        |j#                               dk(  rt%        d|  d      |j#                         d   }|j'                  d      st%        d|  d      |d
d }t)        j*                         }t        j
                  j                  ||      }	 |j-                  |       |S # 1 sw Y   xY w# t.        $ r |<	 |j-                  ||j1                  d             n# t.        $ r t%        d      w xY w|rt%        d      d}|X	 t3        d      }|j-                  ||j1                  d             d
}n$# t.        $ r |dz  }|dk(  rt%        d      Y nw xY w|XY |S w xY w# t4        $ r t%        d|  d      w xY w)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.12/site-packages/cookiecutter/zipfile.pyunzipr<      s   * %002L,' ^^C+A.
77<<j977>>(#(HEHHWT3?Ah% '^^t^< 'E'' ' 77??7+7
8$x  "#q(&	'KLL "**,Q/&&s+&!'*QR 
 &cr*%%'
WW\\*l;
	Z0H G' '@  	 #''ZX__W=U'V# .L  *D  '#5o#F ++!+1I ,  !%' 
 A:"6 T#  & '& G	<  
"gY&BC
 	

sy   1F>
F>B"J *G
 >G
I>"G98I>9HI>#/II>I41I>3I44I>:J =I>>J J).FN)__doc__r   r*   pathlibr   typingr   zipfiler   r   r!   cookiecutter.exceptionsr   cookiecutter.promptr   r	   cookiecutter.utilsr
   strboolr<        r;   <module>rI      sk    N 	    '  8 E 4 (+"iii %i 	i
 smirH   