Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/modutils.cpython-37.opt-1.pyc

B

��\\�@s dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddl
mZej�
d�rrd	Zd
ZndZdZy(ed
ejd�ed
ejd�ed
d�hZWne	k
r�e�ZYnXejdk�rDe�ej�ejd��ye�ej�ejd��WnHek
�rBye�ej�ejd��Wnek
�r<YnXYnXe��dk�r�ej�ejd�Ze�e�ye�ej�ejd��Wnek
�r�YnX[ejdk�ry
ejZWnek
�r�ejZYnXdd�Ze�ed��ejdk�re�ed��e�Ze��dkZ e!�"ej#d
�Z$Gdd�de%�Z&dd�Z'dd �Z(e fd!d"�Z)d#d$�Z*iZ+d%d&�Z,dPd'd(�Z-dQd)d*�Z.dRd+d,�Z/d-d.�Z0d/d0�Z1dSd1d2�Z2dTd3d4�Z3dUd5d6�Z4dVd7d8�Z5dWd9d:�Z6dXd<d=�Z7dYd>d?�Z8d@dA�Z9dZdBdC�Z:dDdE�Z;d[dFdG�Z<dHdI�Z=dJdK�Z>dLdM�Z?dNdO�Z@dS)\aVPython modules manipulation utility functions.

:type PY_SOURCE_EXTS: tuple(str)
:var PY_SOURCE_EXTS: list of possible python source file extension

:type STD_LIB_DIRS: set of str
:var STD_LIB_DIRS: directories where standard modules are located

:type BUILTIN_MODULES: dict
:var BUILTIN_MODULES: dictionary with builtin module names has key
�N)�get_python_lib)�DistutilsPlatformError�)�spec)�util�win)�pyZpyw)ZdllZpyd)r)ZsoT)�standard_lib�prefix)r	�ntZdllsZPyPyZlib_pypy�posixcCs"dtjdd�}tj�t||�S)Nzpython%d.%d�)�sys�version_info�os�path�joinr
)rZbase_python�r�A/opt/alt/python37/lib/python3.7/site-packages/astroid/modutils.py�_posix_pathhsr�libl�lib64ZJythonc@seZdZdZdS)�NoSourceFilezaexception raised when we are not able to get a python
    source file for a precompiled file
    N)�__name__�
__module__�__qualname__�__doc__rrrrr|srcCstj�tj�|��S)N)rr�normcase�abspath)rrrr�_normalize_path�srcCstj�tj�|��S)N)rr�realpath�
expanduser)rrrr�_canonicalize_path�sr"cCsL|s,tjdkr|S|�d�r(|dd�S|S|�d�\}}}|rH|dS|S)N)�rz.pyc���z	$py.classz.py)rr�endswith�	partition)�filenameZ	is_jython�headZhas_pyclass�_rrr�_path_from_filename�s

r*cCs8x2|D]*}||kr|�|�q||kr|�|�qWdS)z`remove files/directories in the black list

    dirnames/filenames are usually from os.walk
    N)�remove)�	blacklist�dirnames�	filenamesZnorecursrrr�_handle_blacklist�s

r/cCs>yt|Stk
r8|s$t|�St|�}t|<|SXdS)zabspath with cachingN)�_NORM_PATH_CACHE�KeyErrorr)r�resultrrr�_cache_normalize_path�sr3cCst|�d�||�S)a"Load a Python module from its name.

    :type dotted_name: str
    :param dotted_name: python name of a module or package

    :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)

    :type use_sys: bool
    :param use_sys:
      boolean indicating whether the sys.modules dictionary should be
      used or not


    :raise ImportError: if the module or package is not found

    :rtype: module
    :return: the loaded module
    �.)�load_module_from_modpath�split)�dotted_namer�use_sysrrr�load_module_from_name�sr9cCs4|r*ytjd�|�Stk
r(YnXg}d}x�|D]�}|�|�d�|�}d}t|�t|�krrtj�|�}n|r�tj�|�}|dkr�t�||�\}}	}
t�	|||	|
�}|r�|�
�|r�t|||�t|dd�}|}|s�t
�|�r�q8|�st|�t|�k�rtdd�|t|�d����tj�|�g}q8W|S)a<Load a python module from its split name.

    :type parts: list(str) or tuple(str)
    :param parts:
      python name of a module or package split on '.'

    :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)

    :type use_sys: bool
    :param use_sys:
      boolean indicating whether the sys.modules dictionary should be used or not

    :raise ImportError: if the module or package is not found

    :rtype: module
    :return: the loaded module
    r4N�__file__�zno module in %s)r�modulesrr1�append�len�get�imp�find_module�load_module�close�setattr�getattrr�is_namespace�ImportErrorrr�dirname)�partsrr8�modpathZ
prevmodule�partZcurname�moduleZmp_fileZmp_filenameZmp_descZ_filerrrr5�s<


r5cCst||�}t|||�S)aLoad a Python module from it's path.

    :type filepath: str
    :param filepath: path to the python module or package

    :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)

    :type use_sys: bool
    :param use_sys:
      boolean indicating whether the sys.modules dictionary should be
      used or not


    :raise ImportError: if the module or package is not found

    :rtype: module
    :return: the loaded module
    )�modpath_from_filer5)�filepathrr8�	extrapathrJrrr�load_module_from_files
rPcCsNg}xD|D]<}|�|�tj�||�}t|�s
t�d�|��}|s
dSq
WdS)z2check there are some __init__.py all along the wayr4FT)r=rrr�	_has_initrrF)rZmod_pathrJrKZ
old_namespacerrr�check_modpath_has_inits

rRcCs�d}tj�|�}tj�|�}tj�|��|�r2|}tj�|�}tj�|��|�rT|}|r�tj�|�d}|t|�d�}dd�|�tj	�D�SdS)a=Extracts the relative mod path of the file to import from

    Check if a file is within the passed in path and if so, returns the
    relative mod path from the one passed in.

    If the filename is no in path_to_check, returns None

    Note this function will look for both abs and realpath of the file,
    this allows to find the relative base path even if the file is a
    symlink of a file in the passed in path

    Examples:
        _get_relative_base_path("/a/b/c/d.py", "/a/b") ->  ["c","d"]
        _get_relative_base_path("/a/b/c/d.py", "/dev") ->  None
    NrcSsg|]}|r|�qSrr)�.0Zpkgrrr�
<listcomp>Isz+_get_relative_base_path.<locals>.<listcomp>)
rrrr�
startswithr �splitextr>r6�sep)r'Z
path_to_checkZimportable_pathZabs_filenameZ
real_filename�	base_pathZrelative_base_pathrrr�_get_relative_base_path,srYcCs�tj�t|��}|dk	rzx`t�tt|�|�D]J}tj�|�}|sBq,t	||�}|sRq,|||dd��r,||�
d�|Sq,WxRt�tttj�tj�D]8}t|�}|s�q�t	||�}|s�q�|||dd��r�|Sq�Wt
d|d�tj�f��dS)Nr$r4z"Unable to find module for %s in %sz, 
)rrr!r*�	itertools�chain�mapr"rrYr6rr3rGr)r'rOZ
is_package_cbZpath_rZ
submodpathrJrrr�modpath_from_file_with_callbackNs,

