
    hD              	       N   U d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d d	lmZmZ eeef   Zh d
Ze	ed<   ddhZ e	ed<   h dZ!e	ed<   dZ"dZ#dZ$e G d d             Z%dedee   fdZ& ed      de'de(de)e%   fd       Z*dede+ddfdZ,d e'de'fd!Z-d"ed#ed$ee.e+e+f      ddfd%Z/d"ed#ed$ee.e+e+f      de(fd&Z0ded'e%d#edee   fd(Z1ded'e%d#edee   fd)Z2d*ede(fd+Z3d*ede(fd,Z4d-e)e   de(fd.Z5d/e'd#ede(fd0Z6y)1    N)
CollectionIterator)	dataclass)	lru_cache)FinalOptionalUnion)ModePreview)CLOSING_BRACKETSSTANDALONE_COMMENT
WHITESPACEcontainer_offirst_leaf_ofmake_simple_prefixpreceding_leafsyms)token)LeafNode>   	# fmt:off
# fmt: off# yapf: disableFMT_OFFz# fmt: skipz
# fmt:skipFMT_SKIP>   # fmt:on	# fmt: on# yapf: enableFMT_ONz !:#'z# ;c                   N    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   y)	ProtoCommenta  Describes a piece of syntax that is a comment.

    It's not a :class:`blib2to3.pytree.Leaf` so that:

    * it can be cached (`Leaf` objects should not be reused more than once as
      they store their lineno, column, prefix, and parent information);
    * `newlines` and `consumed` fields are kept separate from the `value`. This
      simplifies handling of special marker comments like ``# fmt: off/on``.
    typevaluenewlinesconsumed	form_feedleading_whitespaceN)__name__
__module____qualname____doc__int__annotations__strbool     A/var/www/html/immo/lib/python3.12/site-packages/black/comments.pyr"   r"   !   s(     IJMMOr2   r"   leafreturnc              #   6  K   d}t        | j                  | j                  t        j                  k(        D ]R  }|j
                  }t        |j                  |j                        }t        |j                  |j                  |       T t        | |       yw)a  Clean the prefix of the `leaf` and generate comments from it, if any.

    Comments in lib2to3 are shoved into the whitespace prefix.  This happens
    in `pgen2/driver.py:Driver.parse_tokens()`.  This was a brilliant implementation
    move because it does away with modifying the grammar to include all the
    possible places in which comments can be placed.

    The sad consequence for us though is that comments don't "belong" anywhere.
    This is why this function generates simple parentless Leaf objects for
    comments.  We simply don't know what the correct parent should be.

    No matter though, we can live without this.  We really only need to
    differentiate between inline and standalone comments.  The latter don't
    share the line with any code.

    Inline comments are emitted as regular token.COMMENT leaves.  Standalone
    are emitted with a fake STANDALONE_COMMENT token identifier.
    r   is_endmarker)prefixN)list_commentsr9   r#   r   	ENDMARKERr&   r   r%   r'   r   r$   normalize_trailing_prefix)r4   total_consumedpcr9   s       r3   generate_commentsr?   5   st     & NDKKdii5??6RS 5#BKK>277BHHV445 dN3s   BBi   )maxsizer9   r8   c                   g }| rd| vr|S d}d}d}d}t        t        j                  d|             D ]  \  }}|t        |      dz   z  }t        j                  d|      }	|	sJ |	j                         \  }
}|s|dz  }d|v rd}|j                  d      s|j                  d	      r|dz  }y||k(  r|st        j                  }nt        }t        |      }|j                  t        ||||||

             d}d} |S )zNReturn a list of :class:`ProtoComment` objects parsed from the given `prefix`.#r   Fz?
|   z^(\s*)(\S.*|)$T\)r#   r$   r%   r&   r'   r(   )	enumerateresplitlenmatchgroups
startswithendswithr   COMMENTr   make_commentappendr"   )r9   r8   resultr&   nlinesignored_linesr'   index	full_linerJ   
whitespacelinecomment_typecomments                 r3   r:   r:   P   s(    "$FS&HFMI%bhhz6&BC !yC	NQ&&*I6u <<>
DaKFy  	s# }}T""M!, ==L-Lt$!!##-		
 	C!D Mr2   r=   c                     | j                   |d }d|vr:|j                  d      }d|v xr |j                  d      }t        ||      | _         yd| _         y)zNormalize the prefix that's left over after generating comments.

    Note: don't use backslashes for formatting or you'll lose your voting rights.
    NrE   
