Your IP : 52.14.7.53


Current Path : /opt/alt/python37/lib/python3.7/site-packages/libfuturize/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/libfuturize/__pycache__/fixer_util.cpython-37.pyc

B

�A�[VD�@s\dZddlmZmZmZmZmZmZddlm	Z	m
Z
ddlmZ
mZddlmZddlm
Z
mZmZm
Z
mZmZddlZdd	�Zd4d
d�Zd5dd
�Zd6dd�Zdd�Zdd�Zdd�Zdd�Zd7dd�Ze
je
je
je
j e
j!fZ"e
j#e
j$fZ%dd�Z&d8dd�Z'dd�Z(d d!�Z)d"d#�Z*d$d%�Z+d&d'�Z,d(d)�Z-d*d+�Z.d,Z/d-Z0d.d/�Z1d0d1�Z2d9d2d3�Z3dS):z�
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)
�)�
FromImport�Newline�	is_import�	find_root�does_tree_import�Comma)�Leaf�Node)�python_symbols�python_grammar)�token)r	�Call�Name�symsr�NumberNcs~d�kr�S��d�r"�dd���fdd�|D�}t|�dkr^tdd	�d
d�|D����nt|�dkrrtd
��|dSdS)al
    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")
    z.fix_Zfix_�Ncs g|]}|�d����r|�qS)zfix_{0})�endswith�format)�.0�f)�fix��G/opt/alt/python37/lib/python3.7/site-packages/libfuturize/fixer_util.py�
<listcomp>(sz&canonical_fix_name.<locals>.<listcomp>�zOAmbiguous fixer name. Choose a fully qualified module name instead from these:
�
css|]}d|VqdS)z  Nr)rZmyfrrr�	<genexpr>-sz%canonical_fix_name.<locals>.<genexpr>rz1Unknown fixer. Use --list-fixes or -l for a list.)�
startswith�len�
ValueError�join)rZavail_fixes�foundr)rr�canonical_fix_names
r"cCsttjd|d�S)N�*)�prefix)rr�STAR)r$rrr�Star6sr&cCsttjd|d�S)Nz**)r$)rr�
DOUBLESTAR)r$rrr�
DoubleStar9sr(cCsttjd|d�S)N�-)r$)rr�MINUS)r$rrr�Minus<sr+cCs2g}x"|D]}|�|�|�t��q
W|d=|S)z{
    Accepts/turns: (Name, Name, ..., Name, Name)
    Returns/into: (Name, Comma, Name, Comma, ..., Name, Comma, Name)
    ���)�appendr)ZleafsZ	new_leafsZleafrrr�	commatize?s

r.cCs|x"|jdk	r"|jjtjkr"|j}qW|jdkr2dS|jtjkrD|jS|jdk	rd|jjtjkrd|jjS|jdkrrdS|jSdS)zf
    Returns the indentation for this node
    Iff a node is in a suite, then it has indentation.
    N�)	�parent�typer�suiter�INDENT�valueZprev_siblingr$)�noderrr�indentationKs


r6cCs2t|�}tdd�|��D��}|s&dSt|�SdS)a
    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)r1rr3r4)r�irrrrisz#indentation_step.<locals>.<genexpr>z    N)r�setZ	pre_order�min)r5�rZall_indentsrrr�indentation_step`s
r;cCs�x|jD]}|jtjkrdSqWx,t|j�D]\}}|jtjkr,Pq,Wtd��ttjt	�t
tjt|�t
|��g�}|j|d}|��d|_|�|�|�|�dS)zj
    Turn the stuff after the first colon in parent's children
    into a suite, if it wasn't already
    NzNo class suite and no ':'!rr/)�childrenr1rr2�	enumerater�COLONrr	rrr3r6r;�remover$Zappend_child)r0r5r7r2Zone_noderrr�suitifyps&
r@cCsN|dkrd}td|d�|g}|dk	rB|�tddd�t|dd�g�ttj|�S)z�
    Accepts a package (Name node), name to import it as (string), and
    optional prefix and returns a node:
    import <package> [as <as_name>]
    Nr/�import)r$�as� )r�extendr	r�import_name)�package�as_namer$r<rrr�
NameImport�srHccs|jtkst�|j}x2|jtjkrF|j}|jtjkr8Pn|V|j}qW|j}|jtj	ks^t�|j}x|dk	r||V|j}qfW|j}|jt
kr�|}x|jdk	r�|jV|j}q�W|j}|j}|dkr�dSxF|jt
k�r|jtjkr�|V|j}|dkr�|j}|j}|dkr�Pq�WdS)z�
    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)r1�
_import_stmts�AssertionError�next_siblingr�SEMI�NEWLINEr0r�simple_stmt�_compound_stmtsr2)r5�testZnxtr0�context�c�prrr�import_binding_scope�sB




