ó
‹²,]c           @   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 d d l Z d d l	 m
 Z
 d d l m Z m Z d d l m Z d d l m Z e d ƒ Z e j d	 k rÈ d
 Z n d Z e ƒ  rí e j ƒ  d g Z n e j ƒ  Z e j d d j d „  e Dƒ ƒ ƒ Z e e ƒ Z d „  Z d „  Z d „  Z d „  Z e d „ Z  d „  Z! g  d „ Z" d „  Z# d „  Z$ d S(   s“   
Module completion auxiliary functions.

Adapted from IPython/core/completerlib.py of the
`IPython Project <https://github.com/ipython/ipython>`_.
iÿÿÿÿN(   t   time(   t   zipimporter(   t   get_conf_patht   running_in_mac_app(   t   PY3(   t   PickleShareDBt   dbt   nti   i   s   .pyct   rbt   2sK   (?P<name>[a-zA-Z_][a-zA-Z0-9_]*?)(?P<package>[/\\]__init__)?(?P<suffix>%s)$t   |c         c   s"   |  ] } t  j | d  ƒ Vq d S(   i    N(   t   ret   escape(   t   .0t   s(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pys	   <genexpr>B   s    c            s4  |  d k r d }  n  t  j j ‰  t  j j |  ƒ r° g  } x£ t  j |  ƒ D]` \ } } } | t |  ƒ d ‰ ˆ rœ | j ‡  ‡ f d †  | Dƒ ƒ g  | (qI | j | ƒ qI Wn/ y t t |  ƒ j	 j
 ƒ  ƒ } Wn g  } n Xg  } x< | D]4 } t j | ƒ } | rì | j | j d ƒ ƒ qì qì Wt t | ƒ ƒ S(   s`   
    Return the list containing the names of the modules available in the given
    folder.
    t    t   .i   c         3   s   |  ] } ˆ  ˆ | ƒ Vq d  S(   N(    (   R   t   f(   t   pjoint   subdir(    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pys	   <genexpr>_   s    t   name(   t   ost   patht   joint   isdirt   walkt   lent   extendt   listR   t   _filest   keyst	   import_ret   matcht   appendt   groupt   set(   R   t   filest   roott   dirst   nondirst   modulesR   t   m(    (   R   R   sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   module_listK   s*    	 

c         C   s?  g  } g  } x |  D] } | t  | ƒ 7} q Wt | ƒ } d | k rU | j d ƒ n  t | ƒ } d t k ry | t d St ƒ  } t t j ƒ } xG t j D]< } | t  | ƒ 7} t ƒ  | t	 k r› d GHg  t d <g  Sq› Wt | ƒ } d g | } x* | D]" } | | k rû | j | ƒ qû qû Wt | ƒ } | t d <| | S(   s  
    Returns list of names of all modules from PYTHONPATH folders.
    
    paths : list
        A list of additional paths that Spyder adds to PYTHONPATH. They are
        comming from our PYTHONPATH manager and from the currently selected
        project.
    t   __init__t   rootmoduless7   Module list generation is taking too long, we give up.
(
   R*   R#   t   removeR   t
   modules_dbR    t   syst   builtin_module_namesR   t   TIMEOUT_GIVEUP(   t   pathsR(   t   spy_modulesR   t   tt   excluded_modulest   mod(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   get_root_modulesr   s4    		

c         C   sŒ   d „  } y` t  |  ƒ } |  g } t j | j | j d | ƒ } x% | D] } | d } | j | ƒ qG WWn t k
 r} g  S|  g SX| S(   s$   Get all submodules of a given modulec         S   s   d  S(   N(    (   t   module(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   catch_exceptionsŸ   s    R   i   (   t
   __import__t   pkgutilt   walk_packagest   __path__t   __name__R!   t   ImportError(   R6   R9   R)   t
   submodulest   submodst   smt   sm_name(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   get_submodules   s    			
c         C   s?   | r t  j t |  | ƒ ƒ S| d  d k o9 | d d k Sd  S(   Ni   t   __iþÿÿÿ(   t   inspectt   ismodulet   getattr(   R8   t   attrt   only_modules(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   is_importable±   s    c         C   s@  y t  |  ƒ } Wn g  SX|  j d ƒ } x! | d D] } t | | ƒ } q5 Wt | d ƒ oi d | j k } g  } t | d ƒ s | s | rÊ | j g  t | ƒ D] } t | | | ƒ r¢ | ^ q¢ ƒ n  | j t | d g  ƒ ƒ | r| j t t	 j
 j | j ƒ ƒ ƒ n  t | ƒ } d | k r6| j d ƒ n  t | ƒ S(   NR   i   t   __file__R+   t   __all__(   R:   t   splitRH   t   hasattrRL   R   t   dirRK   R*   R   R   t   dirnameR#   R-   R   (   R6   RJ   R)   t   modsR8   t	   m_is_initt   completionsRI   (    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt
   try_import¸   s&    "%c         C   s»   t  |  ƒ d k  rB g  t | ƒ D] } | j |  d ƒ r | ^ q St d j |  d  ƒ t ƒ } g  | D] } | j |  d ƒ re | ^ qe } g  | D]  } d j |  d  | g ƒ ^ q‘ } | S(   Ni   i    R   iÿÿÿÿ(   R   R7   t
   startswithRU   R   t   True(   R6   R2   t   xt   completion_listt   el(    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   dot_completionÑ   s    0,-c         C   s  |  j  d ƒ } t | ƒ } | d k rh | d d k rh | d j d ƒ sZ | d d k ra d g Sg  Sn  | d d	 k rÙ | d k rž | d
 d k rž t | ƒ Sd | d d k r¹ d g S| d j  d ƒ } t | | ƒ S| d k  r+| d d k r+| d
 k rt | ƒ S| d
 j  d ƒ } t | | ƒ S| d k r
| d d k r
| d
 } t | ƒ } | d d	 k r| d d k rd | d k r«| d  | d j  d ƒ } n  d | d k rÙ| d  | d j  d ƒ } n  g  | D] } | j | d ƒ rà| ^ qàS| Sn  g  S(   s¥   
    Returns a list containing the completion possibilities for an import line.
    
    The line looks like this :
    'import xml.d'
    'from xml.dom import'
    t    i   i    t   fromi   t   iR   s   import t   importi   t   ,iÿÿÿÿR   t   (iþÿÿÿ(   RN   R   RV   R7   R[   RU   (   t   lineR2   t   wordst   nwordsR6   RY   RX   (    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   module_completionÝ   s:    	#


 *c           C   s   d t  k r t  d =n  d S(   s   Clear root modules databaseR,   N(   R.   (    (    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   reset  s    c       0   C   så   d t  k r t  d Sd d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 g0 }  g  } x$ |  D] } t | ƒ } | | 7} q· W| t  d <| S(2   sZ   
    Get all submodules of the main scientific modules and others of our
    interest
    R@   t   numpyt   scipyt   sympyt   pandast   networkxt   statsmodelst
   matplotlibt   sklearnt   skimaget   mpmathR   t   PILt   OpenGLt   arrayt   audioopt   binasciit   cPicklet	   cStringIOt   cmatht   collectionst   datetimet   errnot
   exceptionst   gct   imageopt   impt	   itertoolst   marshalt   matht   mmapt   msvcrtR   t   operatort   parsert   rgbimgt   signalt   stropR/   t   threadR    t   wxt	   xxsubtypet	   zipimportt   zlibt   noset   PyQt4t   PySides   os.path(   R.   RD   (   RR   R@   R)   RA   (    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   get_preferred_submodules  s     
(   s   .pycR   R	   (%   t   __doc__R   RF   t   os.pathR   R;   R   R    R/   R   R   t   spyder.config.baseR   R   t   spyder.py3compatR   t   pickleshareR   t   MODULES_PATHR   R1   t   get_suffixest   suffixest   compileR   R   R.   R*   R7   RD   RK   t   FalseRU   R[   Re   Rf   R’   (    (    (    sK   lib/python2.7/site-packages/spyder/utils/introspection/module_completion.pyt   <module>   s<   				'	+			3	