
    ?d                         d 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  G d d	e	      Z
 G d
 de	      Z G d de	      Zy)zRepresents the state of Python objects being formatted.

Objects (e.g., list comprehensions, dictionaries, etc.) have specific
requirements on how they're formatted. These state objects keep track of these
requirements.
    )absolute_import)division)print_function)	py3compat)style)subtypesc                   Z    e Zd ZdZd Zd Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zy)ComprehensionStatea  Maintains the state of list comprehension formatting decisions.

  A stack of ComprehensionState objects are kept to ensure that list
  comprehensions are wrapped with well-defined rules.

  Attributes:
    expr_token: The first token in the comprehension.
    for_token: The first 'for' token of the comprehension.
    opening_bracket: The opening bracket of the list comprehension.
    closing_bracket: The closing bracket of the list comprehension.
    has_split_at_for: Whether there is a newline immediately before the
      for_token.
    has_interior_split: Whether there is a newline within the comprehension.
      That is, a split somewhere after expr_token or before closing_bracket.
  c                 <    || _         d | _        d| _        d| _        y NF)
expr_token	for_tokenhas_split_at_forhas_interior_split)selfr   s     ;/usr/lib/python3/dist-packages/yapf/yapflib/object_state.py__init__zComprehensionState.__init__/   s      DODN!D#D    c                 H    | j                   j                  j                  dk(  S )zBReturns whether the comp_expr is "trivial" i.e. is a single token.for)r   
next_tokenvaluer   s    r   HasTrivialExprz!ComprehensionState.HasTrivialExpr5   s    ??%%++u44r   c                 .    | j                   j                  S N)r   previous_tokenr   s    r   opening_bracketz"ComprehensionState.opening_bracket9   s    ??)))r   c                 .    | j                   j                  S r   r   matching_bracketr   s    r   closing_bracketz"ComprehensionState.closing_bracket=       000r   c                     t        | j                        }| j                  |_        | j                  |_        | j                  |_        |S r   )r
   r   r   r   r   )r   clones     r   ClonezComprehensionState.CloneA   s<    t/EnnEO!22E#66ELr   c                     d| j                   d| j                  d| j                  d| j                  d| j	                         dS )Nz[opening_bracket::z, for_token::z, has_split_at_for::z, has_interior_split::z, has_trivial_expr::])r   r   r   r   r   r   s    r   __repr__zComprehensionState.__repr__H   s9     !!4>>43H3H$$d&9&9&;= >r   c                 0    t        |       t        |      k(  S r   hashr   others     r   __eq__zComprehensionState.__eq__N       :e$$r   c                     | |k(   S r    r-   s     r   __ne__zComprehensionState.__ne__Q       u}r   c                 p    t        | j                  | j                  | j                  | j                  f      S r   )r,   r   r   r   r   r   argskwargss      r   __hash__zComprehensionState.__hash__T   s1    $..$2G2G((* + +r   N)__name__
__module____qualname____doc__r   r   propertyr   r"   r&   r)   r/   r3   r9   r2   r   r   r
   r
      sR     $5 * * 1 1>%+r   r
   c                   X   e Zd ZdZd Zed        Zed        Ze ej                         d               Z
e ej                         d               Ze ej                         d               Z ej                         d        Z ej                         d	        Zd
 Zd Zd Zd Zd Zy)ParameterListStateaH  Maintains the state of function parameter list formatting decisions.

  Attributes:
    opening_bracket: The opening bracket of the parameter list.
    closing_bracket: The closing bracket of the parameter list.
    has_typed_return: True if the function definition has a typed return.
    ends_in_comma: True if the parameter list ends in a comma.
    last_token: Returns the last token of the function declaration.
    has_default_values: True if the parameters have default values.
    has_split_before_first_param: Whether there is a newline before the first
      parameter.
    opening_column: The position of the opening parameter before a newline.
    parameters: A list of parameter objects (Parameter).
    split_before_closing_bracket: Split before the closing bracket. Sometimes
      needed if the indentation would collide.
  c                 ^    || _         || _        || _        |j                  | _        d| _        y r   )r   has_split_before_first_paramopening_column
parameterssplit_before_closing_bracket)r   r   newlinerC   s       r   r   zParameterListState.__init__k   s/    *D(/D%(D%00DO(-D%r   c                 .    | j                   j                  S r   r    r   s    r   r"   z"ParameterListState.closing_bracketr   r#   r   c                 H    | j                   j                  j                  dk(  S )Nz->)r"   r   r   r   s    r   has_typed_returnz#ParameterListState.has_typed_returnv   s    **00D88r   c                 :    t        d | j                  D              S )Nc              3   4   K   | ]  }|j                     y wr   )has_default_value.0params     r   	<genexpr>z8ParameterListState.has_default_values.<locals>.<genexpr>}   s     D5u&&Ds   )anyrD   r   s    r   has_default_valuesz%ParameterListState.has_default_valuesz   s     DDOODDDr   c                 |    | j                   sy| j                   d   j                  j                  j                  dk(  S )NF,)rD   
last_tokenr   r   r   s    r   ends_in_commaz ParameterListState.ends_in_comma   s4     ????2))44::cAAr   c                     | j                   j                  }|j                  s1|j                  r%|j                  }|j                  s|j                  r%|S r   )r   r!   
is_commentr   )r   tokens     r   rV   zParameterListState.last_token   sI       11E5#3#3e 5#3#3Lr   c                    | j                   sy| j                  sy| j                  j                  }| j                  d   j                  }||j                  t        |j                        z
  z  }||z   t        j                  d      k  S )z8Return true if the last parameter fits on a single line.FTrT   COLUMN_LIMIT)	rI   rD   rV   total_lengthfirst_tokenlenr   r   Getr   indentr]   