rTcCsDt|�}tddd�}t|dd�}ttj|||g�}|dk	r@||_|S)NrBrC)r$)rr	r�import_as_namer$)�namerGr$�new_nameZnew_asZnew_as_name�new_noderrr�ImportAsName�srYcCs,|jtjko*t|j�dko*|jdjtjkS)z<
    Returns True if the node appears to be a docstring
    r)r1rrNrr<r�STRING)r5rrr�is_docstring�sr[cCs�t|�}td||�rdSd}xNt|j�D]@\}}t|�s@t|�rD|}t|�rNq(t|�}|s\P||kr(dSq(Wtdt	t
j|dd�g�}|dkr�|dkr�|jdj|_d|jd_|t
�g}|�|ttj|��dS)z
    This seems to work
    �
__future__NrC)r$rr/)rrr=r<�is_shebang_comment�is_encoding_commentr[�check_future_importrrr�NAMEr$r�insert_childr	rrN)�featurer5�rootZshebang_encoding_idx�idx�names�import_r<rrr�
future_import�s(
rgc	Cs�t|�}td||�rdSd}xDt|j�D]6\}}|jtjkr(|jr(|jdjtjkr(|d}Pq(Wx>|j|d�D](}|jtj	kr�|d7}qr|j
}d|_
PqrWd}tdttj
|dd�g�}|t�g}|�|ttj||d��dS)zD
    An alternative to future_import() which might not work ...
    r\Nrrr/rC)r$)rrr=r<r1rrNrrZrMr$rrr`rrar	)	rbr5rc�
insert_posrdZthing_afterr$rfr<rrr�future_import2s(
ricCs�dd�|D�}tdd�|D��}x^t|�D]R\}}|jtjkrl|jdjtjkrl|jdj}|jd||<q*||}|||<q*W|S)z/
    Parse a list of arguments into a dict
    cSsg|]}|jtjkr|�qSr)r1r�COMMA)rr7rrrr2szparse_args.<locals>.<listcomp>cSsg|]}|df�qS)Nr)r�krrrr4srr�)	�dictr=r1rZargumentr<r�EQUALr4)Zarglist�schemeZret_mappingr7�argZslotrrr�
parse_args.srqcCs |jtjko|jot|jd�S)Nr)r1rrNr<r)r5rrr�is_import_stmtHsrrcCst|�}t|||�rdSd}xdD]}td||�r"d}Pq"W|r�d\}}xNt|j�D]@\}}t|�rT|}|}	x$|r�|j}|	d7}	t|�sn|	}PqnWPqTW|dk	s�t�|dk	s�t�|}
n4x.t|j�D] \}}|jtj	kr�Pt
|�s�Pq�W|}
|dk�rttjt
tjd�t
tj|d	d
�g�}n�t|t
tj|d	d
�g�}|dk�r�ttj	ttjt
tjd�ttjt
tjd�t
tjd
�g�ttjt
tjd�t
tjd�g�g�g�}|t�g}
ng}
|t�g}|j|
j}d|j|
_|�|
ttj	||d
��t|
�dk�r|�|
dttj	|
��dS)a�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.
    NF)�absolute_import�division�print_function�unicode_literalsr\T)NNrrArC)r$Zstandard_library�.Zinstall_aliases�(�)r/r)rrr=r<r_rKrJr1rrNr[r	rErrr`rZpower�trailer�DOT�LPAR�RPARrr$rar)rFZname_to_importr5rcr!rV�start�endrdZidx2rhrfZ
install_hooksZchildren_hooksZchildren_importZ
old_prefixrrr�touch_import_topMsf






r�cCsX|}|jtjkr|jst�S|jd}|jtjkrRt|jdd�rR|jdjdksXt�S|jdjtj	krv|jd}n
|jd}|jtj
kr�t�}xZ|jD]P}|jtjkr�|�|j�q�|jtj
kr�|jd}|jtjks�t�|�|j�q�W|S|jtj
k�r(|jd}|jtjk�st�t|jg�S|jtjk�rBt|jg�Sd�sTtd|��d	S)
zZIf this is a future import, return set of symbols that are imported,
    else return None.rrr4r\�rFzstrange import: %sN)r1rrNr<r8�import_from�hasattrr4rr|Zimport_as_namesr`�addrUrJ)r5Zsavenode�result�nrrrr_�s8



r_z^#!.*pythonz^#.*coding[:=]\s*([-\w.]+)cCstt�t|j��S)z�
    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
    )�bool�re�match�
SHEBANG_REGEXr$)r5rrrr]�sr]cCstt�t|j��S)a
    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��ENCODING_REGEXr$)r5rrrr^�s
r^cCsHt|�dkst�t|�dkr2|\}}|t�|g}n|}tt|�||d�S)z�
    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)
    rrl)r$)rrJrr
r)Zfn_name�argsr$Zexpr1Zexpr2Znewargsrrr�wrap_in_fn_call�sr�)N)N)N)NN)N)N)4�__doc__Zlib2to3.fixer_utilrrrrrrZlib2to3.pytreerr	Zlib2to3.pygramr
rrrr
rrr�r"r&r(r+r.r6r;r@rHZif_stmtZ
while_stmtZfor_stmtZtry_stmtZ	with_stmtrOrEr�rIrTrYr[rgrirqrrr�r_r�r�r]r^r�rrrr�<module>	s>  "



;

( c*

?>