Ë
    R/j	+  ã            	       ó^  — d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlZddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" edd	„«       Z# G d
„ d«      Z$edd„«       Z%edddee$dddfd„«       Z&ede$dddfd„«       Z'ede$dddfd„«       Z(ede$dddfd„«       Z)y)é    )Úcontextmanager)ÚbyrefÚcastÚc_charÚc_size_tÚc_void_pÚPOINTER)ÚjoinNé   )Úffi)ÚArchiveEntryÚFileType)ÚOPEN_CALLBACKÚWRITE_CALLBACKÚCLOSE_CALLBACKÚ
NO_OPEN_CBÚNO_CLOSE_CBÚARCHIVE_EOFÚ	page_sizeÚentry_sourcepathÚentry_clearÚread_disk_newÚread_disk_open_wÚread_next_header2Úread_disk_descendÚ	read_freeÚwrite_headerÚ
write_dataÚwrite_finish_entryÚread_disk_set_behaviorc              #   ó¾   K  — t        «       }t        ||«       |rt        j                  |«       t	        || «       	 |–— t        |«       y # t        |«       w xY w­w©N)r   r    r   Úread_disk_set_standard_lookupr   r   )ÚpathÚflagsÚlookupÚ	archive_ps       úB/home/josh/.local/lib/python3.12/site-packages/libarchive/write.pyÚnew_archive_read_diskr)      sL   è ø€ ä“€IÜ˜9 eÔ,ÙÜ×)Ñ)¨)Ô4Ü�Y Ô%ðØŠä�)ÕøŒ	�)Õüs   ‚:A½A ÁAÁAÁAc                   óT   — e Zd Zdd„Zd„ Zddddddœd„Zd	„ Zej                  d
fd„Z	y)ÚArchiveWritec                 ó    — || _         || _        y r"   )Ú_pointerÚheader_codec)Úselfr'   r.   s      r(   Ú__init__zArchiveWrite.__init__!   s   € Ø!ˆŒØ(ˆÕó    c           	      óÂ   — | j                   }|D ]N  }t        ||j                  «       |j                  «       D ]  }t	        ||t        |«      «       Œ t        |«       ŒP y)z.Add the given entries to the archive.
        N)r-   r   Ú_entry_pÚ
get_blocksr   Úlenr   )r/   ÚentriesÚwrite_pÚentryÚblocks        r(   Úadd_entrieszArchiveWrite.add_entries%   sZ   € ð —-‘-ˆØò 	(ˆEÜ˜ %§.¡.Ô1Ø×)Ñ)Ó+ò 7�Ü˜7 E¬3¨u«:Õ6ð7ä˜wÕ'ñ		(r1   r   FNT)r%   r&   ÚpathnameÚ	recursiveÚsymlink_modec          
      ó¼  — | j                   }t        j                  |«      }	|	dk  rd}	d}
|r	 t        t        d|› �«      }
t        | j                  ¬«      }|j                  }|D �]>  }t        |||«      5 }|
r |
|«       	 t        ||«      }|t        k(  r�n|j                  }|rB||k(  r|}n:|j                  |«      sJ ‚t        ||t        |«      d j!                  d«      «      }|j!                  d«      |_        |r |j"                  d
i |¤Ž t%        |«       t'        ||«       |j(                  rKt+        t-        |«      d	«      5 }	 |j/                  |	«      }|snt1        ||t        |«      «       Œ+	 ddd«       t3        |«       t5        |«       |sn�Œddd«       �ŒA y# t        $ r t        d|›d�«      d‚w xY w# 1 sw Y   ŒMxY w# 1 sw Y   �ŒvxY w)a‡  Read files through the OS and add them to the archive.

        Args:
            paths (str): the paths of the files to add to the archive
            flags (int):
                passed to the C function `archive_read_disk_set_behavior`;
                use the `libarchive.flags.READDISK_*` constants
            lookup (bool):
                when True, the C function `archive_read_disk_set_standard_lookup`
                is called to enable the lookup of user and group names
            pathname (str | None):
                the path of the file in the archive, defaults to the source path
            recursive (bool):
                when False, if a path in `paths` is a directory,
                only the directory itself is added.
            symlink_mode (Literal['hybrid', 'logical', 'physical'] | None):
                how symbolic links should be handled; see `man archive_read_disk`
                for meanings
            attributes (dict): passed to `ArchiveEntry.modify()`

        Raises:
            ArchiveError: if a file doesn't exist or can't be accessed, or if
                          adding it to the archive fails
        r   i (  NÚread_disk_set_symlink_zsymlink_mode value z is invalid)r.   ú/Úrb© )r-   r   Úwrite_get_bytes_per_blockÚgetattrÚAttributeErrorÚ
