Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.6/site-packages/libfuturize/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/libfuturize/__pycache__/fixer_util.cpython-36.pyc

3

�uGh�C�@s@dZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
mZddl
mZddlZdd�Zd3d	d
�Zd4dd�Zd5d
d�Zdd�Zdd�Zdd�Zdd�Zd6dd�ZejejejejejfZ ej!ej"fZ#dd�Z$d7dd�Z%dd�Z&dd �Z'd!d"�Z(d#d$�Z)d%d&�Z*d'd(�Z+d)d*�Z,d+Z-d,Z.d-d.�Z/d/d0�Z0d8d1d2�Z1dS)9z�
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�Call�Name�Comma)�Leaf�Node)�python_symbols)�tokenNcs~d�kr�S�jd�r"�dd���fdd�|D�}t|�dkr^tdd	jd
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|]}|jdj���r|�qS)zfix_{0})�endswith�format)�.0�f)�fix��=/root/tmp/pip-build-gzoz1_uw/future/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
rcCsttjd|d�S)N�*)�prefix)r
r
�STAR)r!rrr�Star6sr#cCsttjd|d�S)Nz**)r!)r
r
�
DOUBLESTAR)r!rrr�
DoubleStar9sr%cCsttjd|d�S)N�-)r!)r
r
�MINUS)r!rrr�Minus<sr(cCs2g}x"|D]}|j|�|jt��q
W|d=|S)z{
    Accepts/turns: (Name, Name, ..., Name, Name)
    Returns/into: (Name, Comma, Name, Comma, ..., Name, Comma, Name)
    r���)�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�type�syms�suiter
�INDENT�valueZprev_siblingr!)�noderrr�indentationKs


r4cCs2t|�}tdd�|j�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)r.r
r1r2)r�irrrrisz#indentation_step.<locals>.<genexpr>z    N)r�setZ	pre_order�min)r3�rZall_indentsrrr�indentation_step`s
r9cCs�x|jD]}|jtjkrdSqWx,t|j�D]\}}|jtjkr,Pq,Wtd��ttjt	�t
tjt|�t
|��g�}|j|d}|j�d|_|j|�|j|�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,)�childrenr.r/r0�	enumerater
�COLONrrrr
r1r4r9�remover!Zappend_child)r-r3r5r0Zone_noderrr�suitifyps&
r>cCsN|dkrd}td|d�|g}|dk	rB|jtddd�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�extendrr/�import_name)�package�as_namer!r:rrr�
NameImport�srFccs|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)r.�
_import_stmts�AssertionError�next_siblingr
�SEMI�NEWLINEr-r/�simple_stmt�_compound_stmtsr0)r3�testZnxtr-�context�c�prrr�import_binding_scope�sB




rRcCsDt|�}tddd�}t|dd�}ttj|||g�}|dk	r@||_|S)Nr@rA)r!)rrr/�import_as_namer!)�namerEr!�new_nameZnew_asZnew_as_name�new_noderrr�ImportAsName�srWcCs,|jtjko*t|j�dko*|jdjtjkS)z<
    Returns True if the node appears to be a docstring
    r)r.r/rLrr:r
�STRING)r3rrr�is_docstring�srYcCs�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}|j|ttj|��dS)z
    This seems to work
    �
__future__NrA)r!rr,)rrr;r:�is_shebang_comment�is_encoding_commentrY�check_future_importrr
r
�NAMEr!r�insert_childrr/rL)�featurer3�rootZshebang_encoding_idx�idx�names�import_r:rrr�
future_import�s(
rec	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}|j|ttj||d��dS)zD
    An alternative to future_import() which might not work ...
    rZNrrr,rA)r!)rrr;r:r.r/rLr
rXrKr!rr
r^rr_r)	r`r3ra�
insert_posrbZthing_afterr!rdr:rrr�future_import2s(
rgcCs�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)r.r
�COMMA)rr5rrrr2szparse_args.<locals>.<listcomp>cSsg|]}|df�qS)Nr)r�krrrr4srr�)	�dictr;r.r/Zargumentr:r
�EQUALr2)Zarglist�schemeZret_mappingr5�argZslotrrr�
parse_args.srocCs |jtjko|jot|jd�S)Nr)r.r/rLr:r)r3rrr�is_import_stmtHsrpcCs
t|�}t|||�rdSd}xdD]}td||�r"d}Pq"W|r�d\}}xNt|j�D]@\}}t|�rT|}|}	x$|r�|j}|	d	7}	t|�sn|	}PqnWPqTW|dk	s�t�|dk	s�t�|}
n4x.t|j�D] \}}|jtj	kr�Pt
|�s�Pq�W|}
g}|dk�rttjt
tjd
�t
tj|dd�g�}n�t|t
tj|dd�g�}|d
k�r�ttj	ttjt
tjd
�ttjt
tjd�t
tjd�g�ttjt
tjd�t
tjd�g�g�g�}
|
t�g}|t�g}|j|
j}d|j|
_|j|
ttj	||d��t|�dk�r|j|
d	ttj	|��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_literalsrZTrr?rA)r!Zstandard_library�.Zinstall_aliases�(�)r,r)rqrrrsrt)NN)rrr;r:r]rIrHr.r/rLrYrrCr
r
r^r�power�trailer�DOT�LPAR�RPARrr!r_r)rDZname_to_importr3rarrT�start�endrbZidx2rfZchildren_hooksrdZ
install_hooksZchildren_importZ
old_prefixrrr�touch_import_topMsh






rcCsX|}|jtjko|jst�S|jd}|jtjkoPt|jdd�oP|jdjdksXt�S|jdjtj	krv|jd}n
|jd}|jtj
kr�t�}xZ|jD]P}|jtjkr�|j|j�q�|jtj
kr�|jd}|jtjks�t�|j|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.rrr2rZ�rFzstrange import: %sN)r.r/rLr:r6�import_from�hasattrr2r
r{Zimport_as_namesr^�addrSrH)r3Zsavenode�result�nrrrr]�s8



r]z^#!.*pythonz^#.*coding[:=]\s*([-\w.]+)cCsttjt|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!)r3rrrr[�sr[cCsttjt|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!)r3rrrr\�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)
    rrj)r!)rrHr	rr)�fn_name�argsr!Zexpr1Zexpr2Znewargsrrr�wrap_in_fn_call�sr�)N)N)N)NN)N)N)2�__doc__Zlib2to3.fixer_utilrrrrrrrr	Zlib2to3.pytreer
rZlib2to3.pygramrr/r
r�rr#r%r(r+r4r9r>rFZif_stmtZ
while_stmtZfor_stmtZtry_stmtZ	with_stmtrMrCr�rGrRrWrYrergrorprr]r�r�r[r\r�rrrr�<module>	s<("



;

( b)

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists