
    4_m`                     H   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
 d dl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mZ  G d	 d
e          Zedd            Zeddeeeefd            Zedd            Zedd            Zedd            Zeddefd            Z dS )    )divisionprint_functionunicode_literals)contextmanager)castc_void_pPOINTERcreate_string_buffer)fstatstat   )ffi)ARCHIVE_EOFOPEN_CALLBACKREAD_CALLBACKCLOSE_CALLBACKVOID_CB	page_size)ArchiveEntrynew_archive_entryc                       e Zd Zd Zd ZdS )ArchiveReadc                     || _         d S )N)_pointer)self	archive_ps     /lib/python3.11/site-packages/libarchive/read.py__init__zArchiveRead.__init__   s    !    c              #      K   | j         }t          j        }t                      5 }t	          ||          }	  |||          }|t
          k    r	 ddd           dS |V  *# 1 swxY w Y   dS )z/Iterates through an archive's entries.
        r   N)r   r   read_next_header2r   r   r   )r   r   r!   entry_pentryrs         r   __iter__zArchiveRead.__iter__   s       M	1   	G G44E%%i99##	 	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	s   *A A  A$'A$N)__name__
__module____qualname__r   r%    r   r   r   r      s2        " " "    r   r   allc              #     K   t          j                    } t          t           d|z             |            t          t           d| z             |           	 |V  t          j        |           dS # t          j        |           w xY w)zCreates an archive struct suitable for reading from an archive.

    Returns a pointer if successful. Raises ArchiveError on error.
    read_support_filter_read_support_format_N)r   read_newgetattr	read_free)format_namefilter_namer   s      r   new_archive_readr3       s       I4GC'344Y???4GC'344Y???!i     i    s   A3 3B	c              #      K   t          |          }t          |           }t          |          }	t          ||          5 }
t	          j        |
d|||	            ||
          V  ddd           dS # 1 swxY w Y   dS )z-Read an archive using a custom function.
    N)r   r   r   r3   r   	read_open)	read_funcr1   r2   	open_func
close_func
block_sizearchive_read_classopen_cbread_cbclose_cbr   s              r   custom_readerr>   /   s       I&&GI&&Gj))H	+{	3	3 ,yiwBBB  +++++, , , , , , , , , , , , , , , , , ,s    &A33A7:A7   c              #     K   t          ||          5 }	 t          |           j        }n# t          t          f$ r Y nw xY wt          j        || |           t          |          V  ddd           dS # 1 swxY w Y   dS )z,Read an archive from a file descriptor.
    N)r3   r   
st_blksizeOSErrorAttributeErrorr   read_open_fdr   )fdr1   r2   r9   r   s        r   	fd_readerrF   ?   s       
+{	3	3 %y	r-JJ( 	 	 	D	B
333)$$$$$% % % % % % % % % % % % % % % % % %,   A5*A5>A5>*A55A9<A9c              #     K   t          ||          5 }	 t          |           j        }n# t          t          f$ r Y nw xY wt          j        || |           t          |          V  ddd           dS # 1 swxY w Y   dS )z!Read an archive from a file.
    N)r3   r   rA   rB   rC   r   read_open_filename_wr   )pathr1   r2   r9   r   s        r   file_readerrK   L   s       
+{	3	3 %y	d.JJ( 	 	 	D	 D*===)$$$$$% % % % % % % % % % % % % % % % % %rG   c              #      K   t          ||          5 }t          j        |t          | t                    t          |                      t          |          V  ddd           dS # 1 swxY w Y   dS )z!Read an archive from memory.
    N)r3   r   read_open_memoryr   r   lenr   )bufr1   r2   r   s       r   memory_readerrP   Y   s       
+{	3	3 %yYS((;(;SXXFFF)$$$$$% % % % % % % % % % % % % % % % % %s   AA((A,/A,c              #   x   	
K   t          |          	t          	t                    
	
 fd}t          t                    }t          |          }t          t                    }t          ||          5 }t          j	        |d|||           t          |          V  ddd           dS # 1 swxY w Y   dS )ziRead an archive from a stream.

    The `stream` object must support the standard `readinto` method.
    c                                                    }t          |t          t                              }|d<   |S )Nr   )readintor   r	   r   )r   contextptrptrlengthrO   buf_pstreams       r   r6   z stream_reader.<locals>.read_funcl   s9    %%fgh//00q	r   N)r
   r   r   r   r   r   r   r3   r   r5   r   )rX   r1   r2   r9   r6   r;   r<   r=   r   rO   rW   s   `        @@r   stream_readerrY   b   s      z
*
*ChE       G$$GI&&Gg&&H	+{	3	3 %yiwBBB)$$$$$% % % % % % % % % % % % % % % % % %s   8*B//B36B3N)r*   r*   )r*   r*   r?   )!
__future__r   r   r   
contextlibr   ctypesr   r   r	   r
   osr   r    r   r   r   r   r   r   r   r#   r   r   objectr   r3   r>   rF   rK   rP   rY   r)   r   r   <module>r`      s   A A A A A A A A A A % % % % % % @ @ @ @ @ @ @ @ @ @ @ @              & & & & & & & & & & & & & & & & 2 2 2 2 2 2 2 2    &   & ! ! ! ! $%g)&, , , , 	% 	% 	% 	% 	% 	% 	% 	% % % % % &+&% % % % % %r   