B
    7r\hJ                 @   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ZddlZyddl	Z	W n e
k
rd   Y nX ejd dkZeoejd dkZeeejd eejd  ZG dd deZdKd	d
ZdLddZdMddZereneZde_ dNddZedk renejZG dd deZer$e	jjZndd ZyeZW n ek
rN   eZY nX er`dd Znee ddd de_ G dd deZ!d d! Z"yej#j$Z$e$dkrd"Z$W n e%k
r   d#Z$Y nX dOd%d&Z&d'd( Z'd)d* Z(yddl)Z)W n e
k
r   ddl*Z)Y nX ddl+Z+d+d, Z,ydd-l-m.Z. W n" e
k
rL   dd.l-m/Z. Y nX ye0Z0W n ek
rp   e1Z0Y nX ye2Z2W n ek
r   e1Z2Y nX ye3Z3W n ek
r   e1Z3Y nX d/d0 Z4d1d2 Z5d3d4 Z6erddl7Z7nddl8Z7yddl9Z:W n e
k
r   ddl:Z:Y nX ejdd5 d6krbG d7d8 d8e:j;Z<dPd:d;Z=dQd<d=Z>e<e:_?e=e:_=e>e:_>d>d? Z@d@dA ZAdBdC ZByddDlmCZC W n& e
k
r   G dEdF dFeZCY nX G dGdH dHejDZEejFejGB dfdIdJZHdS )Rz
To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been
created. Clearly there is huge need to use conforming syntax.
    N         c               @   s$   e Zd Zdd Zdd Zdd ZdS )	DummyFilec             C   s   || _ || _d S )N)loaderstring)selfr   r    r	   2lib/python3.7/site-packages/jedi/_compatibility.py__init__   s    zDummyFile.__init__c             C   s   | j | jS )N)r   
get_sourcer   )r   r	   r	   r
   read   s    zDummyFile.readc             C   s   | ` d S )N)r   )r   r	   r	   r
   close   s    zDummyFile.closeN)__name__
__module____qualname__r   r   r   r	   r	   r	   r
   r      s   r   Tc       
   	   C   s   d }d }xt jD ]}|r*|tjjkr*d }n|}y
|j}W n tk
rN   wY nX || |}|d k	r|j}|d kr|js|s~| n|}t	||j
j}	d |	dfS P qW t| ||S )NF)sys	meta_path	importlib	machinery
PathFinder	find_specAttributeErrorr   has_locationImplicitNSInfosubmodule_search_locations_pathfind_module_py33)
r   path	full_nameis_global_searchspecr   finderpr   Zimplicit_ns_infor	   r	   r
   find_module_py34#   s&    


r$   c       	      C   sv  |pt jj| |}|d kr~|d kr~y&tjdd t | }W d Q R X W n2 tk
r| } ztdt	| W d d }~X Y nX |d krtd
| yn|| }|rt|drtj|j}ntj|| }t|drt|| }nd }n|| }t|| }W nV tk
rX   z8y|j}t|| }W n tk
rH   | }d }Y nX W d d}X Y nX t|drl|j}|||fS )NT)recordzOriginally  zCouldn't find a loader for {}r   archiveF)r   r   r   find_modulewarningscatch_warningsfind_loader
ValueErrorImportErrorreprformat
is_packagehasattrosr   dirnameget_filenamer   r   r&   )	r   r   r   r   r    er/   module_pathmodule_filer	   r	   r
   r   @   s>    "



r   c          	   C   s  dd l }y*|| |\}}}|d }||||jkfS  tk
rF   Y nX |d krVtj}x|D ]}	t|	}
|
r\yj|
| }
|
r|
| }t	|
d}|

| }|rtj|}|r|
j}d }|r|rt|
| }|||fS W q\ tk
r   Y q\X q\W td| d S )Nr      r&   zNo module named {})impr'   PKG_DIRECTORYr,   r   r   pkgutilget_importerr/   r0   r3   r1   r2   r&   r   r.   )r   r   r   r    r8   r6   r5   Zdescriptionmodule_typeitemr   r/   Z
is_archivefiler	   r	   r
   find_module_pre_py34u   s:    







r?   a  
Provides information about a module.

This function isolates the differences in importing libraries introduced with
python 3.3 on; it gets a module name and optionally a path. It will return a
tuple containin an open file for the module (if not builtin), the filename
or the name of the module if it is a builtin one and a boolean indicating
if the module is contained in a package.
 c       
   
   c   sd  x\| D ]R}t |}t|tjjsFxt |g|D ]
}|V  q6W q|jd ks^tj	|jsbd S i }yt
|j}W n tk
r   g }Y nX |  x|D ]}t|}|dks||krq|ds|dkrqtj|j|}d}	|s4tj	|r4d|kr4|}yt
| W n tk
r.   wY nX d}	|rd|krd||< ||| |	fV  qW qW d S )Nr   .__pycache__FTr   )r:   r;   
isinstancer   r   
FileFinderiter_modulesr   r1   isdirlistdirOSErrorsortinspectgetmodulename
startswithjoin)
pathsprefixr   importerZmod_infoyielded	filenamesfnmodnameispkgr	   r	   r
   _iter_modules   s@    




