509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
y¾œbÔ@  ã               @   s   d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZ ddlmZmZ y
ejZW n ek
r¨   ejZY nX ee	dGd
�ZdHdd„ZdIdd„ZdZde Zde Z ej!j"dƒpðedƒZ#e#dk�r8ej$j%dƒ�rdZ#n(ej$dk�r"dZ#ne&eej'd� e(eƒ‚dZ)ej$j%dƒ�rÊej!j"ddƒZ*ej+de*ƒZ,xde,D ]\Z-e-j%dƒ�rjedd�Z.ej/d d!ge.d"�Z0ee0j1d#ƒj+ƒ dJ ƒZ2e2ed$ƒk�rÂe-Z#dZ)P �qjW yee#dd%�Z3W n0 e4k
�r
 Z5 ze(e e5 ƒ‚W Y ddZ5[5X nX d&d'„ Z6d(d)„ Z7G d*d+„ d+e(ƒZ8dKd,d-„Z9d.d/„ Z:d0d1„ Z;d2d3„ Z<ej$j%dƒ�rbeeefe3j=_>e
e3j=_?eeefe3j@_>e
e3j@_?eeefe3jA_>e
e3jA_?eeeeefe3jB_>ee3jB_?eeeeefe3jC_>ee3jC_?eeeeefe3jD_>ee3jD_?eeeefe3jE_>e
e3jE_?eeeefe3jF_>e
e3jF_?eeeefe3jG_>e
e3jG_?dd4œd5d6„Z=dd4œd7d8„ZEdd4œd9d:„ZB�n:ej$dk�rDeeeefe3j=_>e
e3j=_?eeeefe3jA_>e
e3jA_?eeeeeefe3jB_>ee3jB_?eeeeeefe3jD_>ee3jD_?eeeeeefe3jE_>e
e3jE_?eeeeeefe3jG_>e
e3jG_?dZHdZIdd4œd;d6„Z=dd4œd<d8„ZEdd4œd=d:„ZB�nXej$j%d>ƒ�rreeeefe3jJ_>e
e3jJ_?eeeefe3jK_>e
e3jK_?eeeefe3jL_>e
e3jL_?eeeeefe3jM_>e
e3jM_?eeeeefe3jN_>e
e3jN_?eeeeefe3jO_>e
e3jO_?eeeeefe3jP_>ee3jP_?eeeeefe3jQ_>ee3jQ_?eeeeefe3jR_>ee3jR_?d ZSZTdL\ZUZVdd4œdAd6„Z=dd4œdBd8„ZEdd4œdCd:„ZBn*dd4œdDd6„Z=dd4œdEd8„ZEdd4œdFd:„ZBdS )MzRA basic extended attributes (xattr) implementation for Linux, FreeBSD and MacOS X.é    N)ÚCDLLÚcreate_string_bufferÚ	c_ssize_tÚc_size_tÚc_char_pÚc_intÚc_uint32Ú	get_errno)Úfind_library)Úparseé   )ÚBufferÚprepare_subprocess_envé   é   )Úlimitc             C   sV   t j| dd��>}yt|jƒ ddƒ W n tk
r8   dS X t|jƒ dƒdkS Q R X dS )z4Determine if xattr is enabled on the filesystem
    zborg-tmp)ÚdirÚprefixz	user.names   valueFN)ÚtempfileZNamedTemporaryFileÚsetxattrÚfilenoÚOSErrorÚgetxattr)ÚpathÚfd© r   ú/usr/lib64/python3.6/xattr.pyÚ
