Lf4ddlZddlZddlZddlmZmZddlmZddlm Z ejdejZ ejdejZ ejeZGddZy) N)joinsplit)execute)Versionz (?:\#!\s*){0,1} # shebang prefix (?P .*?/bin/.*?)? (?P python|pypy) (?P \d[\.\d]*)? (?P -dbg)? (?P.*) a- (?P.*?) (?:\. (?Pabi\d+) |(?:\. (?P (?Pcpython|pypy) - (?P\d{2}) (?P[a-z]*?) ) (?: -(?P[^/]*?) )? ))? (?P_d)? \.so$ceZdZdZdZdZdZdZdZiZ ddZ dZ dZ d Z d Zed Zdd Zdd ZddZddZddZddZddZddZddZddZddZy) InterpreterNpythonFcpythonct}|d=|d=t|tr+|jD]} ||  t || || <ne|rc|j ddj r|st||d<n2|j|jD]\} } ||  | || <|jD]\} } t|| | y)Nselfvalue.version) locals isinstancerkeysgetattrreplaceisdigitrparseitemssetattr) r rpathnamerdebugimploptionsparamskeyvals +/usr/share/python3/debpython/interpreter.py__init__zInterpreter.__init__Es 6N 7O e[ ){{}#;&")%"5F3K%}}S"%--/$+ENy! $ 5 1 7 7 9HCc{*&)s !: HC D#s #'cF|dk(rW|rU|jdrd|jd<n |jdrd|jd<d|vr"d|jd<n|d k(r | t|}|d vr |tt||j|<y||j|<y) Nrr r rpypyz-dbgTrr)rrrr) startswith__dict__rrr)r rrs r# __setattr__zInterpreter.__setattr__Zs 6>e)(1 f%!!&)(. f%)- g& Y 5#4ENE 7 7EM")+t">> sorted(Interpreter.parse('pypy').items()) [('debug', None), ('name', 'pypy'), ('options', ()), ('path', None), ('version', None)] >>> sorted(Interpreter.parse('/usr/bin/python3.3-dbg').items()) [('debug', '-dbg'), ('name', 'python'), ('options', ()), ('path', '/usr/bin/'), ('version', '3.3')] >>> sorted(Interpreter.parse('#! /usr/bin/pypy --foo').items()) [('debug', None), ('name', 'pypy'), ('options', ('--foo',)), ('path', '/usr/bin/'), ('version', None)] >>> 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')] r) SHEBANG_REsearch groupdicttupler)shebangr.s r#rzInterpreter.parse~sT ""7+I!!#   %fY&7&=&=&? @F9  r%ct|xs |j}|jdk(rd}n*|tdzrd|z}n|tdzrd|z}nd}|rd|z}|rd ||}|S) aReturn 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/' >>> Interpreter('pypy').sitedir(version='2.0') '/usr/lib/pypy/dist-packages/' r'z/usr/lib/pypy/dist-packages/2.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/)rrr)r gdbpackagerrs r#sitedirzInterpreter.sitedirsz&'1T\\2 99 1D  &5?D  &5?D4D %,D $+T2D r%c t|xs |j}d|jvrdnd}|tdkr||zSt|\}}|j ds|dz }t |d|ddd |j |d|S) aGiven 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.2') 'bar/__pycache__/foo.cpython-32.pyc' z-Ooc3.1z.py __pycache__Nr)rrrrendswithr magic_tag)r fpathr last_charfdirfnames r# cache_filezInterpreter.cache_files'1T\\24<</CS gen $9$ $El e~~e$ UNED-3BZ!8)*EF Fr%c\t|xs |j}|j|\}}|jddd}|r*|dj |z }|r|dj |z }|j r"|j dk(r|tdzr|dz }d j |S) z5Return extension name with soname and multiarch tags.rrz.{}z-{}r 3_dz{}.so)rr _get_configrr5rr)r rrsoabi multiarchr.s r#ext_filezInterpreter.ext_files'1T\\2++G4yC#A&  ell5) )F%,,y11 ::$))y0ws|+ dNF~~f%%r%ct|xs |j}|jdk(r|tdzry|jd|}t |S)zReturn magic number.r rQrz9import importlib.util; print(importlib.util.MAGIC_NUMBER))rrr_executeeval)r rr.s r# magic_numberzInterpreter.magic_numbersK'1T\\2 99 !g&=Z\cdF|r%ct|xs |j}|jdk(r|tdzry|jd|S)zReturn Python magic tag (used in __pycache__ dir to tag files). >>> i = Interpreter('python') >>> i.magic_tag(version='3.2') 'cpython-32' r 3.2rz/import sys; print(sys.implementation.cache_tag))rrrrXr6s r#rIzInterpreter.magic_tagsD'1T\\2 99 !g&?}}NPWXXr%ct|xs |j} |j|\}}|S#t$rtj ddYywxYw)zReturn multiarch tag.zcannot get multiarchTexc_inforrrrS Exceptionlogrr rrTrUs r#rUzInterpreter.multiarchs\'1T\\2 #//8 E9    II,tI < 1 AAct|xs |j}|jdk(r*|tdz rdj|jSyy)Nr r\zabi{})rrrr5majorr6s r# stableabizInterpreter.stableabisH'1T\\2 99 !g&?>>'--0 0'@ !r%ct|xs |j} |j|\}}|S#t$rtj ddYywxYw)zReturn SOABI flag (used to in .so files). >>> i = Interpreter('python') >>> i.soabi(version=Version('3.3')) 'cpython-33m' zcannot get soabiTr^rr`rcs r#rTzInterpreter.soabi s]'1T\\2 #//8 E9    II(4I 8 rdc t|xs |j}d|vr|jdd\}}nd}tj |}|sy|j }|dryt ||}|dr#dj|dd |dd|_|js|d s d |d xsdvrd |_ |j\}}|d}|jdk(r%|jdz r|jdr|dd}|ds|r9dj||dxs|}|ds|rdj||dxs|}|dz }||k(ryt||S#t$rtjdd YywxYw)aReturn extension file name if file can be renamed. >>> i = Interpreter('python') >>> i.check_extname('foo.so', version='3.3') # doctest: +ELLIPSIS 'foo.cpython-33m-....so' >>> i.check_extname('foo.abi3.so', version='3.3') >>> i.check_extname('foo/bar/bazmodule.so', version='3.3') # doctest: +ELLIPSIS 'foo/bar/baz.cpython-33m-....so' /rPrNrg)rverz{}.{}rrdflagsTzcannot get soabi/multiarchr^rr r\moduleirTrUz{}-{}z.so)rrrsplit EXTFILE_REr9r:rr5rrSrarbrrHr) r rMrrLinfoirTrUr.s r# check_extnamezInterpreter.check_extnames'1T\\2 %<,,sA.KD%D  ' ~~    g . ;tE{1~tE{1~FAIwwDMST']5Hb-IAG  }} E9f 66Y 199#5&//(:SCR[F =E^^FDM,BUCFK I [0A0NYO% F? D&!!  II2TI B  s=E FFc@t|xs |j}|jdk(s#|jdk(r|dz r|dzs |dz s|dk(rd}nd}|dz }|j||j d } t j d |d <|S#t$rY|SwxYw) Nr'r r>rQrEzimport sysconfig as s;z%from distutils import sysconfig as s;zOprint("__SEP__".join(i or "" for i in s.get_config_vars("SOABI", "MULTIARCH")))__SEP__DEB_HOST_MULTIARCHrP)rrrrXrosenvironKeyError)r rcmd conf_varss r#rSzInterpreter._get_configKs'1T\\2 99 $))y"85 W^e#w#~*C9C D DMM#w/55i@  ::&:;IaL   s8B BBct|xs |j}|j|d|f}|r1||jjvr|jj|St |}|ddk7r6t j|dtdj||d|dj}t|dk(r|d}|r||jj|<|S)Nz-c returncoderstderrz{} failed with status code {}stdoutrP) rrr- __class___cacherrbrrar5 splitlineslen)r commandrcacheoutputr.s r#rXzInterpreter._execute^s'1T\\2::g&g6 W 5 55>>((1 1! , 1 $ IIfX& ';BB7FS_L`ab b!,,. v;! AYF -3DNN ! !' * r%)NNNNNNN)FNNr1)NT)__name__ __module__ __qualname__rrrrrrrr$r*r/r2r- staticmethodrrArNrVrZrIrUrgrTrsrSrXr r%r#rr<s D DG E DG FAE04$*( (0$LF2 & Y 1 "/"b&r%r)loggingrwreos.pathrr debpythonrdebpython.versionrcompileVERBOSEr8rp getLoggerrrbrr r%r#rsw* % RZZ    RZZ jj! "g!uur%