
    4_m`                         d dl mZmZmZ 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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#m$Z$m%Z%m&Z&m'Z' edd	            Z( G d
 de)          Z*edd            Z+edeeee*dfd            Z,ede*dfd            Z-ede*dfd            Z.ede*dfd            Z/dS )    )divisionprint_functionunicode_literals)contextmanager)byrefcastc_charc_size_tc_void_pPOINTER   )ffi)ArchiveEntrynew_archive_entry)OPEN_CALLBACKWRITE_CALLBACKCLOSE_CALLBACKVOID_CBREGULAR_FILEDEFAULT_UNIX_PERMISSION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entry_set_sizeentry_set_filetypeentry_set_permread_disk_set_behaviorFc              #      K   t                      }t          ||           |rt          j        |           t	          ||            	 |V  t          |           d S # t          |           w xY wN)r   r&   r   read_disk_set_standard_lookupr   r   )pathflagslookup	archive_ps       0lib/python3.11/site-packages/libarchive/write.pynew_archive_read_diskr/      s~      I9e,,, 5))444Y%%%)	)s   A A.c                   4    e Zd Zd Zd Zd ZeeddddfdZdS )ArchiveWritec                     || _         d S r(   )_pointer)selfr-   s     r.   __init__zArchiveWrite.__init__!   s    !    c           	          | j         }|D ][}t          ||j                   |                                D ] }t	          ||t          |                     !t          |           \dS )z.Add the given entries to the archive.
        N)r3   r    _entry_p
get_blocksr!   lenr"   )r4   entrieswrite_pentryblocks        r.   add_entrieszArchiveWrite.add_entries$   s}     - 	( 	(E%.111))++ 7 77E3u::6666w''''		( 	(r6   c                    | j         }t          j        |          }|dk    rd}t                      5 }t	          d|          }|D ]}t          |fi |5 }	 t          ||          }	|	t          k    rn|j        	                    d          |_        t          |           t          ||           |j        rnt          t          |          d          5 }
	 |
                    |          }|snt!          ||t#          |                     7	 ddd           n# 1 swxY w Y   t%          |           t'          |           	 ddd           n# 1 swxY w Y   	 ddd           dS # 1 swxY w Y   dS )zRead the given paths from disk and add them to the archive.

        The keyword arguments (`**kw`) are passed to `new_archive_read_disk`.
        r   i (  Nr   /rb)r3   r   write_get_bytes_per_blockr   r   r/   r   r   pathnamelstripr   r    isregopenr   readr!   r:   r"   r   )r4   pathskwr<   
block_sizeentry_pr=   r*   read_prfdatas               r.   	add_fileszArchiveWrite.add_files.   sl   
 -27;;
??J   	-G w//E - -*466266 -&--fg>>++!).)>)>s)C)C)&111$Wg666 ; I!%&6w&?&?!F!F I!!I+,66*+=+=D+/ %.(-$.wc$ii$H$H$H	!I ).	I I I I I I I I I I I I I I I +7333#G,,,- "	- - - - - - - - - - - - - - --	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-sZ   #E-B E9D	EDE"D#"EE-EE-EE--E14E1Nc
           	      \   | j         }
t          |t                    r|f}n4t          |t                    rt	          dt          |          z            t                      5 }t          d|          }||_        t          ||           t          ||           t          ||           |#t          |t                    s|df} |j        |  |#t          |t                    s|df} |j        |  |#t          |t                    s|df} |j        |  |	#t          |	t                    s|	df}	 |j        |	  t#          |
|           |D ]$}|s nt%          |
|t'          |                     %t)          |
           t+          |           ddd           dS # 1 swxY w Y   dS )a#  "Add file from memory to archive.

        :param entry_path: where entry should be places in archive
        :type entry_path: str
        :param entry_size: entire size of entry in bytes
        :type entry_size: int
        :param entry_data: content of entry
        :type entry_data: bytes or Iterable[bytes]
        :param filetype: which type of file: normal, symlink etc.
        should entry be created as
        :type filetype: octal number
        :param permission: with which permission should entry be created
        :type permission: octal number
        :param atime: Last access time
        :type atime: int seconds or tuple (int seconds, int nanoseconds)
        :param mtime: Last modified time
        :type mtime: int seconds or tuple (int seconds, int nanoseconds)
        :param ctime: Creation time
        :type ctime: int seconds or tuple (int seconds, int nanoseconds)
        :param birthtime: Birth time (for archive formats that support it)
        :type birthtime: int seconds or tuple (int seconds, int nanoseconds)
        z"entry_data: expected bytes, got %rNr   )r3   
isinstancebytesstr	TypeErrortyper   r   rD   r#   r$   r%   tuple	set_atime	set_mtime	set_ctimeset_birthtimer    r!   r:   r"   r   )r4   
entry_path
entry_size
entry_datafiletype
permissionatimemtimectime	birthtimearchive_pointerarchive_entry_pointerarchive_entrychunks                 r.   add_file_from_memoryz!ArchiveWrite.add_file_from_memoryN   s?   6 -j%(( 	$JJ
C(( 	4tJ7G7GG       	/$9(/DEEM%/M"0*===4h???0*=== !%// '"AJE''// !%// '"AJE''// !%// '"AJE''//$!)U33 /!*AI++Y77*?@@@# ? ? E?E3u::>>>>///-...A 	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/  	/s   #D1F!!F%(F%)	__name__
__module____qualname__r5   r?   rQ   r   r   rj    r6   r.   r1   r1      sm        " " "( ( (- - -D ".Ed$$D/ D/ D/ D/ D/ D/r6   r1   N c              #     K   t          j                    } t          t           d| z             |           |r! t          t           d|z             |           |r?t          |t                    s|                    d          }t          j        ||           	 |V  t          j        |           t          j        |           d S # t          $ r* t          j
        |           t          j        |            w xY w)Nwrite_set_format_write_add_filter_zutf-8)r   	write_newgetattrrS   rT   encodewrite_set_optionswrite_close
write_free	Exception
write_fail)format_namefilter_nameoptionsr-   s       r.   new_archive_writer~      s
     I1GC$[011)<<< A5(455i@@@ 2'5)) 	.nnW--Gi111	"""y!!!!!   y!!!y!!!s   ,C
 
4C>c              #   b   K    fd}t          |          }	t          |          }
t          |          }t          |||          5 }t	          j        |d           t	          j        ||           t	          j        |d |	|
|            ||          V  d d d            d S # 1 swxY w Y   d S )Nc                 p    t          |t          t          |z                      d         } |          S )Nr   )r   r   r	   )r-   contextbuffer_lengthrP   
write_funcs        r.   write_cb_internalz(custom_writer.<locals>.write_cb_internal   s3    GWVf_5566q9z$r6   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_funcrK   archive_write_classr}   r   open_cbwrite_cbclose_cbr-   s   `            r.   custom_writerr      s               I&&G/00Hj))H	;W	=	= -))Q777%i<<<y$8DDD!!),,,,,	- - - - - - - - - - - - - - - - - -s   AB$$B(+B(c              #      K   t          |||          5 }t          j        ||             ||          V  d d d            d S # 1 swxY w Y   d S r(   )r~   r   write_open_fd)fdr{   r|   r   r}   r-   s         r.   	fd_writerr      s      
 
;W	=	= -)R(((!!),,,,,- - - - - - - - - - - - - - - - - -   #AAAc              #      K   t          |||          5 }t          j        ||             ||          V  d d d            d S # 1 swxY w Y   d S r(   )r~   r   write_open_filename_w)filepathr{   r|   r   r}   r-   s         r.   file_writerr      s      
 
;W	=	= -!)X666!!),,,,,- - - - - - - - - - - - - - - - - -r   c              #      K   t          |||          5 }t          t                                }t          | t                    }t          j        ||t          |           |            ||          V  d d d            d S # 1 swxY w Y   d S r(   )r~   r   r
   r   r   r   write_open_memoryr:   )bufr{   r|   r   r}   r-   usedbuf_ps           r.   memory_writerr      s      
 
;W	=	= -XZZ  S(##iC$???!!),,,,,	- - - - - - - - - - - - - - - - - -s   A"BB
B)r   F)Nro   )0
__future__r   r   r   
contextlibr   ctypesr   r   r	   r
   r   r   ro   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/   objectr1   r~   r   r   r   r   rn   r6   r.   <module>r      s   A A A A A A A A A A % % % % % % C C C C C C C C C C C C C C C C       2 2 2 2 2 2 2 2                                                	 	 	 	s/ s/ s/ s/ s/6 s/ s/ s/l    & -1g)("- - - -* %)("- - - - +/("- - - - &*("- - - - - -r6   