o
    =Zc$                     @   sZ  U d Z ddlZddlZddlmZ ddlmZmZ ejdk r%ddl	m
Z
 nddlm
Z
 dZe
ed< ed	e d
 ejZe
ed< edZe
ed< dee dededefddZdedefddZdedee fddZdededefddZdedefddZdeddfd d!Zdedefd"d#Zed$d%d&edee fd'd(Zdedefd)d*ZdS )+zN
Simple formatting on strings. Further string formatting code is in trans.py.
    N)	lru_cache)ListPattern)      )FinalfurbFURBSTRING_PREFIX_CHARSz^([z]*)(.*)$STRING_PREFIX_REz\s*\t+\s*(\S)FIRST_NON_WHITESPACE_REregexreplacementoriginalreturnc                 C   s   |  ||  ||S )zReplace `regex` with `replacement` twice on `original`.

    This is used by string normalization to perform replaces on
    overlapping matches.
    )sub)r   r   r    r   C/var/www/chikooza/env/lib/python3.10/site-packages/black/strings.py	sub_twice   s   r   stringc                 C   s   |  t}|dd dv S )zS
    Returns:
        True iff @string starts with three quotation characters.
    Nr   >   """''')lstripr	   )r   
raw_stringr   r   r   has_triple_quotes    s   
r   sc                 C   s\   g }|   D ]%}t|}|r&|d}||d|  ||d   q|| q|S )zh
    Splits string into lines and expands only leading tabs (following the normal
    Python rules)
       N)
splitlinesr   matchstartappend
expandtabs)r   linesliner   first_non_whitespace_idxr   r   r    lines_with_leading_tabs_expanded)   s   


r$   	docstringprefixc           
      C   s   | sdS t | }tj}|dd  D ]}| }|r$t|t|t| }q|d  g}|tjk r_t|d }t|dd  D ]\}}||d   }	|	sQ||krY|	||	  q?|	d q?d
|S )N r   r      
)r$   sysmaxsizer   minlenstrip	enumeraterstripr   join)
r%   r&   r!   indentr"   strippedtrimmedlast_line_idxistripped_liner   r   r   fix_docstring?   s$   

r8   c                 C   s@   t |  d}d}| | tv r|| | 7 }|d7 }| | tv s|S )z
    Pre-conditions:
        * assert_is_leaf_string(@string)

    Returns:
        @string's prefix (e.g. '', 'r', 'f', or 'rf').
    r'   r   r   )assert_is_leaf_stringr	   )r   r&   
prefix_idxr   r   r   get_string_prefixW   s   r;   c                 C   s   |  d}|  d}d||fv rt||}nt||}d|  kr)t| d k s1n J | d| d dv s>J | dt| d	| tts]J t| d	|  d
tt dd	S )aH  
    Checks the pre-condition that @string has the format that you would expect
    of `leaf.value` where `leaf` is some Leaf such that `leaf.type ==
    token.STRING`. A more precise description of the pre-conditions that are
    checked are listed below.

    Pre-conditions:
        * @string starts with either ', ", <prefix>', or <prefix>" where
        `set(<prefix>)` is some subset of `set(STRING_PREFIX_CHARS)`.
        * @string ends with a quote character (' or ").

    Raises:
        AssertionError(...) if the pre-conditions listed above are not
        satisfied.
    "'r   r   z0 is missing a starting quote character (' or ").)r=   r<   z/ is missing an ending quote character (' or ").Nz is NOT a subset of .)findmaxr,   r-   setissubsetr	   )r   
dquote_idx
squote_idx	quote_idxr   r   r   r9   j   s&   




r9   c                 C   s   t | }|dusJ d| |d}|dddddd	d
d	}t|dkr<d|d  kr<|ddd }| |d S )z#Make all string prefixes lowercase.Nzfailed to match string r   FfBbUr'   ur(   rr   r>   )r
   r   groupreplacer-   lower)r   r   orig_prefix
new_prefixr   r   r   normalize_string_prefix   s   


rS   @   )r+   patternc                 C   s
   t | S )N)recompile)rU   r   r   r   _cached_compile   s   
rX   c                 C   s  |  t}|dd dkr| S |dd dkrd}d}n|d dkr'd}d}nd}d}| |}|dkr6| S | d| }td	| }td
| }td
| }| |t| t|  }	d| v rn||	rk| S |	}
n+t|d| |	}
|	|
kr|
}	| | |	 | } t|d| |
}
t|d| |
}
d| v rt	d|
tj
}|D ]}dt|v r|   S q|dkr|
dd dkr|
dd d }
|	d}|
d}||kr| S ||kr|dkr| S | | |
 | S )zPrefer double quotes but only if it doesn't cause more escaping.

    Adds or removes backslashes as appropriate. Doesn't parse and fix
    strings nested in f-strings.
    Nr   r   r   r   r<   r=   r>   z(([^\\]|^)(\\\\)*)z([^\\]|^)\\((?:\\\\)*)rM   z\1\2z\1\\rH   z
            (?:(?<!\{)|^)\{  # start of the string or a non-{ followed by a single {
                ([^{].*?)  # contents of the brackets except if begins with {{
            \}(?:(?!\})|$)  # A } followed by end of the string or a non-}
            \z\")r   r	   r@   rX   r-   casefoldsearchr   rV   findallVERBOSEstrcount)r   value
orig_quote	new_quotefirst_quote_posr&   unescaped_new_quoteescaped_new_quoteescaped_orig_quotebodynew_bodymatchesmorig_escape_countnew_escape_countr   r   r   normalize_string_quotes   s`   


	

rm   )__doc__rV   r*   	functoolsr   typingr   r   version_infotyping_extensionsr   r	   __annotations__rW   DOTALLr
   r   r^   r   boolr   r$   r8   r;   r9   rS   rX   rm   r   r   r   r   <module>   s.    
		#