ó
î%![c           @   s   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 e	 Z
 Wn e k
 rƒ e Z
 n Xy d  d l m Z Wn! e k
 r» d  d l m Z n Xd d l m Z e j d d ƒ Z i e j e j 6e j e j 6e j e j 6e j e j 6e j e j 6e j e j 6Z e e d ƒ rTe j e e j <n  e e d ƒ rve j e e j <n  d	 „  Z e j d
 d ƒ Z  d e  f d „  ƒ  YZ! d e" f d „  ƒ  YZ# d e# f d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d e# f d „  ƒ  YZ& d e# f d „  ƒ  YZ' e$ e& f Z( e
 rJe j) d  d! k rJe( e' f 7Z( n  e( e% f 7Z( d „  Z* e ƒ  d „  ƒ Z+ d d „ Z- d „  Z. d „  Z/ d d  „ Z0 d S("   iÿÿÿÿN(   t	   lru_cachei   (   t   utilt
   ModuleTypesy   C_BUILTIN C_EXTENSION PKG_DIRECTORY PY_CODERESOURCE PY_COMPILED PY_FROZEN PY_RESOURCE PY_SOURCE PY_ZIPMODULE PY_NAMESPACEt   PY_RESOURCEt   PY_CODERESOURCEc         C   s   t  |  S(   N(   t	   _ImpTypes(   t   imp_type(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   _imp_type_to_module_type&   s    t   _ModuleSpecs4   name type location origin submodule_search_locationst
   ModuleSpecc           B   s    e  Z d  Z d d d d „ Z RS(   s¹   Defines a class similar to PEP 420's ModuleSpec

    A module spec defines a name of a module, its type, location
    and where submodules can be found, if the module is a package.
    c         C   s+   t  j |  d | d | d | d | d | ƒS(   Nt   namet   typet   locationt   origint   submodule_search_locations(   R   t   __new__(   t   clsR
   t   module_typeR   R   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR   3   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR	   ,   s   t   Finderc           B   s5   e  Z d  Z d d „ Z e j d „  ƒ Z d „  Z RS(   s@   A finder is a class which knows how to find a particular module.c         C   s   | p t  j |  _ d  S(   N(   t   syst   patht   _path(   t   selfR   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   __init__=   s    c         C   s   d S(   s÷  Find the given module

        Each finder is responsible for each protocol of finding, as long as
        they all return a ModuleSpec.

        :param str modname: The module which needs to be searched.
        :param list module_parts: It should be a list of strings,
                                  where each part contributes to the module's
                                  namespace.
        :param list processed: What parts from the module parts were processed
                               so far.
        :param list submodule_path: A list of paths where the module
                                    can be looked into.
        :returns: A ModuleSpec, describing how and where the module was found,
                  None, otherwise.
        N(    (   R   t   modnamet   module_partst	   processedt   submodule_path(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   find_module@   s    c         C   s   d S(   s7   Get a list of extra paths where this finder can search.N(    (   R   t   specR   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   contribute_to_pathS   s    N(	   R   R   R   R   R   t   abct   abstractmethodR    R"   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR   :   s   t	   ImpFinderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s!   A finder based on the imp module.c      	   C   s…   | d  k	 r t | ƒ } n  y t j | | ƒ \ } } } Wn t k
 rN d  SX| rb | j ƒ  n  t d | d | d t | d ƒ ƒ S(   NR
   R   R   i   (   R   t   listt   impR    t   ImportErrort   closeR	   R   (   R   R   R   R   R   t   streamt   mp_filenamet   mp_desc(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR    Z   s    c         C   s   | j  d  k r d  St | j  ƒ rq g  t j D]< } t j j t j j | | Œ ƒ r, t j j | | Œ ^ q, } n | j  g } | S(   N(   R   R   t   _is_setuptools_namespaceR   R   t   ost   isdirt   join(   R   R!   R   t   pR   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR"   i   s    ?(   R   R   R   R    R"   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR%   W   s   	t   ExplicitNamespacePackageFinderc           B   s    e  Z d  Z d „  Z d „  Z RS(   sN   A finder for the explicit namespace packages, generated through pkg_resources.c         C   sy   | r d j  | | g ƒ } n  t j | ƒ ru | t j k ru t j | j } t d | d d d d d t j d | ƒ Sd  S(	   Nt   .R
   R   t    R   t	   namespaceR   R   (
   R0   R   t   is_namespaceR   t   modulest   __path__R	   R   t   PY_NAMESPACER   (   R   R   R   R   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR    {   s    	c         C   s   | j  S(   N(   R   (   R   R!   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR"   ‡   s    (   R   R   R   R    R"   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR2   x   s   	t	   ZipFinderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s8   Finder that knows how to find a module inside zip files.c         C   s)   t  t |  ƒ j | ƒ t | ƒ |  _ d  S(   N(   t   superR:   R   t   _precache_zipimporterst   _zipimporters(   R   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR   Ž   s    c         C   sY   y t  | |  j ƒ \ } } } Wn t k
 r3 d  SXt d | d | d d d | d | ƒ S(   NR
   R   R   t   eggR   R   (   t   _search_zipR=   R(   R   R	   (   R   R   R   R   R   t	   file_typet   filenameR   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR    ’   s    (   R   R   R   R   R    (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR:   ‹   s   	t   PathSpecFinderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s/   Finder based on importlib.machinery.PathFinder.c         C   s    t  j j j | d | ƒ} | rœ | j d k r9 | j n d  } | j d k rW t j n d  } t d | j	 d | d | j d | d t
 | j p g  ƒ ƒ } n  | S(   NR   R5   R
   R   R   R   R   (   t	   importlibt	   machineryt
   PathFindert	   find_specR   R   R   R9   R	   R
   R&   R   (   R   R   R   R   R   R!   R   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR        s    c         C   s   | j  t j k r | j Sd  S(   N(   R   R   R9   R   R   (   R   R!   R   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR"   «   s    (   R   R   R   R    R"   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyRB      s   	i   i   i   c         C   sŒ   y: t  t j j |  d ƒ d ƒ  } | j d ƒ } Wd  QXWn t k
 rM n; Xd | k oc d | k } d | k o{ d | k } | p‡ | Sd  S(   Ns   __init__.pyt   rbi   t   pkgutilt   extend_patht   pkg_resourcess   declare_namespace(__name__)(   t   openR.   R   R0   t   readt   IOError(   R   R*   t   dataRI   t   declare_namespace(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR-   º   s    !c         C   s   t  |  ƒ } | j | ƒ | S(   N(   t   sett   difference_update(   t   leftt   rightt   result(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   _cached_set_diffÈ   s    c         C   s   t  j } t |  p t  j ƒ } t | ƒ } t | | ƒ } x? | D]7 } y t j | ƒ | | <Wq@ t j k
 rv q@ q@ Xq@ W| S(   N(   R   t   path_importer_cachet   tupleR   RU   t	   zipimportt   zipimportert   ZipImportError(   R   t   pict	   req_pathst   cached_pathst	   new_pathst
   entry_path(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR<   Ï   s    	c         C   sè   xÈ t  | j ƒ  ƒ D]´ \ } } | d  k	 r | j |  d ƒ } | rÇ | j t j j j |  ƒ ƒ s‹ t d d j |  d ƒ | |  f ƒ ‚ n  t	 j
 t j j | ƒ t j j t j j j |  ƒ | f Sq q Wt d d j |  ƒ ƒ ‚ d  S(   Ni    s   No module named %s in %s/%sR3   i   s   No module named %s(   R&   t   itemsR   R    R.   R   t   sepR0   R(   R   t   PY_ZIPMODULEt   abspath(   t   modpathR[   t   filepatht   importert   found(    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyR?   â   s    #,c         C   s~   g  t  D] } | |  ƒ ^ q } x? | D]7 } | j | | | | ƒ } | d  k rV q& n  | | f SWt d d j | ƒ ƒ ‚ d  S(   Ns   No module named %sR3   (   t   _SPEC_FINDERSR    R   R(   R0   (   t   search_pathR   R   R   R   t   findert   findersR!   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   _find_spec_with_pathñ   s    c   	      C   s¼   | p t  j } |  }  d } |  } g  } xŒ |  r· |  j d ƒ } t | | | | | pY | ƒ \ } } | j | ƒ |  r | j | | ƒ } n  | j t j	 k r, | j
 d | ƒ } q, q, W| S(   s  Find a spec for the given module.

    :type modpath: list or tuple
    :param modpath:
      split module's name (i.e name of a module or package split
      on '.'), with leading empty strings for explicit relative import

    :type path: list or None
    :param path:
      optional list of path where the module or package should be
      searched (use sys.path if nothing or None is given)

    :rtype: ModuleSpec
    :return: A module spec, which describes how the module was
             found and where.
    i    R   N(   R   R   R   t   popRl   t   appendR"   R   R   t   PKG_DIRECTORYt   _replace(	   Rd   R   R   R   R   R   R   Rj   R!   (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyRF   ü   s     		(   i   i   (1   R#   t   collectionst   enumR'   R.   R   RX   t   importlib.machineryRC   t   Truet   _HAS_MACHINERYR(   t   Falset	   functoolsR    t   backports.functools_lru_cacheR4   R   t   EnumR   t	   C_BUILTINt   C_EXTENSIONRo   t   PY_COMPILEDt	   PY_FROZENt	   PY_SOURCER   t   hasattrR   R   R   t
   namedtupleR   R	   t   objectR   R%   R2   R:   RB   Rh   t   version_infoR-   RU   R   R<   R?   Rl   RF   (    (    (    s?   lib/python2.7/site-packages/astroid/interpreter/_import/spec.pyt   <module>   s\   

	!				