a
    
d+                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ejZeh d	Zeh d
Zdd ZG dd deZdS )z*Enhanced token information for formatting.    N)	lru_cache)token)	type_repr)pytree_utils)style)subtypes>   ([{>   )]}c                 C   s4   |dv r,| dkr(dt | | d |  S dS d|  S )a  Build padding string for continuation alignment in tabbed indentation.

  Arguments:
    spaces: (int) The number of spaces to place before the token for alignment.
    align_style: (str) The alignment style for continuation lines.
    tab_width: (int) Number of columns of each tab character.

  Returns:
    A padding string for alignment with style specified by align_style option.
  )ZFIXEDzVALIGN-RIGHTr   	     )int)spacesZalign_styleZ	tab_width r   b/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapf/yapflib/format_token.py_TabbedContinuationAlignPadding!   s
    r   c                   @   s*  e Zd ZdZdd Zedd Zd6ddZd	d
 Zdd Z	dd Z
dd Zdd Zdd Zedd Zedd Zee dd Zedd Zedd Zedd  Zed!d" Zee d#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. Zed/d0 Zed1d2 Zed3d4 Zd5S )7FormatTokena  Enhanced token information for formatting.

  This represents the token plus additional information useful for reformatting
  the code.

  Attributes:
    node: The original token node.
    next_token: The token in the logical line after this token or None if this
      is the last token in the logical line.
    previous_token: The token in the logical line before this token or None if
      this is the first token in the logical line.
    matching_bracket: If a bracket token ('[', '{', or '(') the matching
      bracket.
    parameters: If this and its following tokens make up a parameter list, then
      this is a list of those parameters.
    container_opening: If the object is in a container, this points to its
      opening bracket.
    container_elements: If this is the start of a container, a list of the
      elements in the container.
    whitespace_prefix: The prefix for the whitespace.
    spaces_required_before: The number of spaces required before a token. This
      is a lower-bound for the formatter and not a hard requirement. For
      instance, a comment may have n required spaces before it. But the
      formatter won't place n spaces before all comments. Only those that are
      moved to the end of a line of code. The formatter may use different
      spacing when appropriate.
    total_length: The total length of the logical line up to and including
      whitespace and this token. However, this doesn't include the initial
      indentation amount.
    split_penalty: The penalty for splitting the line before this token.
    can_break_before: True if we're allowed to break before this token.
    must_break_before: True if we're required to break before this token.
    newlines: The number of newlines needed before this token.
  c                 C   s   || _ || _|j| _|j| _|j| _|j| _| jr>|j | _d| _d| _	d| _
g | _d| _g | _d| _d| _d| _d| _tj|tjjdd| _t|tjj| _d| _| jrtd| _t|tjj}|stjhn|| _t |do|j!| _!dS )zConstructor.

    Arguments:
      node: (pytree.Leaf) The node that's being wrapped.
      name: (string) The name of the node.
    Nr   r   FdefaultZSPACES_BEFORE_COMMENT	is_pseudo)"nodenametypecolumnlinenovalueis_continuationrstripZ
next_tokenprevious_tokenZmatching_bracket
parametersZcontainer_openingZcontainer_elementswhitespace_prefixtotal_lengthsplit_penaltyZcan_break_beforer   GetNodeAnnotation
AnnotationZ
MUST_SPLITZmust_break_beforeZNEWLINESnewlinesspaces_required_before
is_commentr   GetZSUBTYPEr   NONEhasattrr   )selfr   r   Zstypesr   r   r   __init__W   s@    
zFormatToken.__init__c                 C   s>   t dr8| jd}t| jt| }|r8d| | S | jS )NZINDENT_BLANK_LINES
)r   r-   r%   lstriplen)r0   Zwithout_newlinesheightr   r   r   formatted_whitespace_prefix   s    
z'FormatToken.formatted_whitespace_prefixr   c                 C   s   t drF|dkr4d| t|t dt d }q`d| d|  }nd| t d d|  }| jrdd | j D }d	| || _| j| _| jsd	| jp| | | _n|  j|7  _d
S )aG  Register a token's whitespace prefix.

    This is the whitespace that will be output before a token's string.

    Arguments:
      newlines_before: (int) The number of newlines to place before the token.
      spaces: (int) The number of spaces to place before the token.
      indent_level: (int) The indentation level.
    ZUSE_TABSr   r   ZCONTINUATION_ALIGN_STYLEINDENT_WIDTHr   c                 S   s   g | ]}|  qS r   )r3   ).0sr   r   r   
<listcomp>       z3FormatToken.AddWhitespacePrefix.<locals>.<listcomp>r2   N)	r   r-   r   r,   r    
splitlinesjoinr%   r*   )r0   newlines_beforer   indent_levelZindent_beforeZcomment_linesr   r   r   AddWhitespacePrefix   s&    


