Spade
Mini Shell
| Directory:~$ /proc/self/root/usr/lib/python2.7/site-packages/past/translation/ |
| [Home] [System Details] [Kill Me] |
�
,�]c#@s�dZddlZddlZddlZddlZddlZddlZddlmZddl m
Z
ddlmZej
e�Zejej�eej�eej�eej�eej�Zdddd d
ddd
ddddddddddddddddddd
d!d"d#d$d%d&d'd(g#Zd)d7d*��YZd+�Zd,�Zd-�Zd.efd/��YZe�Zd8d9d0�Z
d1�Z!d2�Z"d3efd4��YZ#d5efd6��YZ$e Z%dS(:s'
past.translation
==================
The ``past.translation`` package provides an import hook for Python 3 which
transparently runs ``futurize`` fixers over Python 2 code on import to
convert
print statements into functions, etc.
It is intended to assist users in migrating to Python 3.x even if some
dependencies still only support Python 2.x.
Usage
-----
Once your Py2 package is installed in the usual module search path, the
import
hook is invoked as follows:
>>> from past.translation import autotranslate
>>> autotranslate('mypackagename')
Or:
>>> autotranslate(['mypackage1',
'mypackage2'])
You can unregister the hook using::
>>> from past.translation import remove_hooks
>>> remove_hooks()
Author: Ed Schofield.
Inspired by and based on ``uprefix`` by Vinay M. Sajip.
i����N(t
ParseError(tRefactoringTool(tfixesslib2to3.fixes.fix_applyslib2to3.fixes.fix_exceptslib2to3.fixes.fix_execfileslib2to3.fixes.fix_exitfuncslib2to3.fixes.fix_funcattrsslib2to3.fixes.fix_filterslib2to3.fixes.fix_has_keyslib2to3.fixes.fix_idiomsslib2to3.fixes.fix_importslib2to3.fixes.fix_internslib2to3.fixes.fix_isinstanceslib2to3.fixes.fix_methodattrsslib2to3.fixes.fix_neslib2to3.fixes.fix_numliteralsslib2to3.fixes.fix_parenslib2to3.fixes.fix_printslib2to3.fixes.fix_raiseslib2to3.fixes.fix_renamesslib2to3.fixes.fix_reduceslib2to3.fixes.fix_reprslib2to3.fixes.fix_standarderrorslib2to3.fixes.fix_sys_excslib2to3.fixes.fix_throwslib2to3.fixes.fix_tuple_paramsslib2to3.fixes.fix_typesslib2to3.fixes.fix_ws_commaslib2to3.fixes.fix_xreadlinesslib2to3.fixes.fix_basestringslib2to3.fixes.fix_execslib2to3.fixes.fix_getcwduslib2to3.fixes.fix_longslib2to3.fixes.fix_nextslib2to3.fixes.fix_nonzeroslib2to3.fixes.fix_raw_inputslib2to3.fixes.fix_xrangetRTscBsDeZdZdZdZdZdZed��Z ed��Z
RS(s&
A namespace for the refactoring tools. This avoids creating these at
the module level, which slows down the module import. (See issue #117).
There are two possible grammars: with or without the print statement.
Hence we have two possible refactoring tool implementations.
cCsGdtjtjgkrCtt�t_ttitd6�t_ndS(sj
Call this before using the refactoring tools to create them on
demand
if needed.
tprint_functionN(tNoneRt_rtt_rtpRtmyfixestTrue(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytsetup�scCsGdtjtjgkrCtt�t_ttitd6�t_ndS(sj
Call this before using the refactoring tools to create them on
demand
if needed.
RN(RRt_rt_py2_detectt_rtp_py2_detectRtpy2_detect_fixersR (((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytsetup_detect_python2�sN(t__name__t
__module__t__doc__RRRRRtstaticmethodR
R(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyRvscCs�g}x�tr�tjj|�}|d|krI|jd|d�Pq |d|krq|jd|d�Pq |d}|jd|d�q W|S(sA
Split a path into all components. From Python Cookbook.
ii(R tostpathtsplittinsert(Rtallpartstparts((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytsplitall�s
cCskg}t|�}t|�}x:t||�D])\}}||krJPn|j|�q.Wtjj|�S(s^
Returns the longest common substring to the two strings, starting from
the
left.
(RtziptappendRRtjoin(ts1ts2tchunkstpath1tpath2tdir1tdir2((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytcommon_substring�scCs�tj�ytjj||�}WnLtk
rq}|jdksS|jdkrY�ntjj||�}nX|t|�d kr�t j
dj|��tSt j
dj|��t
SdS(sD
Returns a bool indicating whether we think the code is Py2
s bad inputt=i����sDetected Python 2 code: {0}sDetected
Python 3 code:
{0}N(RRRtrefactor_stringRtmsgtvalueRtstrtloggertdebugtformatR tFalse(tsourcetpathnamettreete((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytdetect_python2�s
tPy2FixercBsMeZdZeZd�Zd�Zd�Zdd�Z d�Z
d�ZRS(si
An import hook class that uses lib2to3 for source-to-source translation
of
Py2 code to Py3.
cCs:d|_ddg|_tj|j�|_g|_dS(Ntfuturetpast(Rtfoundtbase_exclude_pathstcopyt
exclude_pathst
include_paths(tself((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt__init__�s cCs|j|7_dS(s�
Pass in a sequence of module names such as
'plotrique.plotting' that,
if present at the leftmost side of the full package name, would
specify the module to be transformed from Py2 to Py3.
N(R:(R;tpaths((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytinclude�scCs|j|7_dS(s�
Pass in a sequence of strings such as 'mymodule' that, if
present at the leftmost side of the full package name, would cause
the module not to undergo any source transformation.
N(R9(R;R=((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytexclude�scCsCtjdj|��d|kr||jdd�\}}|dkrs|j||�}|j|�}|j}n|}nytj||�|_ Wn:t
k
r�}tjd�tjdj||��dSX|j dd|_|jtjkrt
jj|j dd�|_n%|jtjkr?|j d|_n|S(NsRunning
find_module: {0}...t.isPy2Fixer could not find {0}sException was:
{0})i����s__init__.py(R*R+R,trsplitRtfind_moduletload_modulet__path__timpR6t Exceptiontkindt
PKG_DIRECTORYRRRR/t PY_SOURCE(R;tfullnameRtparenttchildtloadertmodR1((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyRBs(
"cCs�tj�|d7}ytjj||j�}WnOtk
r�}|jdks`|jdkrf�ntjj||j�}nXt |�d S(Ns
s bad inputR%i����(
RR
RR&R/RR'R(RR)(R;R.R0R1((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt transforms
c Bs�ejdj|��|ejkr5ej|}n�|jejejej ej
fkree}nneg|j
D]}|j|�^qr�r�e}n:eg|jD]}|j|�^q��r�e}ne}|sejdj|��ej||j�}n�ejdj|��ej|�}|ej|<|j|_||_||_|jejkr�ejj|j�g|_||_ng|_|jd�d|_y�ej|j�}ejj
|�s�e}n3ej!|j�j"}ej!|�j"}||k}|sle#|d��@} | j$�}
ye%j&|
�}Wne'k
rbe}nXWdQXn|r�|jdr�|jdj$�}n9|jejkr�e#|j��} | j$�}WdQXne(||j�r�|j)|�}ne*||jd�}ejj|�}
yZejj
|
�s>ej+|
�ne#|d��#} e%j,|�}
| j-|
�WdQXWq�e'k
r�q�Xn||j.fdUWn e'k
r�}ej|=�nX|jdr�|jdj/�n|S( NsRunning load_module
for {0}...sExcluded {0} from translationsAutoconverting {0}
...R@itrbtexectwb(0R*R+R,tsystmodulesRGREtPY_COMPILEDtC_EXTENSIONt C_BUILTINt PY_FROZENR-tanyR9t
startswithR:R RCR6t
new_moduleR/t__file__Rt
__loader__RHRRtdirnameRDt__package__t
rpartitiontcache_from_sourcetexistststattst_mtimetopentreadtmarshaltloadsRFR2ROtcompiletmakedirstdumpstwritet__dict__tclose(R;RJRNtconvertRt cachenametupdate_cachet
sourcetimet cachetimetftdatatcodeR.R^R1((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyRC1s� + +
N(RRRR tPY2FIXERR<R>R?RRBRORC(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyR3�s cCs�t|t�r|f}nt|t�r6|f}nt|�t|�dks^td��tj|�tj|�tjddk}|r�ttj kr�tj j
dt�ndS(NisPass at least one argumenti(t
isinstanceR)tlentAssertionErrort_hookR>R?RStversion_infot meta_pathR(R:R9tenable((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt
install_hooks�s(
cCs&ttjkr"tjjt�ndS(N(R{RSR}tremove(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytremove_hooks�scCs
ttjkS(sG
Returns True if the import hooks are installed, False if not.
(R{RSR}(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pytdetect_hooks�sthookscBs
eZdZd�Zd�ZRS(s�
Acts as a context manager. Use like this:
>>> from past import translation
>>> with translation.hooks():
... import mypy2module
>>> import requests # py2/3 compatible anyway
>>> # etc.
cCst�|_t�|S(N(R�thooks_were_installedR(R;((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt __enter__�scGs|jst�ndS(N(R�R�(R;targs((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt__exit__�s (RRRR�R�(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyR��s t
suspend_hookscBs
eZdZd�Zd�ZRS(sx
Acts as a context manager. Use like this:
>>> from past import translation
>>> translation.install_hooks()
>>> import http.client
>>> # ...
>>> with translation.suspend_hooks():
>>> import requests # or others that support Py2/3
If the hooks were disabled before the context, they are not installed
when
the context is left.
cCst�|_t�|S(N(R�R�R�(R;((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyR��scGs|jrt�ndS(N(R�R(R;R�((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyR��s (RRRR�R�(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyR��s
((((&RREtloggingRgRRSR8tlib2to3.pgen2.parseRtlib2to3.refactorRtlibfuturizeRt getLoggerRR*tsetLeveltDEBUGtlisttlibfuturize_fix_names_stage1tlib2to3_fix_names_stage1tlibfuturize_fix_names_stage2tlib2to3_fix_names_stage2RR
RRR$R2tobjectR3R{RR�R�R�R�t
autotranslate(((s=/usr/lib/python2.7/site-packages/past/translation/__init__.pyt<module>!sx& 5 