Spade
Mini Shell
| Directory:~$ /proc/self/root/lib/python2.7/site-packages/libfuturize/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@s�dZddlmZmZmZmZmZmZddlm Z m
Z
ddlmZ
mZddlmZddlm
Z
mZmZm
Z
mZmZddlZd�Zdd �Zdd
�Zdd�Zd�Zd
�Zd�Zd�Zddd�Ze
je
je
j
e
j!e
j"fZ#e
j$e
j%fZ&d�Z'dd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/dZ0dZ1d�Z2d�Z3dd�Z4dS(s�
Utility functions from 2to3, 3to2 and python-modernize (and some home-grown
ones).
Licences:
2to3: PSF License v2
3to2: Apache Software License (from 3to2/setup.py)
python-modernize licence: BSD (from python-modernize/LICENSE)
i����(t
FromImporttNewlinet is_importt find_roottdoes_tree_importtComma(tLeaftNode(tpython_symbolstpython_grammar(ttoken(RtCalltNametsymsRtNumberNcCs�d|kr|S|jd�r,|d}ng|D]$}|jdj|��r3|^q3}t|�dkr�tddjd�|D����n!t|�d kr�td
��n|d SdS(sl
Examples:
>>> canonical_fix_name('fix_wrap_text_literals')
'libfuturize.fixes.fix_wrap_text_literals'
>>> canonical_fix_name('wrap_text_literals')
'libfuturize.fixes.fix_wrap_text_literals'
>>> canonical_fix_name('wrap_te')
ValueError("unknown fixer name")
>>> canonical_fix_name('wrap')
ValueError("ambiguous fixer name")
s.fix_tfix_isfix_{0}isOAmbiguous fixer name. Choose a fully
qualified module name instead from these:
s
css|]}d|VqdS(s
N((t.0tmyf((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pys <genexpr>-sis1Unknown
fixer. Use --list-fixes or -l for a list.N(t
startswithtendswithtformattlent
ValueErrortjoin(tfixtavail_fixestftfound((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytcanonical_fix_names
$
cCsttjdd|�S(Nu*tprefix(RR
tSTAR(R((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytStar6scCsttjdd|�S(Nu**R(RR
t
DOUBLESTAR(R((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt
DoubleStar9scCsttjdd|�S(Nu-R(RR
tMINUS(R((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytMinus<scCs?g}x+|D]#}|j|�|jt��q
W|d=|S(s{
Accepts/turns: (Name, Name, ..., Name, Name)
Returns/into: (Name, Comma, Name, Comma, ..., Name, Comma, Name)
i����(tappendR(tleafst new_leafstleaf((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt commatize?s
cCs�x1|jdk r3|jjtjkr3|j}qW|jdkrGdS|jtjkr`|jS|jdk r�|jjtjkr�|jjS|jdkr�dS|j SdS(sf
Returns the indentation for this node
Iff a node is in a suite, then it has indentation.
uN(
tparenttNonettypeR
tsuiteR
tINDENTtvaluetprev_siblingR(tnode((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytindentationKs'
$
cCs@t|�}td�|j�D��}|s2dSt|�SdS(s
Dirty little trick to get the difference between each indentation level
Implemented by finding the shortest indentation string
(technically, the "least" of all of the indentation strings,
but
tabs and spaces mixed won't get this far, so those are
synonymous.)
css*|] }|jtjkr|jVqdS(N(R+R
R-R.(Rti((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pys <genexpr>isu
N(Rtsett pre_ordertmin(R0trtall_indents((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytindentation_step`s
cCs�x'|jD]}|jtjkr
dSq
Wx?t|j�D]"\}}|jtjkr:Pq:q:Wtd��ttjt �t
tjt|�t
|��g�}|j|d}|j�d|_|j|�|j|�dS(sj
Turn the stuff after the first colon in parent's children
into a suite, if it wasn't already
NuNo class suite and no
':'!iu(tchildrenR+R
R,t enumerateR
tCOLONRRRRR-R1R8tremoveRtappend_child(R)R0R2R,tone_node((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytsuitifyps7
cCsw|dkrd}ntdd|�|g}|dk rg|jtddd�t|dd�g�nttj|�S(s�
Accepts a package (Name node), name to import it as (string), and
optional prefix and returns a node:
import <package> [as <as_name>]
uuimportRuasu
N(R*RtextendRR
timport_name(tpackagetas_nameRR9((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt
NameImport�s ccs�|jtkst�|j}xC|jtjkrc|j}|jtjkrRPn|V|j}q!W|j}|jtj ks�t�|j}x|dk r�|V|j}q�W|j}|jtkr|}x$|jdk r�|jV|j}q�W|j}n|j}|dkrdSxg|jtkr�|jtjkrE|Vn|j}|dkr|j}|j}|dkrPqqqWdS(s�
Generator yields all nodes for which a node (an import_stmt) has scope
The purpose of this is for a call to _find() on each of them
N(
R+t
_import_stmtstAssertionErrortnext_siblingR
tSEMItNEWLINER)R
tsimple_stmtR*t_compound_stmtsR,(R0ttesttnxtR)tcontexttctp((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytimport_binding_scope�sB
cCsgt|�}tddd�}t|dd�}ttj|||g�}|dk rc||_n|S(NuasRu
(RRR
timport_as_nameR*R(tnameRCRtnew_nametnew_astnew_as_nametnew_node((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytImportAsName�scCs>|jtjko=t|j�dko=|jdjtjkS(s<
Returns True if the node appears to be a docstring
i(R+R
RJRR9R
tSTRING(R0((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytis_docstring�scCs2t|�}td||�r"dSd}xvt|j�D]e\}}t|�s\t|�re|}nt|�rwq8nt|�}|s�Pn||kr8dSq8Wt dt
tj|dd�g�}|dkr|dkr|jdj
|_
d|jd_
n|t�g}|j|ttj|��dS(s
This seems to work
u
__future__NRt
iu(RRR*R:R9tis_shebang_commenttis_encoding_commentRZtcheck_future_importRRR
tNAMERRtinsert_childRR
RJ(tfeatureR0troottshebang_encoding_idxtidxtnamestimport_R9((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt
future_import�s( $c Cs6t|�}td||�r"dSd}x_t|j�D]N\}}|jtjkr8|jr8|jdjtjkr8|d}Pq8q8WxP|j|D];}|jtj kr�|d7}q�n|j
}d|_
Pq�Wd}tdttj
|dd�g�}|t�g}|j|ttj|d|��dS(sD
An alternative to future_import() which might not work ...
u
__future__NiiuRu (RRR:R9R+R
RJR
RYRIRRRR_RR`R( RaR0Rbt
insert_posRdtthing_afterRRfR9((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytfuture_import2s(
$cCs�g|D]}|jtjkr|^q}tg|D]}|df^q5�}x}t|�D]o\}}|jtjkr�|jdjtj kr�|jdj
}|jd||<q]||}|||<q]W|S(u/
Parse a list of arguments into a dict
iiiN(R+R
tCOMMAtdictR*R:R
targumentR9tEQUALR.(targlisttschemeR2tktret_mappingtargtslot((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt
parse_args.s+%+
cCs,|jtjko+|jo+t|jd�S(Ni(R+R
RJR9R(R0((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytis_import_stmtHscCs�t|�}t|||�r"dSt}x6ddddgD]"}td||�r;t}Pq;q;W|rd\}}xot|j�D]^\}}t|�r�|}|} x3|r�|j}| d7} t|�s�| }Pq�q�WPq�q�W|dk s�t �|dk s t �|}
nLxCt|j�D]2\}}|j
tjkrDPnt
|�s"Pq"q"W|}
|dkr�ttjttjd�ttj|d d
�g�}n�t|ttj|d d
�g�}|dkrottjttjttjd�ttjttjd�ttjd
�g�ttjttjd�ttjd�g�g�g�}|t�g}
ng}
|t�g}|j|
j}d|j|
_|j|
ttj|d |��t|
�dkr�|j|
dttj|
��ndS(s�Works like `does_tree_import` but adds an
import statement at the
top if it was not imported (but below any __future__ imports) and below
any
comments such as shebang lines).
Based on lib2to3.fixer_util.touch_import()
Calling this multiple times adds the imports in reverse order.
Also adds "standard_library.install_aliases()" after
"from future import
standard_library". This should probably be factored into another
function.
Ntabsolute_importtdivisiontprint_functiontunicode_literalst
__future__iuimportRu
ustandard_libraryu.uinstall_aliasesu(u)ui(NN(RRtFalsetTrueR*R:R9R^RGRFR+R
RJRZRRARR
R_RtpowerttrailertDOTtLPARtRPARRRR`R(RBtname_to_importR0RbRRStstarttendRdtidx2RhRft
install_hookstchildren_hookstchildren_importt
old_prefix((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyttouch_import_topMsh
!$ $"cCs�|}|jtjko|js(t�S|jd}|jtjkopt|jdd�op|jdjdkszt�S|jdjtj kr�|jd}n
|jd}|jtj
krRt�}x�|jD]u}|jtjkr|j|j�q�|jtj
kr�|jd}|jtjks7t�|j|j�q�q�W|S|jtj
kr�|jd}|jtjks�t�t|jg�S|jtjkr�t|jg�Sts�td|��dS( sZIf
this is a future import, return set of symbols that are imported,
else return None.iiR.u
__future__iisstrange import: %sN(R+R
RJR9R3timport_fromthasattrR.R
R�timport_as_namesR_taddRRRFR|(R0tsavenodetresulttn((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyR^�s8
s^#!.*pythons^#.*coding[:=]\s*([-\w.]+)cCsttjt|j��S(s�
Comments are prefixes for Leaf nodes. Returns whether the given node
has a
prefix that looks like a shebang line or an encoding line:
#!/usr/bin/env python
#!/usr/bin/python3
(tbooltretmatcht
SHEBANG_REGEXR(R0((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyR\�scCsttjt|j��S(s
Comments are prefixes for Leaf nodes. Returns whether the given node
has a
prefix that looks like an encoding line:
# coding: utf-8
# encoding: utf-8
# -*- coding: <encoding name> -*-
# vim: set fileencoding=<encoding name> :
(R�R�R�tENCODING_REGEXR(R0((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyR]�s
cCsjt|�dkst�t|�dkrK|\}}|t�|g}n|}tt|�|d|�S(s�
Example:
>>> wrap_in_fn_call("oldstr", (arg,))
oldstr(arg)
>>> wrap_in_fn_call("olddiv", (arg1, arg2))
olddiv(arg1, arg2)
>>> wrap_in_fn_call("olddiv", [arg1, comma, arg2,
comma, arg3])
olddiv(arg1, arg2, arg3)
iiR(RRFRRR(tfn_nametargsRtexpr1texpr2tnewargs((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pytwrap_in_fn_call�s(5t__doc__tlib2to3.fixer_utilRRRRRRtlib2to3.pytreeRRtlib2to3.pygramRR
R R
RRRR�RR*RR!R#R(R1R8R?RDtif_stmtt
while_stmttfor_stmtttry_stmtt with_stmtRKRAR�RERQRXRZRgRjRuRvR�R^R�R�R\R]R�(((s:/usr/lib/python2.7/site-packages/libfuturize/fixer_util.pyt<module> s>.. " $ ;
( c *