ValueErrorr   r.   r3   r)   r   r   r;   Ú
startswithr
   r5   ÚlstripÚmodifyr   r   ÚisregÚopenr   Úreadr   r   r   )r/   r%   r&   r;   r<   r=   ÚpathsÚ
attributesr7   Ú
block_sizeÚset_symlink_moder8   Úentry_pr$   Úread_pÚrÚ
entry_pathÚfÚdatas                      r(   Ú	add_fileszArchiveWrite.add_files/   s  € ð8 —-‘-ˆä×2Ñ2°7Ó;ˆ
Ø˜Š?ØˆJàÐÙðÜ#*ÜÐ1°,°Ð@ó$Ð ô ¨$×*;Ñ*;Ô<ˆØ—.‘.ˆØó !	ˆDÜ& t¨U°FÓ;ð  ¸vÙ#Ù$ VÔ,ØÜ)¨&°'Ó:�AØœKÒ'ÙØ!&§¡�JÙØ%¨Ò-Ø)1™Jà#-×#8Ñ#8¸Ô#>Ð>Ð#>Ü)-Ø (Ø *¬3¨t«9¨:Ð 6× =Ñ =¸cÓ Bó*˜Jð &0×%6Ñ%6°sÓ%;�E”NÙ!Ø$˜Ÿ™Ñ2 zÒ2Ü% fÔ-Ü  ¨'Ô2Ø—{’{Ü!Ô"2°7Ó";¸TÓBð EÀaØ"#Ø'(§v¡v¨jÓ'9 Ù'+Ø$)Ü *¨7°D¼#¸d»)Ô Dð	 #$ð %*÷	Eô ' wÔ/Ü Ô(Ù$Øñ; ÷ ñ  ñ!	øô "ò Ü Ø)¨,Ð)9¸ÐEóàððú÷>Eð Eú÷/ ñ  ús0   ®F( Á6CGÅ-GÅ9#GÆ(GÇGÇ
GÇG	c                 ó(   —  | j                   |fi |¤ŽS )z"Single-path alias of `add_files()`)rW   )r/   r$   Úkws      r(   Úadd_filezArchiveWrite.add_file�   s   € àˆt�~‰~˜dÑ) bÑ)Ð)r1   i´  c           	      óL  — | j                   }t        |t        «      r|f}n't        |t        «      rt	        dt        |«      z  «      ‚t        d||||| j                  dœ|¤Ž}t        ||j                  «       |D ]  }	|	s nt        ||	t        |	«      «       Œ t        |«       y)aË  "Add file from memory to archive.

        Args:
            entry_path (str | bytes): the file's path
            entry_size (int): the file's size, in bytes
            entry_data (bytes | Iterable[bytes]): the file's content
            filetype (int): see `libarchive.entry.ArchiveEntry.modify()`
            permission (int): see `libarchive.entry.ArchiveEntry.modify()`
            other_attributes: see `libarchive.entry.ArchiveEntry.modify()`
        z"entry_data: expected bytes, got %r)r;   ÚsizeÚfiletypeÚpermr.   NrB   )r-   Ú
isinstanceÚbytesÚstrÚ	TypeErrorÚtyper   r.   r   r3   r   r5   r   )
r/   rT   Ú
entry_sizeÚ
entry_datar]   Ú
permissionÚother_attributesÚarchive_pointerr8   Úchunks
             r(   Úadd_file_from_memoryz!ArchiveWrite.add_file_from_memory…   s®   € ð Ÿ-™-ˆä�j¤%Ô(Ø$˜‰JÜ˜
¤CÔ(ÜØ4´t¸JÓ7GÑGóð ô ð 
Ø j¸8Ø¨$×*;Ñ*;ñ
ð ñ
ˆô
 	�_ e§n¡nÔ5àò 	;ˆEÙÙÜ�¨¬s°5«zÕ:ð	;ô
 	˜?Õ+r1   )úutf-8)
Ú__name__Ú
__module__Ú__qualname__r0   r:   rW   rZ   r   ÚREGULAR_FILErj   rB   r1   r(   r+   r+      s8   „ ó)ò(ð  e°dÀdØôPòd*ð ×&Ñ&°5ô$,r1   r+   Ú c              #   ó@  K  — t        j                  «       }	  t        j                  | «      |«       |r t        j                  |«      |«       |r'd|vr#| dk(  rt	        j
                  d«       ||rdndz  }|r7t        |t        «      s|j                  d«      }t        j                  ||«       |r8t        |t        «      s|j                  d«      }	 t        j                  ||«       |–— t        j                  |«       t        j                   |«       t&        d	„ «       }y # t        $ r3 t        dt        j                  «       › dt         j                  › d�«      ‚w xY w# t"        $ r, t        j$                  |«       t        j                   |«       ‚ w xY w­w)