last_params       r   LastParamFitsOnLinez&ParameterListState.LastParamFitsOnLine   sv       ????//L$00JJ++c*2B2B.CCCL& EIIn$===r   c                 @   t        j                  d      ry| j                  ry| j                  sy| j                  j
                  }| j                  d   j                  }||j
                  t        |j                        z
  z  }||z   t        j                  d      kD  S )z:Return true if there's a split before the closing bracket.DEDENT_CLOSING_BRACKETSTFrT   r\   )	r   r`   rW   rD   rV   r]   r^   r_   r   ra   s       r   SplitBeforeClosingBracketz,ParameterListState.SplitBeforeClosingBracket   s     yy*+????//L$00JJ++c*2B2B.CCCL& 599^#<<<r   c                     t        | j                  | j                  | j                        }| j                  |_        | j
                  D cg c]  }|j                          c}|_        |S c c}w r   )r@   r   rB   rC   rE   rD   r&   )r   r%   rO   s      r   r&   zParameterListState.Clone   s^    t33#@@#224E *.)J)JE&37??C%CEL Ds   A,c                 N    d| j                   | j                  | j                  fz  S )NzK[opening_bracket::%s, has_split_before_first_param::%s, opening_column::%d])r   rB   rC   r   s    r   r)   zParameterListState.__repr__   s0    "!!4#D#D  "" #r   c                 0    t        |       t        |      k(  S r   r+   r-   s     r   r/   zParameterListState.__eq__   r0   r   c                     | |k(   S r   r2   r-   s     r   r3   zParameterListState.__ne__   r4   r   c                 ~    t        | j                  | j                  | j                  d | j                  D        f      S )Nc              3   2   K   | ]  }t        |        y wr   r+   rM   s     r   rP   z.ParameterListState.__hash__.<locals>.<genexpr>   s     HutE{Hs   )r,   r   rB   rC   rD   r6   s      r   r9   zParameterListState.__hash__   s=    			t@@			HH	JK Kr   N)r:   r;   r<   r=   r   r>   r"   rI   r   	lru_cacherR   rW   rV   rd   rg   r&   r)   r/   r3   r9   r2   r   r   r@   r@   Y   s   ". 1 1 9 9 9E  E 9B  B
 9   9	> 	> 9= =#%Kr   r@   c                   l    e Zd ZdZd Ze ej                         d               Zd Z	d Z
d Zd Zd Zy	)
	Parametera  A parameter in a parameter list.

  Attributes:
    first_token: (format_token.FormatToken) First token of parameter.
    last_token: (format_token.FormatToken) Last token of parameter.
    has_default_value: (boolean) True if the parameter has a default value
  c                      || _         || _        y r   r^   rV   )r   r^   rV   s      r   r   zParameter.__init__   s    "D DOr   c                     | j                   }|| j                  k7  rUt        j                  |j                  v ry|j	                         r|j
                  n|j                  }|| j                  k7  rUy)z2Returns true if the parameter has a default value.TF)r^   rV   r   DEFAULT_OR_NAMED_ASSIGN
OpensScoper!   r   )r   toks     r   rL   zParameter.has_default_value   s]     

C

 		)	)S\\	9$'NN$4C  #..c 
  r   c                 B    t        | j                  | j                        S r   )rp   r^   rV   r   s    r   r&   zParameter.Clone   s    T%%t77r   c                 <    d| j                   d| j                  dS )Nz[first_token::z, last_token:r(   rr   r   s    r   r)   zParameter.__repr__   s    151A1A15B Br   c                 0    t        |       t        |      k(  S r   r+   r-   s     r   r/   zParameter.__eq__   r0   r   c                     | |k(   S r   r2   r-   s     r   r3   zParameter.__ne__   r4   r   c                 D    t        | j                  | j                  f      S r   )r,   r^   rV   r6   s      r   r9   zParameter.__hash__   s    !!4??344r   N)r:   r;   r<   r=   r   r>   r   rn   rL   r&   r)   r/   r3   r9   r2   r   r   rp   rp      sM    ! 9  8B%5r   rp   N)r=   
__future__r   r   r   yapf.yapflibr   r   r   objectr
   r@   rp   r2   r   r   <module>r      sH    '  % "  !8+ 8+vfK fKR&5 &5r   