%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/share/dh-python/dhpython/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/share/dh-python/dhpython/__pycache__/interpreter.cpython-35.pyc



�U]�N�@s�ddlZddlZddlZddlmZmZddlmZmZm	Z	ej
dej�Zej
dej�Z
ejd�ZGdd�d�Zdd	lmZdd
lmZmZdS)�N)�join�split)�INTERPRETER_DIR_TPLS�
PUBLIC_DIR_RE�
OLD_SITE_DIRSz�
    (?:\#!\s*){0,1}  # shebang prefix
    (?P<path>
        .*?/bin/.*?)?
    (?P<name>
        python|pypy)
    (?P<version>
        \d[\.\d]*)?
    (?P<debug>
        -dbg)?
    (?P<options>.*)
    am
    (?P<name>.*?)
    (?:\.
        (?P<stableabi>abi\d+)
     |(?:\.
        (?P<soabi>
            (?P<impl>cpython|pypy)
            -
            (?P<ver>\d{2})
            (?P<flags>[a-z]*)
        )?
        (?:
            (?:(?<!\.)-)?  # minus sign only if soabi is defined
            (?P<multiarch>[^/]*?)
        )?
    ))?
    (?P<debug>_d)?
    \.so$�dhpythonc	@s�eZdZdZdZdZdZdZdZfZ	iZ
ddddddddd�Zd	d
�Zdd�Z
d
d�Zdddd�Zddd�Zedd��Zedd��Zedd��Zedd��Zddddd�Zddddd�Zdd �Zd!d"�Zdd#d$�Zdd%d&�Zdd'd(�Zdd)d*�Zdd+d,�Z dd-d.�Z!ed/d0��Z"ed1d2��Z#dd3d4�Z$d5d6�Z%dd7d8�Z&dd9d:d;�Z'dS)<�Interpretera�
    :attr path: /usr/bin/ in most cases
    :attr name: pypy or python (even for python3 and python-dbg) or empty string
    :attr version: interpreter's version
    :attr debug: -dbg version of the interpreter
    :attr impl: implementation (cpytho2, cpython3 or pypy)
    :attr options: options parsed from shebang
    :type path: str
    :type name: str
    :type version: Version or None
    :type debug: bool
    :type impl: str
    :type options: tuple
    z	/usr/bin/�pythonNF�cCs7t�}|d=|d=t|t�rcx�|j�D])}	||	dkr3t||	�||	<q3Wnx|r�|jdd�j�r�|r�t|�|d<n@x=|j|�j	�D]&\}	}
||	dkr�|
||	<q�WxU|j	�D]G\}	}
|
dk	rt
||	|
�q�|	dkr�t
||	|
�q�WdS)N�self�value�.r
�version)�locals�
isinstancer�keys�getattr�replace�isdigit�Version�parse�items�setattr)rr�path�namer�debug�impl�optionsZparams�key�val�r �,/usr/share/dh-python/dhpython/interpreter.py�__init__Ss$	"zInterpreter.__init__cCs:|dkr�|dkr(td|��|dkro|jr�|jjdkr_d|jd<q�d	|jd<q�|dkr�d|jd<na|d
kr�|dk	r�t|�}|jr�|jdkr�|jdkr�d|_n	d	|_|dkr|dkrn/|d
kr)t|�|j|<n
||j|<dS)Nrr	�pypyr
zinterpreter not supported: %s��cpython3r�cpython2rrrr)zpythonr#r
)zpathznamezimplzoptions)�
ValueErrorr�major�__dict__rrr�bool)rrrr r r!�__setattr__ns*		zInterpreter.__setattr__cCs_|j}|jd�s"|d7}||j|j�7}|jr[|ddj|j�7}|S)N�/� )r�endswith�_vstrrrr)r�resultr r r!�__repr__�s	
	zInterpreter.__repr__cCs|j|j�S)N)r/r)rr r r!�__str__�szInterpreter.__str__cCs�|jdkr|jS|p(|jp(d}|re|sG||jkre|jdkr\dnd}n*t|t�r�|tdd�kr�d}|jr�dj|�S|jt|�S)Nr#r