NÚ
encryptionÚzipzÖThe default encryption scheme of zip archives is weak. Use `options='encryption=$type'` to specify the encryption type you want to use. The supported values are 'zipcrypt' (the weak default), 'aes128' and 'aes256'.z,encryptionrk   z#the libarchive being used (version z, path z) doesn't support encryptionc                 óB   — t        j                  | j                  d«      S )Néÿÿÿÿ)r   Úfilter_bytesr-   )r/   s    r(   Úbytes_writtenz(new_archive_write.<locals>.bytes_writtenÒ   s   € ä×Ñ §¡¨rÓ2Ð2r1   )r   Ú	write_newÚget_write_format_functionÚget_write_filter_functionÚwarningsÚwarnr_   r`   ÚencodeÚwrite_set_optionsÚwrite_set_passphraserE   ÚNotImplementedErrorÚversion_numberÚlibarchive_pathÚwrite_closeÚ
write_freeÚ	ExceptionÚ
write_failÚproperty)Úformat_nameÚfilter_nameÚoptionsÚ
passphraser'   rw   s         r(   Únew_archive_writerŒ   ¬   s{  è ø€ ä—‘“€Ið!Ø2Œ×%Ñ% kÓ2°9Ô=ÙØ6ŒC×)Ñ)¨+Ó6°yÔAÙ˜,¨gÑ5Ø˜eÒ#Ü—‘ðAôð ©‘}°\ÑAˆGÙÜ˜g¤uÔ-Ø!Ÿ.™.¨Ó1�Ü×!Ñ! )¨WÔ5ÙÜ˜j¬%Ô0Ø'×.Ñ.¨wÓ7�
ðÜ×(Ñ(¨°JÔ?ð ŠÜ�‰˜	Ô"Ü�‰�yÔ!ô ñ3ó ñ3øô "ò Ü)Ø9¼#×:LÑ:LÓ:NÐ9Oð PÜ×/Ñ/Ð0Ð0LðNóð ðûô ò Ü�‰�yÔ!Ü�‰�yÔ!Øðüs5   ‚F˜B=E& ÃD' Ã,.E& ÄFÄ'<E#Å#E& Å&5FÆFrk   c
              #   ó`  ‡ K  — ˆ fd„}
|rt        |«      nt        }t        |
«      }|rt        |«      nt        }t        ||||«      5 }t        j                  |d«       t        j                  ||«       t        j                  |d|||«        |||	«      –— ddd«       y# 1 sw Y   yxY w­w)z´Create an archive and send it in chunks to the `write_func` function.

    For formats and filters, see `WRITE_FORMATS` and `WRITE_FILTERS` in the
    `libarchive.ffi` module.
    c                 óR   •— t        |t        t        |z  «      «      d   } ‰|«      S )Nr   )r   r	   r   )r'   ÚcontextÚbuffer_ÚlengthrV   Ú
