%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/past/translation/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyc

�
�A�[c#@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZej
e�Zejej�eej�eej�eej�eej�Zdddd	d
ddd
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$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 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(((sJ/opt/alt/python27/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	(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytsetup_detect_python2�sN(t__name__t
__module__t__doc__RRRRRtstaticmethodR
R(((sJ/opt/alt/python27/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((sJ/opt/alt/python27/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((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytcommon_substring�sc
Cs|tj�ytjj||�}WnLtk
rq}|jdksS|jdkrY�ntjj||�}nX|t|�d kr
t	j
dj|��tdd��}|j
d||f�WdQXtd	d��(}|j
d
|t|�d f�WdQXtSt	j
dj|��tdd��}|j
d||f�WdQXytjd
�Wntk
rsnXtSdS(sD
    Returns a bool indicating whether we think the code is Py2
    s	bad inputt=i����sDetected Python 2 code: {0}s/tmp/original_code.pytws*### Original code (detected as py2): %s
%sNs/tmp/py2_detection_code.pys1### Code after running py3 detection (from %s)
%ssDetected Python 3 code: {0}s*### Original code (detected as py3): %s
%ss/tmp/futurize_code.py(RRRtrefactor_stringRtmsgtvalueRtstrtloggertdebugtformattopentwriteR	RtremovetOSErrortFalse(tsourcetpathnamettreetetf((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytdetect_python2�s2
			
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((sJ/opt/alt/python27/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@(RAtpaths((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytincludescCs|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(R?(RARC((sJ/opt/alt/python27/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|_|jtjkrt
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__timpR<t	Exceptiontkindt
PKG_DIRECTORYRRRR4t	PY_SOURCE(RAtfullnameRtparenttchildtloadertmodR6((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyRHs(	
"cCs�tj�|d7}ytjj||j�}WnOtk
r�}|jdks`|jdkrf�ntjj||j�}nXt	|�d S(Ns
s	bad inputR%i����(
RR
RR'R4RR(R)RR*(RAR3R5R6((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyt	transform,s

c
Bsejdj|��|ejkr5ej|}n�|jejejej	ej
fkree}nneg|j
D]}|j|�^qr�r�e}n:eg|jD]}|j|�^q��r�e}ne}|sejdj|��ej||j�}n�ejdj|��ej|�}|ej|<|j|_||_||_|jejkr�ejj|j�g|_||_ng|_|jd�d|_yej|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)|�}e#dd��!}	|	j*d	|j|f�WdQXne+||jd
�}ejj|�}
yZejj |
�spej,|
�ne#|d��#}	e%j-|�}
|	j*|
�WdQXWq�e'k
r�q�Xn||j.UWn e'k
r�}ej|=�nX|jdr|jdj/�n|S(NsRunning load_module for {0}...sExcluded {0} from translationsAutoconverting {0} ...RFitrbs/tmp/futurized_code.pyR&s### Futurized code (from %s)
%stexectwb(0R+R,R-tsystmodulesRMRKtPY_COMPILEDtC_EXTENSIONt	C_BUILTINt	PY_FROZENR2tanyR?t
startswithR@R	RIR<t
new_moduleR4t__file__Rt
__loader__RNRRtdirnameRJt__package__t
rpartitiontcache_from_sourcetexistststattst_mtimeR.treadtmarshaltloadsRLR8RUR/tcompiletmakedirstdumpst__dict__tclose(RARPRTtconvertRt	cachenametupdate_cachet
sourcetimet	cachetimeR7tdatatcodeR3RdR6((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyRI>s�	+	+	
		
		

	


N(RRRR	tPY2FIXERRBRDRERRHRURI(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyR9�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_hookRDRERYtversion_infot	meta_pathR(R@R?tenable((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyt
install_hooks�s(

cCs&ttjkr"tjjt�ndS(N(R~RYR�R0(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytremove_hooks�scCs
ttjkS(sG
    Returns True if the import hooks are installed, False if not.
    (R~RYR�(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pytdetect_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�(RA((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyt	__enter__�scGs|jst�ndS(N(R�R�(RAtargs((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyt__exit__�s	(RRRR�R�(((sJ/opt/alt/python27/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�(RA((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyR��scGs|jrt�ndS(N(R�R�(RAR�((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyR��s	(RRRR�R�(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyR��s
	((((%RRKtloggingRlRRYR>tlib2to3.pgen2.parseRtlib2to3.refactorRtlibfuturizeRt	getLoggerRR+tsetLeveltDEBUGtlisttlibfuturize_fix_names_stage1tlib2to3_fix_names_stage1tlibfuturize_fix_names_stage2tlib2to3_fix_names_stage2RR
RRR$R8tobjectR9R~R�R�R�R�R�(((sJ/opt/alt/python27/lib/python2.7/site-packages/past/translation/__init__.pyt<module>!sv&	5			"�				

Zerion Mini Shell 1.0