is_enabled   s    r   Tc             C   s¦   yhi }t | |d�}xR|D ]J}yt| ||d�||< W q tk
r` } z|jtkrP‚ W Y dd}~X qX qW |S  tk
r  } z|jtjtjfkr�i S W Y dd}~X nX dS )a¶  
    Return all extended attributes on *path* as a mapping.

    *path* can either be a path (str or bytes) or an open file descriptor (int).
    *follow_symlinks* indicates whether symlinks should be followed
    and only applies when *path* is not an open file descriptor.

    The returned mapping maps xattr names (str) to values (bytes or None).
    None indicates, as a xattr value, an empty value, i.e. a value of length zero.
    )Úfollow_symlinksN)Ú	listxattrr   r   ÚerrnoÚENOATTRZENOTSUPZEPERM)r   r   ÚresultÚnamesÚnameÚer   r   r   Úget_all%   s    

r&   z<Try installing ldconfig, gcc/cc or objdump or use BORG_LIBC.z)Can't find C library. No fallback known. zCan't find C library [%s]. Z	BORG_LIBCÚcÚlinuxz	libc.so.6Údarwinz
libc.dylib)ÚfileFÚ
LD_PRELOADÚ z[ :]Zlibfakeroot)ÚsystemZfakerootz-v)ÚenvÚasciiz1.20.2)Z	use_errnoc             C   s   | j dƒdd… S )zMsplit a list of zero-terminated strings into python not-zero-terminated bytesó    Nr   éÿÿÿÿ)Úsplit)Úbufr   r   r   Úsplit_string0m   s    r4   c             C   sL   g }t | ƒ}x:|rF|d }|jt|dd| … ƒƒ |d| d… }qW |S )zMsplit a list of length-prefixed strings into python not-length-prefixed bytesr   r   N)Ú
memoryviewÚappendÚbytes)r3   r"   ZmvZlengthr   r   r   Úsplit_lstringr   s    r8   c               @   s   e Zd ZdZdS )ÚBufferTooSmallErrorzBthe buffer given to a xattr function was too small for the result.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r9   }   s   r9   c             C   s€   | dk rht ƒ }|r"|tjkr"t‚nFytj|ƒ}W n tk
rH   d}Y nX t|tƒr\d| }t	|||ƒ‚|r|| t
tƒkr|t‚| S )Nr   r,   z<FD %d>)r	   r    ZERANGEr9   ÚosÚstrerrorÚ
ValueErrorÚ
isinstanceÚintr   ÚlenÚbuffer)Úrvr   Údetect_buffer_too_smallr%   Úmsgr   r   r   Ú_check�   s    

rH   c             C   sr   t |tƒrtj|ƒ}ttƒ}xPtj|ƒ}yt| |||ƒ|dd�}W n tk
r^   |d9 }Y qX ||j	fS qW d S )NT)rF   r   )
rA   Ústrr>   ÚfsencoderC   rD   ÚgetrH   r9   Úraw)Úfuncr   Úsizer3   Únr   r   r   Ú_listxattr_inner™   s    


rP   c             C   s~   t |tƒrtj|ƒ}tj|ƒ}ttƒ}xRtj|ƒ}yt| ||||ƒ|dd�}W n tk
rj   |d9 }Y q(X ||j	fS q(W d S )NT)rF   r   )
rA   rI   r>   rJ   rC   rD   rK   rH   r9   rL   )rM   r   r$   rN   r3   rO   r   r   r   Ú_getxattr_inner§   s    



rQ   c             C   sX   t |tƒrtj|ƒ}tj|ƒ}|o*tj|ƒ}|r8t|ƒnd}t| ||||ƒ|dd� d S )Nr   F)rF   )rA   rI   r>   rJ   rC   rH   )rM   r   r$   ÚvaluerN   r   r   r   Ú_setxattr_inner¶   s    


rS   )r   c               s4   ‡ fdd„}t || ƒ\}}dd„ t|d |… ƒD ƒS )Nc                s<   t | tƒrtj| ||ƒS ˆ r*tj| ||ƒS tj| ||ƒS d S )N)rA   rB   ÚlibcÚ
flistxattrr   Ú
llistxattr)r   r3   rN   )r   r   r   rM   Ô   s
    
zlistxattr.<locals>.funcc             S   s&   g | ]}|r|j d ƒ rtj|ƒ‘qS )s   system.posix_acl_)Ú
startswithr>   Úfsdecode)Ú.0r$   r   r   r   ú
<listcomp>Þ   s    zlistxattr.<locals>.<listcomp>)rP   r4   )r   r   rM   rO   r3   r   )r   r   r   Ó   s    	r   c               s,   ‡ fdd„}t || |ƒ\}}|d |… p*d S )Nc                sB   t | tƒrtj| |||ƒS ˆ r.tj| |||ƒS tj| |||ƒS d S )N)rA   rB   rT   Ú	fgetxattrr   Ú	lgetxattr)r   r$   r3   rN   )r   r   r   rM   â   s
    
zgetxattr.<locals>.func)rQ   )r   r$   r   rM   rO   r3   r   )r   r   r   á   s    	r   c               s   ‡ fdd„}t || ||ƒ d S )Nc                sL   d}t | tƒr tj| ||||ƒS ˆ r6tj| ||||ƒS tj| ||||ƒS d S )Nr   )rA   rB   rT   Ú	fsetxattrr   Ú	lsetxattr)r   r$   rR   rN   Úflags)r   r   r   rM   ï   s    
zsetxattr.<locals>.func)rS   )r   r$   rR   r   rM   r   )r   r   r   î   s    
r   c               s4   ‡ fdd„}t || ƒ\}}dd„ t|d |… ƒD ƒS )Nc                sB   t | tƒrtj| ||tƒS ˆ r.tj| ||tƒS tj| ||tƒS d S )N)rA   rB   rT   rU   ÚXATTR_NOFLAGSr   ÚXATTR_NOFOLLOW)r   r3   rN   )r   r   r   rM     s
    
zlistxattr.<locals>.funcc             S   s   g | ]}|rt j|ƒ‘qS r   )r>   rX   )rY   r$   r   r   r   rZ     s    zlistxattr.<locals>.<listcomp>)rP   r4   )r   r   rM   rO   r3   r   )r   r   r     s    	c               s,   ‡ fdd„}t || |ƒ\}}|d |… p*d S )Nc                sN   t | tƒrtj| |||dtƒS ˆ r6tj| |||dtƒS tj| |||dtƒS d S )Nr   )rA   rB   rT   r[   r`   r   ra   )r   r$   r3   rN   )r   r   r   rM     s
    
