ZL i3 LUdZddlZddlZddlmZddlmZmZddlmZddl m Z ddl m Z dZ eed <ejd e zd zej Zeed <ejd ej$Zeed<deedededefdZdedefdZdedeefdZdededefdZdedefdZdeddfdZdedefdZedd edeefd!Zdedefd"Zd#ed$ee d%ede ee effd&Z!d'e ddfd(Z"ed)d*ede#fd+Z$d,ede#fd-Z%d,ed.e#de#fd/Z&y)0zN Simple formatting on strings. Further string formatting code is in trans.py. N) lru_cache)MatchPattern)Final) WIDTH_TABLE)Leaf fturbFTURBSTRING_PREFIX_CHARSz^([z]*)(.*)$STRING_PREFIX_REz(?P\\+)(?P(u(?P[a-fA-F0-9]{4}))|(U(?P[a-fA-F0-9]{8}))|(x(?P[a-fA-F0-9]{2}))|(N\{(?P[a-zA-Z0-9 \-]{2,})\}))UNICODE_ESCAPE_REregex replacementoriginalreturncF|j||j||S)zReplace `regex` with `replacement` twice on `original`. This is used by string normalization to perform replaces on overlapping matches. )sub)r rrs S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/black/strings.py sub_twicers 99[%))K"B CCstringc:|jt}|dddvS)zS Returns: True iff @string starts with three quotation characters. N>"""''')lstripr )r raw_strings rhas_triple_quotesr&s$ 23J bq>^ ++rscFg}|jD]i}|j}|r||k(r|j|,t|t|z }|d|j }|j||zk|j dr|jd|S)zh Splits string into lines and expands only leading tabs (following the normal Python rules) N ) splitlinesrappendlen expandtabsendswith)rlinesline stripped_line prefix_lengthprefixs r lines_with_leading_tabs_expandedr,/s E 1   5 LL IM(::M.=)446F LL-/ 01 zz$ R Lr docstringr+c|sJdt|}tj}|ddD]6}|j}|st |t |t |z }8|dj g}|tjkrdt |dz }t|ddD]E\}}||dj} | s||k(r|j|| z5|jdGdj|S)Nz4INTERNAL ERROR: Multiline docstrings cannot be emptyrr!r ) r,sysmaxsizerminr$strip enumeraterstripr#join) r-r+r'indentr(strippedtrimmed last_line_idxir)s rfix_multiline_docstringr=Bs LLL9 ,Y 7E [[Fab <;;= TS]!:;F< Qx~~ G  E Q  qr+ #GAt M002M] 2v 56r"  # 99W rct|g}|D]}|tvr|j|ndj|S)z Pre-conditions: * assert_is_leaf_string(@string) Returns: @string's prefix (e.g. '', 'r', 'f', or 'rf'). r!)assert_is_leaf_stringr r#r7)rr+chars rget_string_prefixrAYsH&! F & & MM$    776?rc|jd}|jd}d||fvr t||}n t||}d|cxkrt|dz ks nJ|d|ddvs J|dt |d |j t t s&Jt |d |d t t d y ) 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 ', ", ', or " where `set()` 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. "'rr/z0 is missing a starting quote character (' or ").)rDrCz/ is missing an ending quote character (' or ").Nz is NOT a subset of .)findmaxr3r$setissubsetr )r dquote_idx squote_idx quote_idxs rr?r?ls S!JS!J j* %% J/  J/  Y(Vq(F DEF( ": E CDE  vjy! " + +   S fZi ! ""6s;N7O6PPQRS rcltj|}| Jd||jd}|jddjddjdd jd d }t |d k(r|d j d k7r|ddd}||jd S)z#Make all string prefixes lowercase.Nzfailed to match string r/FfBbUr!ur0rrrE)r matchgroupreplacer$lower)rrV orig_prefix new_prefixs rnormalize_string_prefixr\s  " "1 %E  = 7u== ++a.KC% c  b  b   :! 1 3 3 5 <"% \%++a.) **r@)r2patternc,tj|S)N)recompile)r^s r_cached_compilerbs ::g rch|jt}|dddk(r|S|dddk(rd}d}n|ddk(rd}d}nd}d}|j|}|dk7s Jd ||d|}td |}td |}td |}||t |zt | } d |j vr|j | r|S| } nAt|d || } | | k7r | } ||| |}t|d || } t|d|| } d|j vr=tjd| tj} | D]} dt| vs|cS|dk(r| dddk(r| dddz} | jd} | jd}|| kDr|S|| k(r|dk(r|S||| |S)vPrefer double quotes but only if it doesn't cause more escaping. Adds or removes backslashes as appropriate. NrrrrrCrDrEz!INTERNAL ERROR: Malformed string (([^\\]|^)(\\\\)*)([^\\]|^)\\((?:\\\\)*)rU\1\2\1\\rPz (?:(?.replace:sm, | q A %&.0 0 #;#%s (9(9(;; ; C[#%s (9(9(;; ; C[#%s (9(9(;; ;#; 8"4QC 8 8;$&):):)<rs * )U)$"**  ;. %&2:: JJ5DWS\DDsDsD,c,d,S &sCC.cc& S# S$ SF+s+s+* 2SWS\F7sF7sF7R> > $Z>> 4:s? >B:T:d:> 4 S S  4 * * * 3 3 3 r