zFormatToken.AddWhitespacePrefixc                 C   s   d| | j d | _ dS )z0Change the number of newlines before this token.r2   N)r%   r3   )r0   r>   r   r   r   AdjustNewlinesBefore   s    
z FormatToken.AdjustNewlinesBeforec           	      C   s   | j }|sdS |jr"|j }|s"dS | j}|j}|jrD||jd7 }||ksh|jr|jdkr||j jkr| j| |td  | _	dS | j}|j}t
|j}|jr|jdkr|d8 }d}|jrt
|jdd }d|jv rd}|||  | _	dS )z%Retains a token's horizontal spacing.Nr2   r   r7   r   r   )r#   r   r   is_multiline_stringr    countr   r   r-   r+   r4   split)	r0   Zfirst_columndepthpreviousZ
cur_linenoZprev_linenoZ
cur_columnZprev_columnZprev_lenr   r   r   RetainHorizontalSpacing   s@    


z#FormatToken.RetainHorizontalSpacingc                 C   s
   | j tv S N)r    _OPENING_BRACKETSr0   r   r   r   
OpensScope   s    zFormatToken.OpensScopec                 C   s
   | j tv S rI   )r    _CLOSING_BRACKETSrK   r   r   r   ClosesScope   s    zFormatToken.ClosesScopec                 C   s   | j | d S rI   )r   add)r0   subtyper   r   r   
AddSubtype   s    zFormatToken.AddSubtypec                 C   s<   d | jrdn| j| j| j| j| j}|| jr2dnd7 }|S )NzIFormatToken(name={0}, value={1}, column={2}, lineno={3}, splitpenalty={4}Z	DOCSTRINGz	, pseudo)r   )formatis_docstringr   r    r   r   r'   r   )r0   msgr   r   r   __repr__   s    zFormatToken.__repr__c                 C   s   t j| jt jjddS )z8Split penalty attached to the pytree node of this token.r   r   )r   r(   r   r)   ZSPLIT_PENALTYrK   r   r   r   node_split_penalty   s    zFormatToken.node_split_penaltyc                 C   s   t j| j v S )zToken is a binary operator.)r   ZBINARY_OPERATORrK   r   r   r   is_binary_op   s    zFormatToken.is_binary_opc                 C   s   | j th dv S )z Token is an arithmetic operator.>   &z>>-*z**|/z//%^+@z<<)r    	frozensetrK   r   r   r   is_arithmetic_op   s    zFormatToken.is_arithmetic_opc                 C   s   t j| j v S )z,Token is an operator in a simple expression.)r   ZSIMPLE_EXPRESSIONrK   r   r   r   is_simple_expr  s    zFormatToken.is_simple_exprc                 C   s   t j| j v S )zToken is a subscript colon.)r   ZSUBSCRIPT_COLONrK   r   r   r   is_subscript_colon  s    zFormatToken.is_subscript_colonc                 C   s   | j tjkS rI   )r   r   COMMENTrK   r   r   r   r,     s    zFormatToken.is_commentc                 C   s
   | j tkS rI   )r   CONTINUATIONrK   r   r   r   r!     s    zFormatToken.is_continuationc                 C   sD   t | jpB| jdkr(t| jjjdkpB| jdkoBt| jjjdkS )NmatchZ
match_stmtZcaseZ
case_block)keyword	iskeywordr    r   r   parentr   rK   r   r   r   
is_keyword  s    

zFormatToken.is_keywordc                 C   s   | j tjko| j S rI   )r   r   NAMErk   rK   r   r   r   is_name!  s    zFormatToken.is_namec                 C   s   | j tjkS rI   )r   r   NUMBERrK   r   r   r   	is_number%  s    zFormatToken.is_numberc                 C   s   | j tjkS rI   )r   r   STRINGrK   r   r   r   	is_string)  s    zFormatToken.is_stringc                 C   s   | j o| jdS )a  Test if this string is a multiline string.

    Returns:
      A multiline string always ends with triple quotes, so if it is a string
      token, inspect the last 3 characters and return True if it is a triple
      double or triple single quote mark.
    )z"""z''')rq   r    endswithrK   r   r   r   rC   -  s    	zFormatToken.is_multiline_stringc                 C   s   | j o| jd u S rI   )rq   r#   rK   r   r   r   rS   8  s    zFormatToken.is_docstringc                 C   s   | j otd| jS )Nz #.*\bpylint:\s*(disable|enable)=r,   rerg   r    rK   r   r   r   is_pylint_comment<  s    zFormatToken.is_pylint_commentc                 C   s   | j otd| jS )Nz #.*\bpytype:\s*(disable|enable)=rs   rK   r   r   r   is_pytype_commentA  s    zFormatToken.is_pytype_commentc                 C   s   | j otd| jS )Nz'#.*\bcopybara:\s*(strip|insert|replace)rs   rK   r   r   r   is_copybara_commentF  s    
zFormatToken.is_copybara_commentN)r   r   )__name__
__module____qualname____doc__r1   propertyr6   r@   rA   rH   rL   rN   rQ   rU   rV   rW   r   rb   rc   rd   r,   r!   rk   rm   ro   rq   rC   rS   ru   rv   rw   r   r   r   r   r   3   sZ   #)

"&













r   )r{   rh   rt   	functoolsr   Z yapf_third_party._ylib2to3.pgen2r   Z!yapf_third_party._ylib2to3.pytreer   Zyapf.pytreer   Zyapf.yapflibr   r   N_TOKENSrf   ra   rJ   rM   r   objectr   r   r   r   r   <module>   s   