zgetxattr.<locals>.func)rQ   )r   r$   r   rM   rO   r3   r   )r   r   r     s    	c               s   ‡ fdd„}t || ||ƒ d S )Nc                sN   t | tƒrtj| |||dtƒS ˆ r6tj| |||dtƒS tj| |||dtƒS d S )Nr   )rA   rB   rT   r]   r`   r   ra   )r   r$   rR   rN   )r   r   r   rM   '  s
    
zsetxattr.<locals>.func)rS   )r   r$   rR   r   rM   r   )r   r   r   &  s    	Zfreebsdúuser.ó   user.c               s4   ‡ fdd„}t || ƒ\}}dd„ t|d |… ƒD ƒS )Nc                sB   t | tƒrtj| t||ƒS ˆ r.tj| t||ƒS tj| t||ƒS d S )N)rA   rB   rT   Úextattr_list_fdÚnsÚextattr_list_fileÚextattr_list_link)r   r3   rN   )r   r   r   rM   I  s
    
zlistxattr.<locals>.funcc             S   s   g | ]}|rt tj|ƒ ‘qS r   )r   r>   rX   )rY   r$   r   r   r   rZ   S  s    zlistxattr.<locals>.<listcomp>)rP   r8   )r   r   rM   rO   r3   r   )r   r   r   H  s    	c               sX   ‡ fdd„}t |tƒrtnt}|j|ƒr8|t|ƒd … }t|| |ƒ\}}|d |… pVd S )Nc                sH   t | tƒrtj| t|||ƒS ˆ r2tj| t|||ƒS tj| t|||ƒS d S )N)rA   rB   rT   Úextattr_get_fdre   Úextattr_get_fileÚextattr_get_link)r   r$   r3   rN   )r   r   r   rM   V  s
    
zgetxattr.<locals>.func)rA   rI   r   Úprefix_brW   rC   rQ   )r   r$   r   rM   Ú_prefixrO   r3   r   )r   r   r   U  s    
c               sJ   ‡ fdd„}t |tƒrtnt}|j|ƒr8|t|ƒd … }t|| ||ƒ d S )Nc                sH   t | tƒrtj| t|||ƒS ˆ r2tj| t|||ƒS tj| t|||ƒS d S )N)rA   rB   rT   Úextattr_set_fdre   Úextattr_set_fileÚextattr_set_link)r   r$   rR   rN   )r   r   r   rM   h  s
    
zsetxattr.<locals>.func)rA   rI   r   rk   rW   rC   rS   )r   r$   rR   r   rM   rl   r   )r   r   r   g  s
    
c            C   s   g S )a  
        Return list of xattr names on a file.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        r   )r   r   r   r   r   r   y  s    c            C   s   dS )al  
        Read xattr and return its value (as bytes) or None if its empty.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *name* is the name of the xattr to read (str).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        Nr   )r   r$   r   r   r   r   r   ƒ  s    c            C   s   dS )aÒ  
        Write xattr on *path*.

        *path* can either be a path (str or bytes) or an open file descriptor (int).
        *name* is the name of the xattr to read (str).
        *value* is the value to write. It is either bytes or None. The latter
        signals that the value shall be empty (size equals zero).
        *follow_symlinks* indicates whether symlinks should be followed
        and only applies when *path* is not an open file descriptor.
        Nr   )r   r$   rR   r   r   r   r   r   �  s    i   )N)Tr1   )NF)rb   rc   )Wr=   r    r>   ÚreÚ
subprocessÚsysr   Zctypesr   r   r   r   r   r   r   r	   Zctypes.utilr
   Zpackaging.versionr   Zparse_versionZhelpersr   r   r!   ÚAttributeErrorZENODATArD   r   r&   ZHINT_MSGZLIBC_NOT_FOUND_NO_FALLBACK_MSGZLIBC_NOT_FOUND_FNAME_MSGÚenvironrK   Z	libc_nameÚplatformrW   ÚprintÚstderrÚ	ExceptionZXATTR_FAKEROOTr+   r2   ZpreloadsZpreloadr.   Zcheck_outputZfakeroot_outputÚdecodeZfakeroot_versionrT   r   r%   r4   r8   r9   rH   rP   rQ   rS   r   ZargtypesZrestyperV   rU   r   r^   r]   r   r\   r[   r`   ra   rd   rg   rf   rh   rj   ri   rm   ro   rn   re   ZEXTATTR_NAMESPACE_USERr   rk   r   r   r   r   Ú<module>   sî   (






	