rV   "   c               @   s   e Zd ZdZdd ZdS )r   z;Stores information returned from an implicit namespace specc             C   s   || _ || _d S )N)namerN   )r   rX   rN   r	   r	   r
   r      s    zImplicitNSInfo.__init__N)r   r   r   __doc__r   r	   r	   r	   r
   r      s   r   c              C   s   dd l } dd |  D S )Nr   c             S   s   g | ]\}}}|qS r	   r	   ).0suffix_r	   r	   r
   
<listcomp>   s    z all_suffixes.<locals>.<listcomp>)r8   Zget_suffixes)r8   r	   r	   r
   all_suffixes   s    r^   c             C   s   |  |d S )N)with_traceback)Z	exception	tracebackr	   r	   r
   reraise   s    ra   zI
def reraise(exception, traceback):
    raise exception, None, traceback
Zblubexeczf
Re-raise `exception` with a `traceback` object.

Usage::

    reraise(Exception, sys.exc_info()[2])

c               @   s   e Zd Zdd Zdd ZdS )Python3Methodc             C   s
   || _ d S )N)func)r   rd   r	   r	   r
   r     s    zPython3Method.__init__c                s&    d krfddS  fddS d S )Nc                 s    j | |S )N)rd   )argskwargs)r   r	   r
   <lambda>  s    z'Python3Method.__get__.<locals>.<lambda>c                 s   j  f| |S )N)rd   )re   rf   )objr   r	   r
   rg     s    r	   )r   rh   Zobjtyper	   )rh   r   r
   __get__  s    zPython3Method.__get__N)r   r   r   r   ri   r	   r	   r	   r
   rc   
  s   rc   c             G   s   |s
t f}| d|i S )z" Create a class with a metaclass. ZPy2CompatibilityMetaClass)object)metabasesr	   r	   r
   use_metaclass  s    rm   zutf-8asciistrictc             C   s   t | trt| d|dS | S )zCast to unicode DAMMIT!
    Written because Python2 repr always implicitly casts to a string, so we
    have to cast back to a unicode (and we now that we always deal with valid
    unicode, because we check that in the beginning).
    zUTF-8)encodingerrors)rC   bytesunicode)r   rq   r	   r	   r
   u$  s    
rt   c             C   s   t | ddS )ad  
    Take a bytes or str path and cast it to unicode.

    Apparently it is perfectly fine to pass both byte and unicode objects into
    the sys.path. This probably means that byte paths are normal at other
    places as well.

    Since this just really complicates everything and Python 2.7 will be EOL
    soon anyway, just go with always strings.
    replace)rq   )rt   )rh   r	   r	   r
   	cast_path/  s    rv   c             C   s   t | S )N)rv   )rh   r	   r	   r
   force_unicode=  s    rw   c             C   s
   t | S )N)astliteral_eval)r   r	   r	   r
   ry   L  s    ry   )zip_longest)izip_longestc             C   s(   ddl }|| }ttdd| dS )a  
    Python 2/3 dict __repr__ may be different, because of unicode differens
    (with or without a `u` prefix). Normally in doctests we could use `pprint`
    to sort dicts and check for equality, but here we have to write a separate
    function to do that.
    r   Nzu'')pprintZpformatprintresub)Zdctr}   sr	   r	   r
   no_unicode_pprinte  s    
r   c              G   s*   t rtd nttj? | f tj  d S )Nzprint(*args, file=sys.stderr))is_py3evalr~   r   stderrflush)re   r	   r	   r
   print_to_stderrq  s    
r   c                s    fdd}t r S |S dS )z
    ``__repr__`` methods in Python 2 don't allow unicode objects to be
    returned. Therefore cast them to utf-8 bytes in this decorator.
    c                s$    | }t |tr|dS |S d S )Nzutf-8)rC   rs   encode)r   result)rd   r	   r
   wrapper~  s    

zutf8_repr.<locals>.wrapperN)r   )rd   r   r	   )rd   r
   	utf8_repry  s    r   r7   )r   r   c               @   sb   e Zd ZeejjZdd Zdd Zeeej	d < dd Z
e
eejd < dd	 Zeeejd < d
S )NewUnpicklerc             C   s"   | j dkr|S || j | jS d S )Nrr   )rp   decoderq   )r   valuer	   r	   r
   _decode_string  s    