r%�3r(�zpython{}-dbg)	rrr�default_versionrrr�format�str)rr�consider_default_verr r r!r/�s$	
zInterpreter._vstrcCsdj|j|j|��S)Nz{}{})r6rr/)rrr r r!�binary�szInterpreter.binarycCsdj|j|jdd��S)z�Like binary(), but returns path to default intepreter symlink
        if version matches default one for given implementation.
        z{}{}r8T)r6rr/)rr r r!�	binary_dv�szInterpreter.binary_dvcCs|jrt|j�SdS)N)r�default)rr r r!r5�s	zInterpreter.default_versioncCsytj|�}|siS|j�}d|krKt|dj��|d<|ddkru|ddkrud|d<|S)a^Return dict with parsed shebang

        >>> sorted(Interpreter.parse('/usr/bin/python3.2-dbg').items())
        [('debug', '-dbg'), ('name', 'python'), ('options', ()), ('path', '/usr/bin/'), ('version', '3.2')]
        >>> sorted(Interpreter.parse('#! /usr/bin/python3.2').items())
        [('debug', None), ('name', 'python'), ('options', ()), ('path', '/usr/bin/'), ('version', '3.2')]
        >>> sorted(Interpreter.parse('/usr/bin/python3.2-dbg --foo --bar').items())
        [('debug', '-dbg'), ('name', 'python'), ('options', ('--foo', '--bar')), ('path', '/usr/bin/'), ('version', '3.2')]
        rrr	rN�2)�
SHEBANG_RE�search�	groupdict�tupler)Zshebangr0r r r!r�s 
zInterpreter.parsecCs�t�}t|d��.}|jd�}d|krBtd��WdQRXt|d�jd�d}|jd	�s�td
|��|j|�}|s�td
|��x*|j�D]\}}t	|||�q�W|S)z!Read file's shebang and parse it.�rb�`szcannot parse binary fileNzutf-8�
rz#!zdoesn't look like a shebang: %s)
r�open�readr'r7r�
startswithrrr)�cls�fpathZinterpreter�fp�dataZparsedrrr r r!�	from_file�s	zInterpreter.from_filecCs�yt|p|j�}Wn5tk
rP}ztd|��WYdd}~XnX|jdkrid}n@|td�>r�d|}n#|td�>r�d|}nd	}|r�d
|}|r�d||f}|S)a�Return path to site-packages directory.

        Note that returned path is not the final location of .py files

        >>> i = Interpreter('python')
        >>> i.sitedir(version='3.1')
        '/usr/lib/python3/dist-packages/'
        >>> i.sitedir(version='2.5')
        '/usr/lib/python2.5/site-packages/'
        >>> i.sitedir(version=Version('2.7'))
        '/usr/lib/python2.7/dist-packages/'
        >>> i.sitedir(version='3.1', gdb=True, package='python3-foo')
        'debian/python3-foo/usr/lib/debug/usr/lib/python3/dist-packages/'
        >>> i.sitedir(version=Version('3.2'))
        '/usr/lib/python3/dist-packages/'
        zcannot find valid version: %sNr#z/usr/lib/pypy/dist-packages/z2.6z /usr/lib/python%s/site-packages/z3.0z /usr/lib/python%s/dist-packages/z/usr/lib/python3/dist-packages/z/usr/lib/debug%szdebian/%s%s)rr�	Exceptionr'r)r�packager�gdb�errrr r r!�sitedir�s #	