write_funcs        €r(   Úwrite_cb_internalz(custom_writer.<locals>.write_cb_internalä   s(   ø€ Ü�GœW¤V¨f¡_Ó5Ó6°qÑ9ˆÙ˜$ÓÐr1   r   N)
r   r   r   r   r   rŒ   r   Úwrite_set_bytes_in_last_blockÚwrite_set_bytes_per_blockÚ
write_open)r’   rˆ   r‰   Ú	open_funcÚ
close_funcrO   Úarchive_write_classrŠ   r‹   r.   r“   Úopen_cbÚwrite_cbÚclose_cbr'   s   `              r(   Úcustom_writerr�   ×   sž   øè ø€ ô ñ +4Œm˜IÔ&¼€GÜÐ/Ó0€HÙ-7Œ~˜jÔ)¼[€Hä	˜;¨°WØ%ó
'ð ;Ø*3Ü×)Ñ)¨)°QÔ7Ü×%Ñ% i°Ô<Ü�‰�y $¨°¸8ÔDÙ! )¨\Ó:Ò:÷;÷ ;ñ ;üs   ƒAB.ÁAB"Â	B.Â"B+Â'B.c              #   ó”   K  — t        ||||«      5 }t        j                  || «        |||«      –— ddd«       y# 1 sw Y   yxY w­w)z¥Create an archive and write it into a file descriptor.

    For formats and filters, see `WRITE_FORMATS` and `WRITE_FILTERS` in the
    `libarchive.ffi` module.
    N)rŒ   r   Úwrite_open_fd)Úfdrˆ   r‰   r™   rŠ   r‹   r.   r'   s           r(   Ú	fd_writerr¡   ô   sM   è ø€ ô 
˜;¨°WØ%ó
'ð ;Ø*3Ü×Ñ˜) RÔ(Ù! )¨\Ó:Ò:÷;÷ ;ñ ;üó   ‚A‘"<³	A¼AÁAc              #   ó”   K  — t        ||||«      5 }t        j                  || «        |||«      –— ddd«       y# 1 sw Y   yxY w­w)zšCreate an archive and write it into a file.

    For formats and filters, see `WRITE_FORMATS` and `WRITE_FILTERS` in the
    `libarchive.ffi` module.
    N)rŒ   r   Úwrite_open_filename_w)Úfilepathrˆ   r‰   r™   rŠ   r‹   r.   r'   s           r(   Úfile_writerr¦     sM   è ø€ ô 
˜;¨°WØ%ó
'ð ;Ø*3Ü×!Ñ! )¨XÔ6Ù! )¨\Ó:Ò:÷;÷ ;ñ ;ür¢   c              #   óð   K  — t        ||||«      5 }t        t        «       «      }t        | t        «      }	t        j                  ||	t        | «      |«        |||«      –— ddd«       y# 1 sw Y   yxY w­w)zœCreate an archive and write it into a buffer.

    For formats and filters, see `WRITE_FORMATS` and `WRITE_FILTERS` in the
    `libarchive.ffi` module.
    N)rŒ   r   r   r   r   r   Úwrite_open_memoryr5   )
Úbufrˆ   r‰   r™   rŠ   r‹   r.   r'   ÚusedÚbuf_ps
             r(   Úmemory_writerr¬     sm   è ø€ ô 
˜;¨°WØ%ó
'ð ;Ø*3Ü”X“ZÓ ˆÜ�Sœ(Ó#ˆÜ×Ñ˜i¨´°C³¸$Ô?Ù! )¨\Ó:Ò:÷;÷ ;ñ ;üs   ‚A6‘AA*Á!	A6Á*A3Á/A6)r   F)Nrp   N)*Ú
contextlibr   Úctypesr   r   r   r   r   r	   Ú	posixpathr
   r{   rp   r   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r)   r+   rŒ   r�   r¡   r¦   r¬   rB   r1   r(   ú<module>r°      sô   ðÝ %ß C× CÝ Û å ß )÷÷ ÷ ÷ ÷ ð ò	ó ð	÷J,ñ J,ðZ ò'3ó ð'3ðT à)-Ø˜t°	Ø$¨b¸TØò	;ó ð;ð8 à!%Ø$¨b¸TØò;ó ð;ð  à'+Ø$¨b¸TØò;ó ð;ð  à"&Ø$¨b¸TØò;ó ñ;r1   