rD    )r9   countrM   r   )r4   r=   	remaindernl_countr'   s        r3   r<   r<      s\    
 NO,I9??4(I%B)*<*<T*B	(9=DKr2   contentc                     | j                         } | sy| d   dk(  r| dd } | r/| d   dk(  r'| j                         j                  d      sd| dd z   } | r| d   t        vrd| z   } d| z   S )a  Return a consistently formatted comment from the given `content` string.

    All comments (except for "##", "#!", "#:", '#'") should have a single
    space between the hash sign and the content.

    If `content` didn't start with a hash sign, one is provided.
    rB   r   rC   N    ztype: )rstriplstriprL   COMMENT_EXCEPTIONS)r`   s    r3   rO   rO      s     nnGqzS!"+AJ.. ++G4#71:%77-=r2   nodemodelinesc                 .    d}|rt        | ||      }|ryy)zJConvert content between `# fmt: off`/`# fmt: on` into standalone comments.TN)convert_one_fmt_off_pair)rg   rh   ri   	try_agains       r3   normalize_fmt_offrm      s     I
,T4?	 r2   c                 &   | j                         D ]|  }d}t        |j                  d      D ]\  }|j                  t        v }t        |j                  |      }|s|r|r|j                  t        v r|j                  }Q|j                  t        k7  r7t        |      }|r*|r|j                  t        vr|r|j                  t        v rt        t        |||            }	|	s|	d   }
|
j                  }|
j                  }|j                  t        v r||j                  d |
_        |r
d|
_        |}n|d| d|j                  z  z   }dj!                  d |	D              }|j"                  |j                  z
  |j                  t        v rqd}t%        |      dkD  rJt'        fd|D              s6|j)                  |j                        d   }d|v r|j)                  d      d	   }||z  }|j                  dz   |z   }|r||j*                  |j                  z   z  }|j-                  d      r|dd	 }d}|	D ]  }|j/                         }||} |J d
       |J d       |j1                  |t3        t        ||t5        |
                     y  y)zConvert content of a single `# fmt: off`/`# fmt: on` into a standalone comment.

    Returns True if a pair was converted.
    r   Fr7   Nr\   r[   c              3   2   K   | ]  }t        |        y wN)r/   ).0ns     r3   	<genexpr>z+convert_one_fmt_off_pair.<locals>.<genexpr>   s     "Aa3q6"As   c              3   J   K   | ]  }|d    cxk  xr |d   k  nc   yw)r   rC   Nr1   )rq   rW   comment_linenos     r3   rs   z+convert_one_fmt_off_pair.<locals>.<genexpr>   s+      .=ADG~8a88.s    #z(INTERNAL ERROR: fmt: on/off handling (1)z(INTERNAL ERROR: fmt: on/off handling (2))r9   fmt_pass_converted_first_leafT)leavesr:   r9   r$   r   _contains_fmt_skip_commentr#   r   r&   r   r   r   listgenerate_ignored_nodesparentr%   joinlinenorI   anyrH   r(   rM   removeinsert_childr   r   )rg   rh   ri   r4   previous_consumedrY   
is_fmt_offis_fmt_skipprevignored_nodesfirstr|   r9   standalone_comment_prefixhidden_valuefmt_off_prefix	first_idxignoredrT   ru   s                      @r3   rk   rk      s     J$T[[uE H	G '1J4W]]DIK{II!11$+$4$4! ||11%d+!diiz&A "tyyJ'>  !7gt!LMM !!$E\\F\\F}}'%g&6&6&89!,2) --.8H8H1HH * 77"A="AAL![[7+;+;;N}}'!#u:># .EJ. + &,\\'--%@%CN~-)7)=)=d)CB)G)^;)&}}t3lB : :W]] JJ$$T*  ,CR0'+I( &($ %I& %Q'QQ%(T*TT(& 42?2F	 QH	JX r2   rY   c              #     K   t        |j                  |      rt        | ||      E d{    yt        |       }|J|j                  t
        j                  k7  r+t        |      ryt        |      rt        |j                        D ]  \  }}t        |t              r#t        |      r|j                  t        v r|  y|j                  t
        j                  k(  r8|t        |j                        dz
  k  rt        |j                  |dz            r yt        |      r y|  n:|j                  t
        j                   k(  r|j"                  y| |j"                  }| |j                  t
        j                  k7  r)yyyy7 _w)zStarting from the container of `leaf`, generate all leaves until `# fmt: on`.

    If comment is skip, returns leaf only.
    Stops at the end of the block.
    NrC   )ry   r$   %_generate_ignored_nodes_from_fmt_skipr   r#   r   r;   	is_fmt_onchildren_contains_fmt_onrF   children
isinstancer   r   INDENTrI   DEDENTnext_sibling)r4   rY   rh   	containerrT   childs         r3   r{   r{     sR     "'--68wMMM*40I

INNeoo$EY $I. ))*<*< = ueT*y/?zz%55
 $JJ%,,.I$6$6 7! ;;01C1CEAI1NO +E2'* ~~-)2H2H2P O!..IA 
