
    h                         S r SSKrSSKrSSKrSSKrSSKrSSKJr   " S S\5      r	 " S S\	5      r
S r " S	 S
5      r " S S5      r " S S\5      r " S S\5      r\R#                  S\5      r\\S'   g)a  
Based on "python-archive" -- https://pypi.org/project/python-archive/

Copyright (c) 2010 Gary Wilson Jr. <gary.wilson@gmail.com> and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
    N)SuspiciousOperationc                       \ rS rSrSrSrg)ArchiveException"   z.
Base exception class for all archive errors.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       F/var/www/html/env/lib/python3.13/site-packages/django/utils/archive.pyr   r   "       r   r   c                       \ rS rSrSrSrg)UnrecognizedArchiveFormat(   zC
Error raised when passed file is not a recognized archive format.
r   Nr   r   r   r   r   r   (   r   r   r   c                 p    [        U 5       nUR                  U5        SSS5        g! , (       d  f       g= f)zY
Unpack the tar or zip file at the specified path to the directory
specified by to_path.
N)Archiveextract)pathto_patharchives      r   r   r   .   s#    
 
'  
s   '
5c                   L    \ rS rSrSrS r\S 5       rS rS r	S r
S rS	 rS
rg)r   7   zE
The external API class that encapsulates an archive implementation.
c                 <    U R                  U5      " U5      U l        g N)_archive_cls_archiveselffiles     r   __init__Archive.__init__<   s    ))$/5r   c                    S n[        U [        5      (       a  U nO U R                  n[
        R                  R                  UR                  5       5      u  p4[        R                  U5      nU(       d6  [
        R                  R                  U5      u  p5[        R                  U5      nU(       d  [	        SU-  5      eU$ ! [         a    [	        S5      ef = f)Nz,File object not a recognized archive format.z(Path not a recognized archive format: %s)
isinstancestrnameAttributeErrorr   osr   splitextlowerextension_mapget)r#   clsfilenamebasetail_extexts         r   r   Archive._archive_cls?   s    dC  H99
 ))(..*:;)((.ID##C(C+:XE  
 " /B s   C   Cc                     U $ r   r   r"   s    r   	__enter__Archive.__enter__V   s    r   c                 $    U R                  5         g r   )close)r"   exc_type	exc_value	tracebacks       r   __exit__Archive.__exit__Y   s    

r   c                 :    U R                   R                  U5        g r   )r    r   )r"   r   s     r   r   Archive.extract\   s    g&r   c                 8    U R                   R                  5         g r   r    listr7   s    r   rE   Archive.list_   s    r   c                 8    U R                   R                  5         g r   r    r;   r7   s    r   r;   Archive.closeb       r   r    N)r	   r
   r   r   r   r$   staticmethodr   r8   r?   r   rE   r;   r   r   r   r   r   r   7   s9    6  ,'r   r   c                   F    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	rg
)BaseArchivef   zA
Base Archive class.  Implementations should inherit this class.
c                 b    U [         R                  -  (       a  [        R                  " X5        gg)z
If the file in the archive has some permissions (this assumes a file
won't be writable/executable without being readable), apply those
permissions to the unarchived file.
N)statS_IROTHr+   chmod)moder1   s     r   _copy_permissionsBaseArchive._copy_permissionsk   s!     $,,HHX$ r   c                     [        U5      nUR                  S5      R                  S5      nSU;   aB  SU;   a$  UR                  S5      UR                  S5      :  d  SU;  a  UR                  SS5      $ SU;   a  UR                  SS5      $ US4$ )N/\    )r(   lstripfindsplit)r"   r   s     r   split_leading_dirBaseArchive.split_leading_diru   s    4y{{3&&t,$;T\diintyy>4tCS::c1%%T\::dA&&8Or   c                 n    SnU H-  nU R                  U5      u  pEU(       d    gUc  UnM&  XB:w  d  M-    g   g)zw
Return True if all the paths have the same leading path name
(i.e., everything is in one subdirectory in an archive).
NFT)r_   )r"   pathscommon_prefixr   prefixrests         r   has_leading_dirBaseArchive.has_leading_dir   sD    
 D11$7LF& &(  r   c                    [         R                  R                  U5      n[         R                  R                  [         R                  R                  X25      5      nUR	                  U5      (       d  [        SU-  5      eU$ )Nz#Archive contains invalid path: '%s')r+   r   abspathjoin
startswithr   )r"   r   r)   target_pathr1   s        r   target_filenameBaseArchive.target_filename   sZ    ggoog.77??277<<#BC"";//%&Kd&RSSr   c                     [        S5      e)Nz:subclasses of BaseArchive must provide an extract() methodNotImplementedErrorr7   s    r   r   BaseArchive.extract   s    !H
 	
r   c                     [        S5      e)Nz6subclasses of BaseArchive must provide a list() methodrp   r7   s    r   rE   BaseArchive.list   s    !D
 	
r   r   N)r	   r
   r   r   r   rL   rU   r_   rf   rm   r   rE   r   r   r   r   rN   rN   f   s4     % %
 


r   rN   c                   ,    \ rS rSrS rS rS rS rSrg)
TarArchive   c                 :    [         R                  " U5      U l        g r   )tarfileopenr    r!   s     r   r$   TarArchive.__init__   s    T*r   c                 <    U R                   R                  " U0 UD6  g r   rD   r"   argskwargss      r   rE   TarArchive.list   s    D+F+r   c           
         U R                   R                  5       nU R                  S U 5       5      nU GH)  nUR                  nU(       a  U R	                  U5      S   nU R                  X5      nUR                  5       (       a   U(       a  [        R                  " USS9  Mo  Mq   U R                   R                  U5      n[        R                  R                  U5      nU(       a  [        R                  " USS9  [        US5       n	[        R                  " Xy5        U R                  UR                   U5        S S S 5        W(       a  UR)                  5         GM)  GM,     g ! , (       d  f       N.= f! ["        [$        4 a+  n
['        SU< SUR                  < SU
< 35         S n
A
NgS n
A
ff = f! W(       a  UR)                  5         f f = f)	Nc              3   8   #    U  H  oR                   v   M     g 7fr   )r)   ).0xs     r   	<genexpr>%TarArchive.extract.<locals>.<genexpr>   s     &?w!vvws   rZ   Texist_okwbzIn the tar file z the member z is invalid: )r    
getmembersrf   r)   r_   rm   isdirr+   makedirsextractfiler   dirnamerz   shutilcopyfileobjrU   rT   KeyErrorr*   printr;   )r"   r   membersleadingmemberr)   r1   	extractedr   outfileexcs              r   r   TarArchive.extract   s^   --**,&&&?w&??F;;D--d3A6++G:H||~~KK48 * $ 9 9& AI !ggooh7GGd;h-**9>..v{{HE . !!) !5 , .- !.1  c3  !!) !sI   'E5AF3	3E$<F3$
E2	.F35F0!F+&F3+F00F33Gc                 8    U R                   R                  5         g r   rH   r7   s    r   r;   TarArchive.close   rJ   r   rK   N	r	   r
   r   r   r$   rE   r   r;   r   r   r   r   rv   rv      s    +,*@r   rv   c                   ,    \ rS rSrS rS rS rS rSrg)
ZipArchive   c                 :    [         R                  " U5      U l        g r   )zipfileZipFiler    r!   s     r   r$   ZipArchive.__init__   s    -r   c                 <    U R                   R                  " U0 UD6  g r   )r    printdirr}   s      r   rE   ZipArchive.list   s    //r   c                    U R                   R                  5       nU R                  U5      nU GH  nU R                   R                  U5      nU R                   R	                  U5      nU(       a  U R                  U5      S   nU(       d  M^  U R                  X5      nUR                  S5      (       a  [        R                  " USS9  M  [        R                  R                  U5      nU(       a  [        R                  " USS9  [        US5       n	U	R                  U5        S S S 5        UR                  S-	  n
U R                  X5        GM      g ! , (       d  f       N4= f)NrZ   )rX   rY   Tr   r      )r    namelistrf   readgetinfor_   rm   endswithr+   r   r   r   rz   writeexternal_attrrU   )r"   r   r   r   r)   datainfor1   r   r   rT   s              r   r   ZipArchive.extract   s
   ==))+&&x0D==%%d+D==((.D--d3A6++G:H}}[))Ht4''//(3KK$7(D)WMM$' * ))R/&&t6'  *)s   E
E	c                 8    U R                   R                  5         g r   rH   r7   s    r   r;   ZipArchive.close   rJ   r   rK   Nr   r   r   r   r   r      s    .070r   r   )z.tarz.tar.bz2z.tbz2z.tbzz.tz2z.tar.gzz.tgzz.tazz	.tar.lzmaz.tlzz.tar.xzz.txzz.zip)r   r+   r   rQ   ry   r   django.core.exceptionsr   	Exceptionr   r   r   r   rN   rv   r   dictfromkeysr.   r   r   r   <module>r      s   0 
     6y  0 !, ,^:
 :
z( (V   F  " #f r   