zInterpreter.sitedircs(yt|p|j�}Wn5tk
rP}ztd|��WYdd}~XnXg}xjtj|jg�D]S}t|t�r�|j	|j
|��qm||�}|dk	rm|j	|�qmW|rdd�|D�}|jjd�r|j	dj
|���r$�fdd�|D�}|S)z5Return deprecated paths to site-packages directories.zcannot find valid version: %sNcSsg|]}dj|��qS)z/usr/lib/debug{})r6)�.0�ir r r!�
<listcomp>s	z,Interpreter.old_sitedirs.<locals>.<listcomp>�cpythonz(/usr/lib/debug/usr/lib/pyshared/python{}cs"g|]}dj�|��qS)zdebian/{}{})r6)rQrR)rMr r!rSs	)rrrLr'r�getrrr7�appendr6rF)rrMrrNrOr0�item�resr )rMr!�old_sitedirss$#zInterpreter.old_sitedirscCsMt|jj|�}|rI|jd�}|rE|drEt|�SdSdS)z]Return version assigned to site-packages path
        or True is it's unversioned public dir.rTN)rr�match�groupsr)rrrZZversr r r!�parse_public_dirs
zInterpreter.parse_public_dircs�dj�j�}|�jjkr{�fdd�tj�D�}tjdjdd�|D���}|�jj|<n�jj|}|j	|�S)zBReturn True if path is used by another interpreter implementation.zshould_ignore_{}cs+g|]!\}}|�jkr|�qSr )r)rQ�k�v)rr r!rS&s	z-Interpreter.should_ignore.<locals>.<listcomp>�|css|]}dj|�VqdS)z({})N)r6)rQrRr r r!�	<genexpr>'sz,Interpreter.should_ignore.<locals>.<genexpr>)
r6r�	__class__�_cacherr�re�compilerr>)rrZ	cache_key�exprZregexpr )rr!�
should_ignore"s%zInterpreter.should_ignorecCs�t|p|j�}d|jkr*dnd}|td�krJ||St|�\}}|jd�su|d7}t|dd|dd
�|j|�|f�S)a�Given path to a .py file, return path to its .pyc/.pyo file.

        This function is inspired by Python 3.2's imp.cache_from_source.

        :param fpath: path to file name
        :param version: Python version

        >>> i = Interpreter('python')
        >>> i.cache_file('foo.py', Version('3.1'))
        'foo.pyc'
        >>> i.cache_file('bar/foo.py', '3.4')
        'bar/__pycache__/foo.cpython-34.pyc'
        z-O�o�cz3.1z.py�__pycache__z
%s.%s.py%sNr$���)rrrrr.r�	magic_tag)rrHrZ	last_char�fdir�fnamer r r!�
cache_file-s
zInterpreter.cache_filecCsDt|p|j�}|jdkr(dS|jd|�}t|�S)zReturn magic number.r&r
z"import imp; print(imp.get_magic()))rrr�_execute�eval)rrr0r r r!�magic_numberFs
zInterpreter.magic_numbercCsKt|p|j�}|jjd�r;|td�>r;dS|jd|�S)z�Return Python magic tag (used in __pycache__ dir to tag files).

        >>> i = Interpreter('python')
        >>> i.magic_tag(version='3.4')
        'cpython-34'
        rTz3.2r
z import imp; print(imp.get_tag()))rrrrFro)rrr r r!rkNs"zInterpreter.magic_tagcCsht|p|j�}y#|j|�dd�\}}Wn)tk
rctjddd�dSYnX|S)zReturn multiarch tag.Nr4zcannot get multiarch�exc_infoTr
)rr�_get_configrL�logr)rr�soabi�	multiarchr r r!rvZs#
	zInterpreter.multiarchcCsHt|p|j�}|jdkrD|td�?rDdj|j�SdS)Nr%z3.2zabi{})rrrr6r()rrr r r!�	stableabieszInterpreter.stableabicCsht|p|j�}y#|j|�dd�\}}Wn)tk
rctjddd�dSYnX|S)z)Return SOABI flag (used to in .so files).Nr4zcannot get soabirrTr
)rrrsrLrtr)rrrurvr r r!ruks#
	zInterpreter.soabicCs�|jdkrdSy|j�d}|r0|SWn+tk
r^d}tjddd�YnXdj|j�}|j}|jr�|d	>r�|d
7}q�|d7}n-|d?r�|d
7}n|dkr�|d7}|S)z�Return INCLUDE_DIR path.

        >>> Interpreter('python2.7').include_dir
        '/usr/include/python2.7'
        >>> Interpreter('python3.4-dbg').include_dir
        '/usr/include/python3.4dm'
        r#z/usr/lib/pypy/includer4r