INNeoo$E
$E
 	Ns   'FFEFFc              #   "  K   | j                   }| j                  }g }t        | j                  d      }|r|j                  |d   j                  k7  ry|| j                  |j
                  d | _        t        j                  |vra|g}d|j                  vrE|j                   9|j                   }|j                  d|       d|j                  vr|j                   9|E d{    y|}|g}|j                   |j                  |j                  }d|j                  vr|j                   t        |j                   j                               }	|	r|	d   n|}|j                  t        j                  t        j                  fv rd|_        nQ|j                  d|       |j                   |j                  |j                  }d|j                  vr|j                   |E d{    y||j                  t        j                   k(  r| j                  t        j                  k(  rd| _        |j                   }
|
[|
j                  t        j                   k7  r>|j                  d|
       |
j                   }
|
|
j                  t        j                   k7  r>|j                  }|O|j                   C|j                   j                  t        j"                  k(  r|j                  d|j                          t%        |      E d{    yyyy7 &7 *7 w)zLGenerate all leaves that should be ignored by the `# fmt: skip` from `leaf`.Fr7   r   Nr[   rv   r\   )prev_siblingr|   r:   r9   r$   r&   r   fix_fmt_skip_in_one_linersinsertrz   rx   r#   r   NEWLINEr   r   suiteASYNCiter)r4   rY   rh   r   r|   r   commentssiblingscurrent_node
leaf_nodesparent_siblinggrandparents               r3   r   r   6  s     $$L[[F M T[[u=Hw}}(9(99kk'"2"2"45--T9$~HL/// --9+88<0	 L/// --9  * $%$$,1D1D1P'..L,---,2K2K2Wl77>>@AJ-7:b>\L  U]]ELL$AA&(#  L1((0\5H5H5T+22 ,---,2K2K2W !  v{{djj8TYY%--=W
 ,,(^-@-@DJJ-N  N3+88N (^-@-@DJJ-N
 mm#((4((--<  K$<$<=&&&' >X8Q  L 	!* 	'sK   CLL!L"C8LL L
!B1LA+L>L?	L
LLr   c                     d}t        | j                  d      D ],  }|j                  t        v rd}|j                  t        v s+d}. |S )zDetermine whether formatting is switched on within a container.
    Determined by whether the last `# fmt:` comment is `on` or `off`.
    Fr7   T)r:   r9   r$   r   r   )r   fmt_onrY   s      r3   r   r     sN     F !1!1F ==F"F]]g%F	
 Mr2   c                 \    | j                   D ]  }t        |      }|t        |      s y y)z2Determine if children have formatting switched on.TF)r   r   r   )r   r   r4   s      r3   r   r     s5    ## U#	$
 r2   comment_listc                 L    | D ]  }|j                   j                  d      s y y)z
    Returns:
        True iff one of the comments in @comment_list is a pragma used by one
        of the more common static analysis tools for python (e.g. mypy, flake8,
        pylint).
    )z# type:z# noqaz	# pylint:TF)r$   rL   )r   rY   s     r3   contains_pragma_commentr     s.       ==##$FG r2   comment_linec                 L   | g| j                  t              dd D cg c]  }t        |j                         z    c}| j                  t              j                  t              D cg c]  }t        |j                         z    c}}t	        d |D              S c c}w c c}w )aQ  
    Checks if the given comment contains FMT_SKIP alone or paired with other comments.
    Matching styles:
      # fmt:skip                           <-- single comment
      # noqa:XXX # fmt:skip # a nice line  <-- multiple comments (Preview)
      # pylint:XXX; fmt:skip               <-- list of comments (; separated, Preview)
    rC   Nc              3   ,   K   | ]  }|t         v   y wrp   )r   )rq   rY   s     r3   rs   z-_contains_fmt_skip_comment.<locals>.<genexpr>  s     Jww("Js   )rH   _COMMENT_PREFIXstrip_COMMENT_LIST_SEPARATORr   )r   rh   rY   semantic_comment_blockss       r3   ry   ry     s     	 (--o>qrB

 gmmo-

 (--o>DD'

 gmmo-

 J2IJJJ



s   B(B!)7rG   collections.abcr   r   dataclassesr   	functoolsr   typingr   r   r	   
black.moder
   r   black.nodesr   r   r   r   r   r   r   r   blib2to3.pgen2r   blib2to3.pytreer   r   LNr   r.   r   r   rf   r   r   r"   r?   r/   r0   rz   r:   r-   r<   rO   tuplerm   rk   r{   r   r   r   r   ry   r1   r2   r3   <module>r      s)   	 0 !  ) ) $	 	 	 ! & 4:? ? ,/% /; ;     &4B 48D> 46 4,# , ,l9K , ,^B   # # 2@
@@#-eCHo#>@	@S
SS#-eCHo#>S	Sl,/
,/%,/-1,/b\,/^R'
R'%R'-1R'b\R'j
 
 
 t $t*  KS K K Kr2   