
V]c           @  sV  d  Z  d d l m 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
 d d l Z d d l Z d d l Z y d d l Z Wn e k
 r n Xd d l m Z d d l m Z m Z e j d d k Z e oe j d d	 k Z e e e j d  e e j d   Z d
 e f d     YZ d d e d  Z d d d e d  Z  d   Z! d   Z" d d e d  Z# e re n e# Z$ d e$ _  d d  Z% e d k re% n e	 j& Z& d e f d     YZ' e re j( j) Z) n	 d   Z) y
 e* Z* Wn e+ k
 r4e Z* n Xe rGd   Z, n e- e. d d d   d e, _  d   Z/ y% e j0 j1 Z1 e1 d k rd Z1 n  Wn e2 k
 rd Z1 n Xd  d!  Z3 d"   Z4 d#   Z5 y d d l6 Z6 Wn e k
 rd d l7 Z6 n Xd d l8 Z8 d$   Z9 y d d% l: m; Z; Wn! e k
 rHd d& l: m< Z; n Xy
 e= Z= Wn e+ k
 rle> Z= n Xy
 e? Z? Wn e+ k
 re> Z? n Xy
 e@ Z@ Wn e+ k
 re> Z@ n Xd'   ZA d(   ZB e rd d lC ZC n d d lD ZC y d d lE ZF Wn e k
 rd d lF ZF n Xe j d)  d; k rd* eF jG f d+     YZH e d, d  d-  ZI e d, d  d.  ZJ eH eF _K eI eF _I eJ eF _J n  d/   ZL d0   ZM d1   ZN d2   ZO y d d3 l mP ZP Wn' e k
 rd4 e f d5     YZP n Xd6 e jQ f d7     YZR e jS e jT Bd d8  ZU e sRd9 e f d:     YZV e jW eV jX  eV e _V n  d S(<   s   
To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been
created. Clearly there is huge need to use conforming syntax.
i(   t   print_functionN(   t   zipimporter(   t   KnownContentFileIOt	   ZipFileIOi    i   i   i   t	   DummyFilec           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s   | |  _  | |  _ d  S(   N(   t   loadert   string(   t   selfR   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   __init__   s    	c         C  s   |  j  j |  j  S(   N(   R   t
   get_sourceR   (   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   read#   s    c         C  s
   |  `  d  S(   N(   R   (   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   close&   s    (   t   __name__t
   __module__R   R
   R   (    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR      s   		c   
      C  s   d  } d  } x t j D] } | r= | t j j k r= d  } n | } y | j } Wn t k
 rf q n X| |  |  } | d  k	 r | j } | d  k r | j	 r | s |  n | } t
 | | j j  }	 |	 t f SPq q Wt |  | |  S(   N(   t   Nonet   syst	   meta_patht	   importlibt	   machineryt
   PathFindert	   find_spect   AttributeErrorR   t   has_locationt   ImplicitNSInfot   submodule_search_locationst   _patht   Truet   find_module_py33(
   R   t   patht	   full_namet   is_global_searcht   specR   t   findert   pR   t   implicit_ns_info(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   find_module_py34*   s&    		
c         C  s   | p t  j j j |  |  } | d  k r | d  k r y, t j d t   t  j |   } Wd  QXWq t	 k
 r } t
 d t |    q Xn  | d  k r t
 d j |     n  t | |   S(   Nt   records   Originally  s   Couldn't find a loader for {}(   R   R   R   t   find_moduleR   t   warningst   catch_warningsR   t   find_loadert
   ValueErrort   ImportErrort   reprt   formatt   _from_loader(   R   R   R   R   R   t   e(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR   G   s    c         C  s   |  j  |  } y |  j } Wn t k
 r6 d  | f SXt | |   } t |   j } t r | t j	 j
 j k	 r |  j |  } n t |  |  } | d  k r d  | f St |  t  r t | | t |  j   | f St | |  | f S(   N(   t
   is_packaget   get_filenameR   R   t	   cast_patht   typeR	   t   is_py3R   R   t   SourceFileLoadert   _get_sourcet
   isinstanceR   R   t   archiveR   (   R   R   R/   R0   t   module_patht   ft   code(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR-   ^   s    
c         C  sJ   |  j  |  } y |  j |  SWn# t k
 rE t d d |  n Xd S(   s   
    This method is here as a replacement for SourceLoader.get_source. That
    method returns unicode, but we prefer bytes.
    s'   source not available through get_data()t   nameN(   R0   t   get_datat   OSErrorR*   (   R   t   fullnameR   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR5   |   s    	c         C  s  d d  l  } y | j |  |  \ } } } | d } | | j k }	 |	 r t j j | d  }
 y t |
  } |
 } Wq t k
 r q Xn1 | | j k r | d  k	 r | j
   n  d  } n  | d  k r d  } d  |	 f S|  | j   } Wd  QXt t |  |  |	 f SWn t k
 rn X| d  k r7t j } n  xN | D]F } t j |  } | r>| j |   } | d  k	 rt | |   Sq>q>Wt d j |     d  S(   Nii   s   __init__.pys   No module named {}(   t   impR%   t   PKG_DIRECTORYt   osR   t   joint   opent   FileNotFoundErrort	   PY_SOURCER   R   R
   R   R1   R*   R   t   pkgutilt   get_importerR-   R,   (   R   R   R   R   R?   t   module_fileR8   t   descriptiont   module_typeR/   R!   R:   t   itemR   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   find_module_pre_py3   sB    

	
s  
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.
t    c   
      c  s  x|  D]} t  j |  } t | t j j  s\ x" t  j | g |  D] } | VqG Wq n  | j d  k s t	 j j
 | j  r d  Si  } y t	 j | j  } Wn t k
 r g  } n X| j   x| D] } t j |  } | d k s | | k r q n  | j d  s | d k r q n  t	 j j | j |  } t }	 | rt	 j j
 |  rd | k r| } y t	 j |  Wn t k
 rq n Xt }	 n  | r d | k r d | | <| | | |	 f Vq q Wq Wd  S(   NR   t   .t   __pycache__i   (   RF   RG   R6   R   R   t
   FileFindert   iter_modulesR   R   RA   t   isdirt   listdirR=   t   sortt   inspectt   getmodulenamet
   startswithRB   t   FalseR   (
   t   pathst   prefixR   t   importert   mod_infot   yieldedt	   filenamest   fnt   modnamet   ispkg(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   _iter_modules   s@    	%

%	
i"   R   c           B  s   e  Z d  Z d   Z RS(   s;   Stores information returned from an implicit namespace specc         C  s   | |  _  | |  _ d  S(   N(   R;   RY   (   R   R;   RY   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR      s    	(   R   R   t   __doc__R   (    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR      s   c          C  s2   d d  l  }  g  |  j   D] \ } } } | ^ q S(   Ni(   R?   t   get_suffixes(   R?   t   suffixt   _(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   all_suffixes  s    c         C  s   |  j  |   d  S(   N(   t   with_traceback(   t	   exceptiont	   traceback(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   reraise  s    sI   
def reraise(exception, traceback):
    raise exception, None, traceback
t   blubt   execsf   
Re-raise `exception` with a `traceback` object.

Usage::

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

c         G  s"   | s t  f } n  |  d | i   S(   s"    Create a class with a metaclass. t   Py2CompatibilityMetaClass(   t   object(   t   metat   bases(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   use_metaclass&  s    s   utf-8t   asciit   strictc         C  s)   t  |  t  r% t |  d d d | S|  S(   s   Cast 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).
    t   encodings   UTF-8t   errors(   R6   t   bytest   unicode(   R   Rv   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   u5  s    c         C  s   t  |  d d S(   sd  
    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.
    Rv   t   replace(   Ry   (   t   obj(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR1   @  s    c         C  s
   t  |   S(   N(   R1   (   R{   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   force_unicodeN  s    c         C  s   t  j |   S(   N(   t   astt   literal_eval(   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR~   ]  s    (   t   zip_longest(   t   izip_longestc         C  s8   d d l  } | j |   } t t j d d |   d S(   s  
    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.
    iNs   u't   '(   t   pprintt   pformatt   printt   ret   sub(   t   dctR   t   s(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   no_unicode_pprintv  s    c           s!     f d   } t  r   S| Sd S(   s   
    ``__repr__`` methods in Python 2 don't allow unicode objects to be
    returned. Therefore cast them to utf-8 bytes in this decorator.
    c           s0     |   } t  | t  r( | j d  S| Sd  S(   Ns   utf-8(   R6   Rx   t   encode(   R   t   result(   t   func(    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   wrapper  s    N(   R3   (   R   R   (    (   R   s2   lib/python2.7/site-packages/jedi/_compatibility.pyt	   utf8_repr  s    i   t   NewUnpicklerc           B  sq   e  Z e e j j  Z d    Z d   Z e e e j d <d   Z	 e	 e e j
 d <d   Z e e e j d <RS(   c         C  s-   |  j  d k r | S| j |  j  |  j  Sd  S(   NRw   (   Ru   t   decodeRv   (   R   t   value(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   _decode_string  s    c         C  s   |  j    d  } t |  d k rV | d | d k rV | d d k rV | d d !} n t j d   |  j |  j t j j |  d   d  S(   Nii   i    s   "'i   s)   the STRING opcode argument must be quoted(   t   readlinet   lent   picklet   UnpicklingErrort   appendR   t   codecst   escape_decode(   R   t   data(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   load_string  s
    6i    c         C  sh   t  j j d |  j d   \ } | d k  r? t  j d   n  |  j |  } |  j |  j |   d  S(   Ns   <ii   i    s(   BINSTRING pickle has negative byte count(   R   t   structt   unpackR
   R   R   R   (   R   R   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   load_binstring  s
    !c         C  s<   |  j  d  d } |  j  |  } |  j |  j |   d  S(   Ni   i    (   R
   R   R   (   R   R   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   load_short_binstring  s    (   R   R   t   dictR   t
   _Unpicklert   dispatchR   R   t   STRINGR   t	   BINSTRINGR   t   SHORT_BINSTRING(    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s   					t   ASCIIc         C  s"   t  |  d | d | d | j   S(   Nt   fix_importsRu   Rv   (   R   t   load(   t   fileR   Ru   Rv   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s    c         C  sR   t  |  t  r t d   n  t j j |   } t | d | d | d | j   S(   Ns%   Can't load pickle from unicode stringR   Ru   Rv   (   R6   t   strt	   TypeErrorR   t   iot   BytesIOR   R   (   R   R   Ru   Rv   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   loads  s
    c         C  s`   y* t  r t j |  d d St j |   SWn/ t k
 r[ t j d k rU t    n    n Xd  S(   NRu   Rw   t   win32(   R3   R   R   R=   R   t   platformt   EOFError(   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   pickle_load  s    c         C  s   t  |  t  r# t d   |  D  St  |  t  rF t d   |  D  St |  d  r t |  j  t k r d   |  j j   D |  _ n  |  S(   s   
    Python 2 stores object __dict__ entries as bytes, not unicode, correct it
    here. Python 2 can deal with both, Python 3 expects unicode.
    c         s  s   |  ] } t  |  Vq d  S(   N(   t   _python2_dct_keys_to_unicode(   t   .0t   x(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pys	   <genexpr>  s    c         s  s   |  ] } t  |  Vq d  S(   N(   R   (   R   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pys	   <genexpr>  s    t   __dict__c         S  s%   i  |  ] \ } } | t  |   q S(    (   Rx   (   R   t   kt   v(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pys
   <dictcomp>  s   	 (   R6   t   tuplet   listt   hasattrR2   R   R   t   items(   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s    $c         C  su   y6 t  s t |   }  n  t j |  | |  | j   Wn8 t k
 rp t j d k rj t t	 j
 d   n    n Xd  S(   NR   s   Broken pipe(   R3   R   R   t   dumpt   flushR=   R   R   t   IOErrort   errnot   EPIPE(   R   R   t   protocol(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   pickle_dump  s    c         C  sH   d } x; |  D]3 } | d d k r' d S| d d k  r d } q q W| S(   Ni   i    i   i   i   (    (   t   python_versionsR   t   version(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   highest_pickle_protocol  s    (   t	   ParameterR   c           B  s5   e  Z e   Z e   Z e   Z e   Z e   Z RS(    (   R   R   Ro   t   POSITIONAL_ONLYt   POSITIONAL_OR_KEYWORDt   VAR_POSITIONALt   KEYWORD_ONLYt   VAR_KEYWORD(    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s
   				t   GeneralizedPopenc           B  s   e  Z d    Z RS(   c         O  ss   t  j d k rC y t j } Wn t k
 r5 d } n X| | d <n  d t j k | d <t t |   j	 | |   d  S(   Nt   nti   t   creationflagst   posixt	   close_fds(
   RA   R;   t
   subprocesst   CREATE_NO_WINDOWR   R   t   builtin_module_namest   superR   R   (   R   t   argst   kwargsR   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR      s    
(   R   R   R   (    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s   c           s  d   } t  j j    r2 |   |  r.   Sd S| d k rY t  j j d t  j  } n  | sc d S| j t  j  } t	 j
 d k rt  j | k r | j d t  j  n  t  j j d d  j t  j  } t   f d   | D  r   g } qg  | D] }   | ^ q } n	   g } t   } xu | D]m } t  j j |  }	 |	 | k r+| j |	  x9 | D]. }
 t  j j | |
  } | | |  rc| SqcWq+q+Wd S(	   s3  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  s5   t  j j |   o4 t  j |  |  o4 t  j j |   S(   N(   RA   R   t   existst   accessRR   (   R_   t   mode(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   _access_check<  s    $t   PATHR   i    t   PATHEXTRM   c         3  s*   |  ]  }   j    j | j     Vq d  S(   N(   t   lowert   endswith(   R   t   ext(   t   cmd(    s2   lib/python2.7/site-packages/jedi/_compatibility.pys	   <genexpr>Y  s    N(   RA   R   t   dirnameR   t   environt   gett   defpatht   splitt   pathsepR   R   t   curdirt   insertt   anyt   sett   normcaset   addRB   (   R   R   R   R   t   pathextt   filesR   t   seent   dirt   normdirt   thefileR;   (    (   R   s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   which/  s8    	! 		t   finalizec           B  s;   e  Z d  Z d Z i  Z d   Z d   Z e d    Z RS(   s  Class for finalization of weakrefable objects.

        finalize(obj, func, *args, **kwargs) returns a callable finalizer
        object which will be called when obj is garbage collected. The
        first time the finalizer is called it evaluates func(*arg, **kwargs)
        and returns the result. After this the finalizer is dead, and
        calling it just returns None.

        When the program exits any remaining finalizers will be run.
        c         O  s;   t  j | | |  } t j | |   | _ | |  j |  <d  S(   N(   t	   functoolst   partialt   weakreft   reft	   _registry(   R   R{   R   R   R   t   info(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR     s    c         C  s&   |  j  j |  d  } | r" |   Sd S(   s&   Return func(*args, **kwargs) if alive.N(   R   t   popR   (   R   R   (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   __call__  s    c         C  sr   |  j  s d  Sx^ t |  j   D]M } y |   Wn$ t k
 rT t j t j     n X| |  j  k s t  q Wd  S(   N(   R   R   t	   ExceptionR   t
   excepthookt   exc_infot   AssertionError(   t   clst	   finalizer(    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt	   _exitfunc  s    	(    (	   R   R   Rc   t	   __slots__R   R   R   t   classmethodR  (    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyR   q  s   
		(   i   i   (Y   Rc   t
   __future__R    t   atexitR   R   R   RA   R   RF   R&   RU   R   R   R   R*   t	   zipimportR   t   jedi.file_ioR   R   t   version_infoR3   t   is_py35t   intR   t
   py_versionRo   R   R   R   R#   R   R-   R5   RL   R%   Rb   RQ   R   R   Rg   Rx   t	   NameErrorRk   t   evalt   compileRr   t   stdoutRu   R   Ry   R1   R|   t   builtinst   __builtin__R}   R~   t	   itertoolsR   R   RD   R   t   IsADirectoryErrort   PermissionErrorR   R   t   queuet   Queuet   cPickleR   R   R   R   R   t	   UnpicklerR   R   R   R   R   t   PopenR   t   F_OKt   X_OKR   R   t   registerR  (    (    (    s2   lib/python2.7/site-packages/jedi/_compatibility.pyt   <module>   s   *		+		8	

			
			





		%						?'