r]cCst||t�S)aigiven a file path return the corresponding split module's name
    (i.e name of a module or package split on '.')

    :type filename: str
    :param filename: file's path for which we want the module's name

    :type extrapath: dict
    :param extrapath:
      optional extra search path, with path as key and package name for the path
      as value. This is usually useful to handle package split in multiple
      directories using __path__ trick.


    :raise ImportError:
      if the corresponding module's name has not been found

    :rtype: list(str)
    :return: the corresponding split module's name
    )r]rR)r'rOrrrrMksrMcCst|||�jS)N)�file_info_from_modpath�location)rJr�context_filerrr�file_from_modpath�sracCs�|dk	rtj�|�}n|}|ddkr`ytdg|dd�||�Stk
r\t|||�SXn"|ddgkr�tjdtjjtj	d	�St|||�S)
a�given a mod path (i.e. split module / package name), return the
    corresponding file, giving priority to source file over precompiled
    file if it exists

    :type modpath: list or tuple
    :param modpath:
      split module's name (i.e name of a module or package split
      on '.')
      (this means explicit relative imports that start with dots have
      empty strings in this list!)

    :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)

    :type context_file: str or None
    :param context_file:
      context file to consider, necessary if the identifier has been
      introduced using a relative import unresolvable in the actual
      context (i.e. modutils)

    :raise ImportError: if there is no such module in the directory

    :rtype: (str or None, import type)
    :return:
      the path to the module's file or None if it's an integrated
      builtin module such as 'sys'
    NrZxmlZ_xmlplusrrrzos.path)�namer_�module_type)
rrrH�_spec_from_modpathrGr�
ModuleSpecr:r@�	PY_SOURCE)rJrr`�contextrrrr^�sr^c	Cs|�d�rdS|�d�}|dk	rH|dtkrHt|�dkr@t|��|dSd}d}|ddkrt|dk	sltd��g}d}x$||dkr�|d7}tj�|�}qvWxrt	|t|��D]`}yt
|||d�||d	�Wq�tk
�r|tdt|�d�kr��d�|d|��SXq�W|S)
agiven a dotted name return the module part of the name :

    >>> get_module_part('astroid.as_string.dump')
    'astroid.as_string'

    :type dotted_name: str
    :param dotted_name: full name of the identifier we are interested in

    :type context_file: str or None
    :param context_file:
      context file to consider, necessary if the identifier has been
      introduced using a relative import unresolvable in the actual
      context (i.e. modutils)


    :raise ImportError: if there is no such module in the directory

    :rtype: str or None
    :return:
      the module part of the name or None if we have not been able at
      all to import the given name

    XXX: deprecated, since it doesn't handle package precedence over module
    (see #10066)
    zos.pathr4Nrr
r;z.explicit relative import, but no context_file?r)rr`)
rUr6�BUILTIN_MODULESr>rG�AssertionErrorrrrH�rangera�maxr)r7r`rIrZstarti�irrr�get_module_part�s6