zNewUnpickler._decode_stringc             C   sp   |   d d }t|dkrF|d |d krF|d dkrF|dd }n
td| | tj|d  d S )Nr7   r   s   "'r   z)the STRING opcode argument must be quoted)readlinelenpickleUnpicklingErrorappendr   codecsescape_decode)r   datar	   r	   r
   load_string  s
    (
zNewUnpickler.load_stringr   c             C   sF   t jd| d\}|dk r(t d| |}| | | d S )Nz<i   r   z(BINSTRING pickle has negative byte count)r   ZstructZunpackr   r   r   r   )r   r   r   r	   r	   r
   load_binstring  s
    

zNewUnpickler.load_binstringc             C   s,   |  dd }|  |}| | | d S )Nr   r   )r   r   r   )r   r   r   r	   r	   r
   load_short_binstring  s    
z!NewUnpickler.load_short_binstringN)r   r   r   dictr   
_Unpicklerdispatchr   r   STRINGr   Z	BINSTRINGr   ZSHORT_BINSTRINGr	   r	   r	   r
   r     s   	r   ASCIIc             C   s   t | |||d S )N)fix_importsrp   rq   )r   load)r>   r   rp   rq   r	   r	   r
   r     s    r   c             C   s2   t | trtdtj| }t||||d S )Nz%Can't load pickle from unicode string)r   rp   rq   )rC   str	TypeErrorr   ioBytesIOr   r   )r   r   rp   rq   r>   r	   r	   r
   loads  s
    
r   c             C   sH   yt rtj| ddS t| S  tk
rB   tjdkr<t  Y nX d S )Nrr   )rp   win32)r   r   r   rH   r   platformEOFError)r>   r	   r	   r
   pickle_load  s    

r   c             C   sL   yt | || |  W n, tk
rF   tjdkr@ttjd Y nX d S )Nr   zBroken pipe)	r   dumpr   rH   r   r   IOErrorerrnoZEPIPE)r   r>   protocolr	   r	   r
   pickle_dump  s    
r   c             C   s6   d}x,| D ]$}|d dkrdS |d dk r
d}q
W |S )Nr   r   r7   r   r   r	   )Zpython_versionsr   versionr	   r	   r
   highest_pickle_protocol  s    
r   )	Parameterc               @   s*   e Zd Ze Ze Ze Ze Ze ZdS )r   N)	r   r   r   rj   ZPOSITIONAL_ONLYZPOSITIONAL_OR_KEYWORDZVAR_POSITIONALZKEYWORD_ONLYZVAR_KEYWORDr	   r	   r	   r
   r     s
   r   c                   s   e Zd Z fddZ  ZS )GeneralizedPopenc                sZ   t jdkr6y
tj}W n tk
r,   d}Y nX ||d< dtjk|d< tt| j	|| d S )Nnti   ZcreationflagsposixZ	close_fds)
r1   rX   
subprocessCREATE_NO_WINDOWr   r   builtin_module_namessuperr   r   )r   re   rf   r   )	__class__r	   r
   r     s    


zGeneralizedPopen.__init__)r   r   r   r   __classcell__r	   r	   )r   r
   r     s   r   c                s"  dd }t j r&| |r" S dS |dkr>t jdt j}|sFdS |t j}tj	dkrt j
|krt|dt j
 t jddt j}t fd	d
|D r g}q fdd|D }n g}t }xT|D ]L}t j|}||kr|| x(|D ] }	t j||	}
||
|r|
S qW qW dS )a3  Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.

    `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
    of os.environ.get("PATH"), or can be overridden with a custom search
    path.

    c             S   s&   t j| o$t | |o$t j|  S )N)r1   r   existsaccessrF   )rS   moder	   r	   r
   _access_check#  s    zwhich.<locals>._access_checkNPATHr   r   ZPATHEXTr@   c             3   s    | ]}   |  V  qd S )N)lowerendswith)rZ   ext)cmdr	   r
   	<genexpr>@  s    zwhich.<locals>.<genexpr>c                s   g | ]} | qS r	   r	   )rZ   r   )r   r	   r
   r]   C  s    zwhich.<locals>.<listcomp>)r1   r   r2   environgetdefpathsplitpathsepr   r   curdirinsertanysetnormcaseaddrM   )r   r   r   r   ZpathextfilesseendirZnormdirZthefilerX   r	   )r   r
   which  s8    






r   )NNT)NNNT)NNT)r@   )ro   )Tr   ro   )Tr   ro   )IrY   r   r   r1   r   r:   r(   rJ   r   r   r,   version_infor   Zis_py35intr   Z
py_versionrj   r   r$   r   r?   r'   rV   rE   r   r   r^   rs   	NameErrorra   r   compilerc   rm   stdoutrp   r   rt   rv   rw   builtinsZ__builtin__rx   ry   	itertoolsrz   r{   FileNotFoundErrorr   NotADirectoryErrorPermissionErrorr   r   r   ZqueueZQueueZcPickler   r   r   r   r   Z	Unpicklerr   r   r   r   Popenr   F_OKX_OKr   r	   r	   r	   r
   <module>   s    

5
#	
8


	






%

