a
    Ø
þd‘  ã                   @   s‚   d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ	dZ
dZeh d	£ƒZd
d„ ZG dd„ dejƒZdd„ Zdd„ Zdd„ ZdS )a;  Calculate the number of blank lines between top-level entities.

Calculates how many blank lines we need between classes, functions, and other
entities at the same level.

  CalculateBlankLines(): the main function exported by this module.

Annotations:
  newlines: The number of newlines required before the node.
é    )Útoken)Úpytree_utils)Úpytree_visitor)Ústyleé   é   é   >   Zassert_stmtZ	exec_stmtZ	with_stmtZreturn_stmtZdel_stmtZ
raise_stmtZglobal_stmtZcontinue_stmtZsimple_stmtZ
while_stmtZfor_stmtZ
small_stmtZtry_stmtZnonlocal_stmtZimport_stmtZ	expr_stmtZif_stmtZ
async_stmtZ
break_stmtZ
yield_stmtZ
print_stmtZ	pass_stmtc                 C   s   t ƒ }| | ¡ dS )z¨Run the blank line calculator visitor over the tree.

  This modifies the tree in place.

  Arguments:
    tree: the top-level pytree node to annotate with subtypes.
  N)Ú_BlankLineCalculatorÚVisit)ÚtreeZblank_line_calculator© r   új/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapf/pytree/blank_line_calculator.pyÚCalculateBlankLines,   s    r   c                       s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡ fdd„Z	dd„ Z
dd„ Zdd„ Z‡  ZS )r	   zB_BlankLineCalculator - see file-level docstring for a description.c                 C   s"   d| _ d| _d| _d| _d| _d S )Nr   F)Úclass_levelÚfunction_levelÚlast_comment_linenoÚlast_was_decoratorÚlast_was_class_or_function)Úselfr   r   r   Ú__init__;   s
    z_BlankLineCalculator.__init__c                 C   s.   |   |¡ |jd jtjkr*|jd j| _d S ©Nr   )ÚDefaultNodeVisitÚchildrenÚtypeÚgrammar_tokenÚCOMMENTÚlinenor   ©r   Únoder   r   r   ÚVisit_simple_stmtB   s    
z&_BlankLineCalculator.Visit_simple_stmtc                 C   sd   | j r.| j |jd jd kr.t|jd tƒ nt|jd |  |¡ƒ |jD ]}|  |¡ qJd| _d S )Nr   r   T)r   r   r   Ú_SetNumNewlinesÚ_NO_BLANK_LINESÚ_GetNumNewlinesr
   r   )r   r   Úchildr   r   r   ÚVisit_decoratorG   s    ÿ
z$_BlankLineCalculator.Visit_decoratorc                 C   sZ   d| _ |  |¡}d| _|  jd7  _|j|d … D ]}|  |¡ q2|  jd8  _d| _ d S )NFr   T)r   Ú(_SetBlankLinesBetweenCommentAndClassFuncr   r   r   r
   ©r   r   Úindexr#   r   r   r   ÚVisit_classdefQ   s    
z#_BlankLineCalculator.Visit_classdefc                 C   sŒ   d| _ |  |¡}t|ƒr8|  |jj¡}t|jd d ƒ n
|  |¡}d| _|  jd7  _|j|d … D ]}|  	|¡ qd|  jd8  _d| _ d S )NFr   r   T)
r   r%   Ú_AsyncFunctionÚprev_siblingÚparentr    r   r   r   r
   r&   r   r   r   ÚVisit_funcdef[   s    
ÿ
z"_BlankLineCalculator.Visit_funcdefc                    sH   | j r.t |¡tv r.t |¡}t||  |¡ƒ d| _ tt| ƒ 	|¡ dS )zÄOverride the default visitor for Node.

    This will set the blank lines required if the last entity was a class or
    function.

    Arguments:
      node: (pytree.Node) The node to visit.
    FN)
r   r   ZNodeNameÚ_PYTHON_STATEMENTSÚFirstLeafNoder    r"   Úsuperr	   r   )r   r   Zleaf©Ú	__class__r   r   r   k   s    	
z%_BlankLineCalculator.DefaultNodeVisitc                 C   sÆ   d}t  |j| ¡rP|  |j| jd ¡ | jsFt|j| jd tƒ |d7 }q|rŒ|j| jd |j|d  jd jkrŒt|j| tƒ n6| j	d |j| jkr¨t}n
|  
|¡}t|j| |ƒ |S )aL  Set the number of blanks between a comment and class or func definition.

    Class and function definitions have leading comments as children of the
    classdef and functdef nodes.

    Arguments:
      node: (pytree.Node) The classdef or funcdef node.

    Returns:
      The index of the first child past the comment nodes.
    r   r   )r   ZIsCommentStatementr   r
   r   r    Ú_ONE_BLANK_LINEr   r!   r   r"   )r   r   r'   Únum_newlinesr   r   r   r%   {   s    
ÿ
z=_BlankLineCalculator._SetBlankLinesBetweenCommentAndClassFuncc                 C   s&   | j r
tS |  |¡r"dt d¡ S tS )Nr   Z'BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION)r   r!   Ú_IsTopLevelr   ZGetr2   r   r   r   r   r"   š   s
    
z$_BlankLineCalculator._GetNumNewlinesc                 C   s   | j p
| j ot|ƒS ©N)r   r   Ú_StartsInZerothColumnr   r   r   r   r4   ¡   s    ÿz _BlankLineCalculator._IsTopLevel)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r$   r(   r,   r   r%   r"   r4   Ú__classcell__r   r   r0   r   r	   8   s   

r	   c                 C   s   t  | t jj|¡ d S r5   )r   ZSetNodeAnnotationZ
AnnotationZNEWLINES)r   r3   r   r   r   r    ¦   s    ÿr    c                 C   s$   t  | ¡jdkp"t| ƒo"| jjdkS r   )r   r.   Úcolumnr)   r*   ©r   r   r   r   r6   «   s    ÿr6   c                 C   s   | j o| j jtjkS r5   )r*   r   r   ÚASYNCr=   r   r   r   r)   °   s    r)   N)r:   Z yapf_third_party._ylib2to3.pgen2r   r   Zyapf.pytreer   r   Zyapf.yapflibr   r!   r2   Z_TWO_BLANK_LINESÚ	frozensetr-   r   ZPyTreeVisitorr	   r    r6   r)   r   r   r   r   Ú<module>   s   	n