
    )g4                     
   S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
JrJr  Sr\" \5      rSrSr " S S	\5      r " S
 S\5      r " S S\5      r\S:X  a.  \" S5      r\" SR5                  \R7                  5       5      5        gg)zRepresentation of ar archives for use with Debian binary packages

These classes are primarily intended to be used with the
:class:`debian.debfile.DebFile` class for working with Debian binary
packages.
    )PathN)BinaryIODict	GeneratorIteratorListNoReturnOptionalUnions   !<arch>
<   s   `
c                       \ rS rSrSrSrg)ArError/   z?Common base for all exceptions raised within the arfile module  N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       //usr/lib/python3/dist-packages/debian/arfile.pyr   r   /   s    Jr   r   c                   |    \ rS rSrSr     SS jrSS jrS rS rS r	\
" \	5      rS	 rS
 rS rS rS rS rSrg)ArFile3   zRepresentation of an ar archive, see man 1 ar.

The interface of this class tries to mimic that of the TarFile module in
the standard library.

ArFile objects have the following (read-only) properties:
    - members       same as getmembers()
Nc                     / U l         0 U l        Xl        X0l        U=(       d    [        R
                  " 5       U l        Uc  SnXPl        US:X  a  U R                  5         gg)aY  Build an ar file representation starting from either a filename or
an existing file object. The only supported mode is 'r'.

The encoding and errors parameters control how member
names are decoded into Unicode strings. Like tarfile, the default
encoding is sys.getfilesystemencoding() and the default error handling
scheme is 'surrogateescape'.
Nsurrogateescaper)	_ArFile__members_ArFile__members_dict_ArFile__fname_ArFile__fileobjsysgetfilesystemencoding_ArFile__encoding_ArFile__errors_ArFile__index_archive)selffilenamemodefileobjencodingerrorss         r   __init__ArFile.__init__=   sY        "Ac&?&?&A>&F3;  " r   c                    U R                   (       a1  [        U R                   S5       nU R                  U5        S S S 5        g U R                  (       a  U R                  U R                  5        g [	        S5      e! , (       d  f       g = f)NrbzUnable to open valid file)r!   open_ArFile__collect_membersr"   r   )r(   fps     r   __index_archiveArFile.__index_archiveZ   s]    <<dllD)R&&r* *)^^""4>>2566 *)s   A;;
B	c                    UR                  [        5      [        :w  a  [        S5      e [        R                  XR                  U R                  U R                  S9nU(       d  g U R                  R                  U5        X R                  UR                  '   UR                  S-  S:X  a  UR                  UR                  S5        OUR                  UR                  S-   S5        M  )NzUnable to find global header)r,   r-      r      )readGLOBAL_HEADER_LENGTHGLOBAL_HEADERr   ArMember	from_filer!   r%   r&   r   appendr    namesizeseek)r(   r4   	newmembers      r   __collect_membersArFile.__collect_membersc   s    77'(M9899 **2||48OO26-- + AI NN!!),2;	/~~!Q&	*	*A. r   c                      U R                   U   $ )zReturn the (last occurrence of a) member in the archive whose name
is 'name'. Raise KeyError if no member matches the given name.

Note that in case of name collisions the only way to retrieve all
members matching a given name is to use getmembers. )r    r(   r@   s     r   	getmemberArFile.getmemberu   s     ""4((r   c                     U R                   $ )zReturn a list of all members contained in the archive.

The list has the same order of members in the archive and can contain
duplicate members (i.e. members with the same name) if they are
duplicate in the archive itself. )r   r(   s    r   
getmembersArFile.getmembers   s     ~~r   c                 X    U R                    Vs/ s H  oR                  PM     sn$ s  snf )z2Return a list of all member names in the archive. )r   r@   )r(   fs     r   getnamesArFile.getnames   s"     !%/1///s   'c                     [         ezNot (yet) implemented. NotImplementedErrorrK   s    r   
extractallArFile.extractall   
     "!r   c                     [         erS   rT   )r(   memberpaths      r   extractArFile.extract   rX   r   c                     U R                    HI  n[        U[        5      (       a  UR                  UR                  :X  a  Us  $ XR                  :X  d  MG  Us  $    g)zReturn a file object corresponding to the requested member. A member
can be specified either as a string (its name) or as a ArMember
instance. N)r   
isinstancer=   r@   )r(   rZ   ms      r   extractfileArFile.extractfile   sG     A&(++&++0E	  
 r   c                 ,    [        U R                  5      $ )z4Iterate over the members of the present ar archive. )iterr   rK   s    r   __iter__ArFile.__iter__   s     DNN##r   c                 $    U R                  U5      $ )zSame as .getmember(name). )rH   rG   s     r   __getitem__ArFile.__getitem__   s     ~~d##r   )
__encoding__errors	__fileobj__fname	__members__members_dict)Nr   NNNreturnN)r   r   r   r   r   r.   r'   r3   rH   rL   propertymembersrP   rV   r\   ra   re   rh   r   r   r   r   r   r   3   s[     #:7/$) z"G0"".$$r   r   c                   <   \ rS rSrSrSS jr\  SS j5       rSS jrSS jr	SS	\
S\\   4S
 jjrSS\
S\
SS4S jjrS\
4S jrS\4S jrSS jrS\4S jrS r\" S 5      r\" S 5      r\" S 5      r\" S 5      r\" S 5      r\" S 5      r\" S 5      rSrg)r=      a  Member of an ar archive.

Implements most of a file object interface: read, readline, next,
readlines, seek, tell, close.

ArMember objects have the following (read-only) properties:
    - name      member name in an ar archive
    - mtime     modification time
    - owner     owner user
    - group     owner group
    - fmode     file permissions
    - size      size in bytes
    - fname     file namerq   Nc                     S U l         S U l        S U l        S U l        S U l        S U l        SU l        S U l        SU l        SU l	        SU l
        g )N r   )_ArMember__name_ArMember__mtime_ArMember__owner_ArMember__group_ArMember__fmode_ArMember__size_ArMember__fname_ArMember__fp_ArMember__offset_ArMember__end_ArMember__currK   s    r   r.   ArMember.__init__   sO    	

r   c                    U R                  [        5      nU(       d  g[        U5      [        :  a  [        S5      eUSS [        :w  a  [        S5      eUc  [
        R                  " 5       nUc  Sn[        5       nUSS R                  S	5      S   R                  5       nUR                  X#5      Ul        [        USS
 5      Ul        [        US
S 5      Ul        [        USS 5      Ul        USS Ul        [        USS 5      Ul        Xl        U(       d  Xl        U R)                  5       Ul        UR*                  UR"                  -   Ul        UR*                  Ul        U$ )zfp is an open File object positioned on a valid file header inside
an ar archive. Return a new ArMember on success, None otherwise. NzIncorrect header length:   r   zIncorrect file magicr   r         /   "   (   0   )r:   FILE_HEADER_LENGTHlenIOError
FILE_MAGICr#   r$   r=   splitstripdecoderx   intry   rz   r{   r|   r}   r~   r   tellr   r   r   )r4   fnamer,   r-   bufrO   r@   s          r   r>   ArMember.from_file   s8    gg() s8((344r":#011002H>&F J 1Ryt$Q'--/;;x0Br
O	Br
O	Br
O	2J	s2bz?	FWWY
**qxx'**r   c                    U R                   c3  U R                  c  [        S5      e[        U R                  S5      U l         U R                   R	                  U R
                  5        SUs=:  a  U R                  U R
                  -
  ::  a?  O  O<U R                   R                  U5      nU R                   R                  5       U l        U$ U R
                  U R                  :  d  U R
                  U R                  :  a  gU R                   R                  U R                  U R
                  -
  5      nU R                   R                  5       U l        U$ )N'Cannot have both fp and fname undefinedr1   r   r   )
r   r~   
ValueErrorr2   rB   r   r   r:   r   r   r(   rA   r   s      r   r:   ArMember.read&  s    99||# !JKKT\\40DI		tzz"t.tzzDJJ..))..&C)DJJ::#tzzDMM'AiinnTZZ$**45YY^^%

r   c                 ,   U R                   c3  U R                  c  [        S5      e[        U R                  S5      U l         U R                   R	                  U R
                  5        UbW  U R                   R                  U5      nU R                   R                  5       U l        U R
                  U R                  :  a  gU$ U R                   R                  5       nU R                   R                  5       U l        U R
                  U R                  :  a  gU$ )Nr   r1   r   )	r   r~   r   r2   rB   r   readliner   r   r   s      r   r   ArMember.readline:  s    99||# !JKKT\\40DI		tzz"))$$T*C)DJzzDJJ&Jii  "YY^^%
::

"
r   sizehintc                 f    S n/ n U R                  5       nU(       d   U$ UR                  U5        M-  N)r   r?   )r(   r   r   liness       r   	readlinesArMember.readlinesP  s:    --/C  LL	 r   offsetwhencec                 P   [        U R                  U R                  5      U l        US:  a*  XR                  -   U R                  :  a  [        SU-  5      eUS:X  a  U R                  U-   U l        g US:X  a  U R                  U-   U l        g US:X  a  U R                  U-   U l        g g )Nr8   zCan't seek at %dr9   r   )maxr   r   r   r   )r(   r   r   s      r   rB   ArMember.seek\  s    T]]3
A:&::-=,v566Q;f,DJq[/DJq[f,DJ r   c                 j    U R                   U R                  :  a  gU R                   U R                  -
  $ )Nr   )r   r   rK   s    r   r   ArMember.telli  s(    ::%zzDMM))r   c                     g)NTr   rK   s    r   seekableArMember.seekablen  s    r   c                 ~    U R                   b0  U R                  b"  U R                   R                  5         S U l         g g g r   )r   r~   closerK   s    r   r   ArMember.closeq  s2    99 T\\%=IIOODI &> r   c                 "    U R                  5       $ r   r   rK   s    r   nextArMember.nextv  s    }}r   c                 0   ^  U 4S jn[        U" 5       5      $ )Nc               3   F   >#    TR                  5       n U (       a  U v   g g 7fr   r   )liner(   s    r   nextline#ArMember.__iter__.<locals>.nextline{  s     ==?D
 s   !)rd   )r(   r   s   ` r   re   ArMember.__iter__y  s    	 HJr   c                     U R                   $ r   )rx   rK   s    r   <lambda>ArMember.<lambda>      r   c                     U R                   $ r   )ry   rK   s    r   r   r         $,,r   c                     U R                   $ r   )rz   rK   s    r   r   r     r   r   c                     U R                   $ r   )r{   rK   s    r   r   r     r   r   c                     U R                   $ r   )r|   rK   s    r   r   r     r   r   c                     U R                   $ r   )r}   rK   s    r   r   r     r   r   c                     U R                   $ r   )r~   rK   s    r   r   r     r   r   )__cur__end__fmoderm   __fp__group__mtime__name__offset__owner__sizerp   )NN)r   r   )r   r   r   r   r   r.   staticmethodr>   r:   r   r   r   bytesr   rB   r   boolr   r   r   re   rr   r@   mtimeownergroupfmoderA   r   r   r   r   r   r=   r=      s    !0   8 8z(,
# 
d5k 
-3 - -D -*c *
$ 
e   ,-D./E./E./E./E,-D./Er   r=   __main__ztest.ar
)r   pathlibr   r#   typingr   r   r   r   r   r	   r
   r   r<   r   r;   r   r   	Exceptionr   objectr   r=   r   aprintjoinrP   r   r   r   <module>r      s   0  
	 	 	 =)  
Ki KK$V K$\H0v H0V z 	yA	$))AJJL
!"	 r   