rmFc	Cs�g}xvt�|�D]h\}}}||kr$qt|||�|sJd|krJd|dd�<qx,|D]$}t|�rPtj�||�}|�|�qPWqW|S)aNgiven a package directory return a list of all available python
    module's files in the package and its subpackages

    :type src_directory: str
    :param src_directory:
      path of the directory corresponding to the package

    :type blacklist: list or tuple
    :param blacklist: iterable
      list of files or directories to ignore.

    :type list_all: bool
    :param list_all:
        get files from all paths, including ones without __init__.py

    :rtype: list
    :return:
      the list of all available python module's files in the package and
      its subpackages
    z__init__.pyrN)r�walkr/�_is_python_filerrr=)	Z
src_directoryr,Zlist_all�files�	directoryr-r.r'�srcrrr�get_module_files�s
rscCsntj�t|��}tj�|�\}}x(tD] }d||f}tj�|�r&|Sq&W|rb|sbtj�|�rb|St|��dS)a�given a python module's file name return the matching source file
    name (the filename will be returned identically if it's already an
    absolute path to a python source file...)

    :type filename: str
    :param filename: python module's file name


    :raise NoSourceFile: if no source file exists on the file system

    :rtype: str
    :return: the absolute path of the source file if it exists
    z%s.%sN)rrrr*rV�PY_SOURCE_EXTS�existsr)r'Zinclude_no_ext�baseZorig_ext�ext�source_pathrrr�get_source_files
rycCstj�|�ddd�tkS)zN
    rtype: bool
    return: True if the filename is a python source file
    rN)rrrVrt)r'rrr�is_python_source1srzcCs�|�d�d}yt|g�}Wntk
r0dSX|dkrFt�|�St|�}|�tt��r`dS|dkrlt	}x|D]}|�t|��rrdSqrWdS)a�try to guess if a module is a standard python module (by default,
    see `std_path` parameter's description)

    :type modname: str
    :param modname: name of the module we are interested in

    :type std_path: list(str) or tuple(str)
    :param std_path: list of path considered has standard


    :rtype: bool
    :return:
      true if the module:
      - is located on the path listed in one of the directory in `std_path`
      - is a built-in module
    r4rFNT)
r6rarGrrFrrUr3�EXT_LIB_DIR�STD_LIB_DIRS)�modnameZstd_pathr'rrrr�is_standard_module9s 
r~cCsntj�|�stj�|�}|tjkr&dSy.t�|�d�d|g�\}}}|rR|��dSt	k
rhdSXdS)avreturn true if the given module name is relative to the given
    file name

    :type modname: str
    :param modname: name of the module we are interested in

    :type from_file: str
    :param from_file:
      path of the module from which modname has been imported

    :rtype: bool
    :return:
      true if the module has been imported relatively to `from_file`
    Fr4rTN)
rr�isdirrHrr@rAr6rCrG)r}Z	from_file�streamr)rrr�is_relativeas
r�cCs�|st�d}|dk	rVyt�||g�}|j}Wqbtk
rRt�||�}|j}YqbXnt�||�}|jtjjkr�yt|j�}|j	|tjj
d�Stk
r�|j	|d�SXnD|jtjjkr�|j	dd�S|jtjj
kr�t|j�}|j	|tjj
d�S|S)z�given a mod path (i.e. split module / package name), return the
    corresponding spec

    this function is used internally, see `file_from_modpath`'s
    documentation for more information
    N)r_�type)r_)rir�	find_specr_rGr��
ModuleTypeZPY_COMPILEDry�_replacerfrZ	C_BUILTIN�
PKG_DIRECTORYrQ)rJrrgr_Z
found_specrrrrd�s.


rdcCs xdD]}|�|�rdSqWdS)zkreturn true if the given filename should be considered as a python file

    .pyc and .pyo are ignored
    )z.pyz.soz.pydz.pywTF)r%)r'rwrrrro�s

rocCsDtj�|d�}x0tdD]$}tj�|d|�r|d|SqWdS)z\if the given directory has a valid __init__ file, return its path,
    else return None
    �__init__)ZpycZpyor4N)rrrrtru)rqZmod_or_packrwrrrrQ�s
rQcCs|jtjjkS)N)r�rr�ZPY_NAMESPACE)�specobjrrrrF�srFcCs|jtjjkS)N)r�rr�r�)r�rrr�is_directory�sr�)NT)Nr)NTN)NN)N)NN)NN)N)F)F)N)NN)Arr@r�platformrrZ�distutils.sysconfigr�distutils.errorsrZinterpreter._importrrrUrtZPY_COMPILED_EXTSr
�exec_prefixr|�setrb�addrrZreal_prefix�AttributeError�base_exec_prefixZpython_implementationZ_rootr�maxsizer{Z	IS_JYTHON�dict�fromkeys�builtin_module_namesrh�	Exceptionrrr"r*r/r0r3r9r5rPrRrYr]rMrar^rmrsryrzr~r�rdrorQrFr�rrrr�<module>s�




8

"



0
=
%

(!
#