U
    f                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZ edef edef dddZdd Zdd
dZ	e
eegef dddZe
eegef dddZG dd deZdS )    N)AnyCallable.)funcsreturnc                  G   s   dd }t || S )Nc                    s    fddS )Nc                     s    | |S N )argskwargsf1f2r   ./tmp/pip-unpacked-wheel-qyyspjli/path/masks.py<lambda>       z+compose.<locals>.<lambda>.<locals>.<lambda>r   r
   r   r
   r   r      r   zcompose.<locals>.<lambda>)	functoolsreduce)r   Zcompose_twor   r   r   compose
   s    r   c                 C   s   t | dd }ttt|S )z
    Return a zero or one for each bit of a numeric value up to the most
    significant 1 bit, beginning with the least significant bit.

    >>> list(gen_bit_values(16))
    [0, 0, 0, 0, 1]
       N)binmapintreversed)numberdigitsr   r   r   gen_bit_values   s    r   Fc           	      c   s   t | }|dkr*t|t|E dH  nZ|dk r<tdnHd}|D ]}|V  |d7 }qD|rh|| | n|| }t|D ]
}|V  qxdS )a  Yield the elements from *iterable*, followed by *fillvalue*, such that
    at least *n* items are emitted.

        >>> list(padded([1, 2, 3], '?', 5))
        [1, 2, 3, '?', '?']

    If *next_multiple* is ``True``, *fillvalue* will be emitted until the
    number of items emitted is a multiple of *n*::

        >>> list(padded([1, 2, 3, 4], n=3, next_multiple=True))
        [1, 2, 3, 4, None, None]

    If *n* is ``None``, *fillvalue* will be emitted indefinitely.

    N   zn must be at least 1r   )iter	itertoolschainrepeat
ValueErrorrange)	iterable	fillvaluenZnext_multipleitZ
item_countitem	remaining_r   r   r   padded   s    

r)   )moder   c                 C   s   t ttt| d S )zw
    Support multiple, comma-separated Unix chmod symbolic modes.

    >>> oct(compound('a=r,u+w')(0))
    '0o644'
    ,)r   r   simpler   split)r*   r   r   r   compound=   s    r.   c                    s   t d| }|std| tddddfdd|d	D }ttj|d
tddd
d|d	dd}fdd|D }ttj|}|d}|dkr|dN }|dkr؇fdd|D }ttj|dA  tjtj
 fddd}t|| |S )au  
    Convert a Unix chmod symbolic mode like ``'ugo+rwx'`` to a function
    suitable for applying to a mask to affect that change.

    >>> mask = simple('ugo+rwx')
    >>> mask(0o554) == 0o777
    True

    >>> simple('go-x')(0o777) == 0o766
    True

    >>> simple('o-x')(0o445) == 0o444
    True

    >>> simple('a+x')(0) == 0o111
    True

    >>> simple('a=rw')(0o057) == 0o666
    True

    >>> simple('u=x')(0o666) == 0o166
    True

    >>> simple('g=')(0o157) == 0o107
    True

    >>> simple('gobbledeegook')
    Traceback (most recent call last):
    ValueError: ('Unrecognized symbolic mode', 'gobbledeegook')
    z.(?P<who>[ugoa]+)(?P<op>[-+=])(?P<what>[rwx]*)$zUnrecognized symbolic mode   r   r   )rwxc                 3   s   | ]} | V  qd S r   r   ).0perm)spec_mapr   r   	<genexpr>m   s     zsimple.<locals>.<genexpr>whatr         )ugowhoaZugoc                 3   s   | ]} | > V  qd S r   r   r3   Zsubj)	shift_mapspecr   r   r6   s   s     op-i  =c                 3   s   | ]}d  | > V  qdS )   Nr   r?   )r@   r   r   r6   ~   s     c                    s   | @ | A S r   r   )masktarget)retainr   r   r      r   zsimple.<locals>.<lambda>)+rC   rD   )rematchr    dictgroupr   r   operatoror_replaceand_partial)r*   parsedspecsr=   masksrF   rB   Zop_mapr   )rH   r@   rA   r5   r   r,   G   s*     


r,   c                   @   s0   e Zd ZdZedd Zedd Zdd ZdS )	Permissionsz
    >>> perms = Permissions(0o764)
    >>> oct(perms)
    '0o764'
    >>> perms.symbolic
    'rwxrw-r--'
    >>> str(perms)
    'rwxrw-r--'
    >>> str(Permissions(0o222))
    '-w--w--w-'
    c                 C   s"   d dd ttd| jD S )N c                 s   s   | ]\}}d |g| V  qdS )rC   Nr   )r3   valbitr   r   r   r6      s    z'Permissions.symbolic.<locals>.<genexpr>Zrwx)joinzipr   cyclebitsselfr   r   r   symbolic   s    
zPermissions.symbolicc                 C   s   t ttt| dddS )Nr   	   )r$   )r   tupler)   r   r^   r   r   r   r]      s    zPermissions.bitsc                 C   s   | j S r   )r`   r^   r   r   r   __str__   s    zPermissions.__str__N)__name__
__module____qualname____doc__propertyr`   r]   rc   r   r   r   r   rV      s   

rV   )NNF)r   r   rN   rJ   typingr   r   r   r   r)   strr   r.   r,   rV   r   r   r   r   <module>   s    
 
B