B
    7Ør\ê  ã               @   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mZ ejj	Z
ejjdk	rXe
ejj7 Z
e d e e
¡¡¡Z[
dd„ Zdd„ ZG d	d
„ d
eƒZdd„ Zdd„ ZG dd„ deƒZejdd„ ƒZddd„ZdS )zC A universal module with functions / classes without dependencies. é    N)Úreraisez (?:\.[^{0}]+|[{0}]__init__\.py)$c                s   ‡ fdd„}|S )Nc                 s   t ˆ | |ŽƒS )N)Úlist)ÚargsÚkwargs)Úfunc© ú2lib/python3.7/site-packages/jedi/evaluate/utils.pyÚwrapper   s    zto_list.<locals>.wrapperr   )r   r	   r   )r   r   Úto_list   s    r
   c             C   s   t dd„ | D ƒƒS )z5Turns a two dimensional array into a one dimensional.c             s   s   | ]}|D ]
}|V  q
qd S )Nr   )Ú.0ÚtypesÚtypr   r   r   ú	<genexpr>   s    zunite.<locals>.<genexpr>)Úset)Úiterabler   r   r   Úunite   s    r   c               @   s   e Zd ZdZdS )ÚUncaughtAttributeErroraè  
    Important, because `__getattr__` and `hasattr` catch AttributeErrors
    implicitly. This is really evil (mainly because of `__getattr__`).
    `hasattr` in Python 2 is even more evil, because it catches ALL exceptions.
    Therefore this class originally had to be derived from `BaseException`
    instead of `Exception`.  But because I removed relevant `hasattr` from
    the code base, we can now switch back to `Exception`.

    :param base: return values of sys.exc_info().
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r      s   
r   c             C   s   t t| ƒƒS )N)ÚpropertyÚreraise_uncaught)r   r   r   r   Úsafe_property*   s    r   c                s   t  ˆ ¡‡ fdd„ƒ}|S )aŠ  
    Re-throw uncaught `AttributeError`.

    Usage:  Put ``@rethrow_uncaught`` in front of the function
    which does **not** suppose to raise `AttributeError`.

    AttributeError is easily get caught by `hasattr` and another
    ``except AttributeError`` clause.  This becomes problem when you use
    a lot of "dynamic" attributes (e.g., using ``@property``) because you
    can't distinguish if the property does not exist for real or some code
    inside of the "dynamic" attribute through that error.  In a well
    written code, such error should not exist but getting there is very
    difficult.  This decorator is to help us getting there by changing
    `AttributeError` to `UncaughtAttributeError` to avoid unexpected catch.
    This helps us noticing bugs earlier and facilitates debugging.

    .. note:: Treating StopIteration here is easy.
              Add that feature when needed.
    c                 sB   y
ˆ | |ŽS  t k
r<   t ¡ }tt|d ƒ|d ƒ Y nX d S )Né   é   )ÚAttributeErrorÚsysÚexc_infor   r   )r   Úkwdsr   )r   r   r   r	   B   s
    
z!reraise_uncaught.<locals>.wrapper)Ú	functoolsÚwraps)r   r	   r   )r   r   r   .   s    r   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚPushBackIteratorc             C   s   g | _ || _d | _d S )N)ÚpushesÚiteratorÚcurrent)Úselfr$   r   r   r   Ú__init__M   s    zPushBackIterator.__init__c             C   s   | j  |¡ d S )N)r#   Úappend)r&   Úvaluer   r   r   Ú	push_backR   s    zPushBackIterator.push_backc             C   s   | S )Nr   )r&   r   r   r   Ú__iter__U   s    zPushBackIterator.__iter__c             C   s   |   ¡ S )z Python 2 Compatibility )Ú__next__)r&   r   r   r   ÚnextX   s    zPushBackIterator.nextc             C   s&   | j r| j  ¡ | _nt| jƒ| _| jS )N)r#   Úpopr%   r-   r$   )r&   r   r   r   r,   \   s    zPushBackIterator.__next__N)r   r   r   r'   r*   r+   r-   r,   r   r   r   r   r"   L   s
   r"   c              g   s$   y
dV  W n | k
r   Y nX dS )zŠ
    Context manager that ignores all of the specified exceptions. This will
    be in the standard library starting with Python 3.4.
    Nr   )Ú
exceptionsr   r   r   Úignoredd   s    
r0   ú    c                sX   d}x,| r0| d dkr0|| d 7 }| dd… } qW |   d¡}d t‡ fdd„|ƒ¡| S )zAThis function indents a text block with a default of four spaces.Ú éÿÿÿÿÚ
Nc                s   ˆ |  S )Nr   )Ús)Ú	indentionr   r   Ú<lambda>w   s    zindent_block.<locals>.<lambda>)ÚsplitÚjoinÚmap)Útextr6   ZtempÚlinesr   )r6   r   Úindent_blockp   s    
r=   )r1   )r   r   Ú
contextlibr    ÚreÚosZjedi._compatibilityr   ÚpathÚsepZ_sepÚaltsepÚcompileÚformatÚescapeZ_path_rer
   r   Ú	Exceptionr   r   r   Úobjectr"   Úcontextmanagerr0   r=   r   r   r   r   Ú<module>   s&   