zcannot get include pathrrTz/usr/include/{}z3.3�_dZdmz3.2�mZmu)rrsrLrtrr6rr)rr0rr r r!�include_dirws(	
		





zInterpreter.include_dircCs�|jdkrdS|j�dd�\}}|jd�rP|jdd�}|ri|rit||�Stdj|���dS)	zReturn libfoo.so file path.r#r
r$�z.az.sozcannot find library file for {}N)rrsr.rrrLr6)rZlibplZ	ldlibraryr r r!�library_file�s
zInterpreter.library_filec
Cs�|r|jrdSt|p$|j�}d|krQ|jdd�\}}nd}tj|�}|spdS|j�}|dr�|s�|jdkr�td|dd|ddf�}|dr�dS|d	r�|jd
kr�dS|dr|drdSy#|j|�dd
�\}}Wn)t	k
rSt
jddd�dSYnX|drx|rx|d|krxdS|dp�|}|dp�|}|d}	|	jd�r�|jdkr�|d?s�|jdkr�|dkr�|	dd�}	|rNdj
|	|�}	|r�|jdko)|d>r�||kr�dj
|	|�}	n3|jdkr�|dkr�|r�dj
|	|�}	|jr�|jdkr�|	d7}	|	d7}	||	kr�dSt||	�S)z2Return extension file name if file can be renamed.Nr,�r
Zverz%s.%srrwrFrurvr4zcannot get soabi/multiarchrrTr�moduler%z3.2r&z2.7�z{}.{}z3.3z{}-{}rxz.soi����)rr�rsplit�
EXTFILE_REr>r?�minorrrsrLrtr.rr6r)
rrmrrl�inforurvZ	tmp_soabiZ
tmp_multiarchr0r r r!�
check_extname�sV &
#
	 
(,!

zInterpreter.check_extnamecCs`|jdkrdj|�S|jdkr1dnd}dj||�}|jr\|d7}|S)aASuggest binary package name with for given library name

        >>> Interpreter('python3.1').suggest_pkg_name('foo')
        'python3-foo'
        >>> Interpreter('python3.4').suggest_pkg_name('foo')
        'python3-foo'
        >>> Interpreter('python2.7-dbg').suggest_pkg_name('bar')
        'python-bar-dbg'
        r#zpypy-{}r%r3r
zpython{}-{}z-dbg)rr6r)rrrr0r r r!�suggest_pkg_name�s

	
zInterpreter.suggest_pkg_namecCs�t|p|j�}|jdks`|jjd�ri|d?rJ|d>s`|d?s`|dkrid}nd}|d7}|j||�jd	�}|d
|dkr�|djd|d
d
�|d<ytjd|d
<Wnt	k
r�YnX|S)Nr#rTz2.6r3z3.1zimport sysconfig as s;z%from distutils import sysconfig as s;zrprint("__SEP__".join(i or "" for i in s.get_config_vars("SOABI", "MULTIARCH", "INCLUDEPY", "LIBPL", "LDLIBRARY")))Z__SEP__r}rz-%sr
ZDEB_HOST_MULTIARCH)
rrrrFrorr�os�environ�KeyError)rr�cmdZ	conf_varsr r r!rs�s!	
"
zInterpreter._get_configTcCs�t|p|j�}dj|j|�|jdd��}|rb||jjkrb|jj|St|�}|ddkr�tj	|d�t
dj||d���|dj�}t|�dkr�|d}|r�||jj|<|S)	Nz
{} -c '{}'�'�
returncoder�stderrz{} failed with status code {}�stdoutr})
rrr6r/rrarb�executertrrL�
splitlines�len)rZcommandr�cache�outputr0r r r!ros'
zInterpreter._execute)(�__name__�
__module__�__qualname__�__doc__rrrrrrrbr"r+r1r2r/r9�propertyr:r5�staticmethodr�classmethodrKrPrYr\rfrnrqrkrvrwrurzr|r�r�rsror r r r!r<sF	
%
 
?r)r�)rr;)Zloggingr�rc�os.pathrrrrrrrd�VERBOSEr=r�Z	getLoggerrtrZdhpython.toolsr�Zdhpython.versionrr;r r r r!�<module>s��

Zerion Mini Shell 1.0