bg0H dZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZmZdd lmZddlZddlZdd lmZed eeZgd ZGd deZedddddedddddedddddeddd d!d"ed#d$d%d&d'ed(d)d*d+d,gZd-eDZdVd3Z dWdXd:Z ej!ej"ej#ej$ej%ej&ej'd;Z(ed<d=DZ)ej*d>ej+?Z,dYd@Z-dZdDZ.d[dFZ/d\dGZ0e dHId[dJZ1d]dMZ2d^dOZ3GdPdQej4Z5d_dUZ6dS)`a2Unicode and some other ASCII characters can be used to create programs that run much different compared to what a human reader would expect from them. PEP 672 lists some examples. See: https://www.python.org/dev/peps/pep-0672/ The following checkers are intended to make users are aware of these issues. ) annotationsN) OrderedDict)Iterable) lru_cache)detect_encoding) NamedTupleTypeVar)nodes)checkers_StrLike) u‪u‫u‬u‭u‮u⁦u⁧u⁨u⁩u‏cVeZdZUdZded<ded<ded<ded<ded<d d Zd d Zd S) _BadCharz/Representation of an ASCII char considered bad.strname unescapedescapedcode help_textreturnc(d|jd|jdS)z0Used for the detailed error message description.zInvalid unescaped character z, use "z " instead.)rrselfs h/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/checkers/unicode.py descriptionz_BadChar.descriptionCs. -49 - -L - - - cd|jS)z2Used to generate the human readable error message.zinvalid-character-)rrs r human_codez_BadChar.human_codeJs/DI///rN)rr)__name__ __module__ __qualname____doc____annotations__rrrrrr:sq99 IIINNNLLL IIINNN    000000rr backspacez\bE2510zUMoves the cursor back, so the character after it will overwrite the character before.zcarriage-return z\rE2511z]Moves the cursor to the start of line, subsequent characters overwrite the start of the line.subz\x1AE2512zcCtrl+Z "End of text" on Windows. Some programs (such as type) ignore the rest of the file after it.escz\x1BE2513zNCommonly initiates escape codes which allow arbitrary control of the terminal.nulz\0E2514zMostly end of input for python.zzero-width-spaceu​z\u200BE2515z9Invisible space character could hide real code execution.ci|] }|j| Sr#)r).0chars r r6sDDD$DDDrlinecodecrrintct|tr%t|||d}n|}|d}||kr|d}t |S)z?Get the length of a string like line as displayed in an editor.replace r') isinstancebytes _remove_bomdecoderstriplen)r7r8decodedstrippeds r _line_lengthrEss$dE**11%CC~~d##H7??4(( x==r search_dictdict[_StrLike, _BadChar]new_linebyte_str_lengthdict[int, _BadChar]cpi}|D]\}}||vr |jdkr+||rt|d|zz }nd}d}|||} | dkr>| |krt | |z } ||| <| dz}|||} | dk>|S)zGet all occurrences of search dict keys within line. Ignores Windows end of line and can handle bytes as well as string. Also takes care of encodings for which the length of an encoded code point does not default to 8 Bit. r'NrrF)itemsrendswithrBfindr9) r7rGrIrJresult search_forr5 ignore_posstartposcols r_map_positions_to_resultrWs#%F'--//// D T ! !  >T ! !dmmH&=&= !TQ%88JJJii E**Aggj  #/00"s !GE))J..C Agg Mr)utf-8utf-16utf-32utf-16leutf-16beutf-32leutf-32bec#4K|]}t||fVdSN) UNICODE_BOMS)r4r8s r rbsB"" %% """"""r)r]r^rXr[r\z%utf[ -]?(8|16|32)[ -]?(le|be|)?(sig)?)flagsc\td|S)zDMake sure the codec name is always given as defined in the BOM dict.zutf-\1\2)UTF_NAME_REGEX_COMPILEDr)lowerr8s r_normalize_codec_namerhs$ " & &{E : : @ @ B BBrencodedr>encodingc|tvr|St|}||r|t|dS|S)z$Remove the bom if given from a line.N)ra startswithrB)rirjboms rr?r?sL|## x C##s3xxzz"" NrstringcHt|||S)z#Encode a string but remove the BOM.)r?encodernrjs r_encode_without_bomrrs v}}X.. 9 99rcb|drdS|drdSdS)z6Return how many byte are usually(!) a character point.rZrYrMrFrlrgs r_byte_to_str_lengthrvs= !!q !!q 1ri)maxsizec"t||S)z3A cached version of encode used for search pattern.)rrrqs r_cached_encode_searchrys vx 0 00rsteamIterable[bytes]c#K|ds|ds |Ed{VdSdd|D}td|}d} |||}|dkr|||t |zVn||dr ||dVdS|t |z}d)zHandle line ending for UTF16 and UTF32 correctly. Currently, Python simply strips the required zeros after after the line ending. Leading to lines that can't be decoded properly rYrZNrc3K|]}|VdSr`r#)r4r7s rrbz,_fix_utf16_32_line_stream..s"22D4222222rr<r)rljoinryrPrB)rzr8contentrIrTrUs r_fix_utf16_32_line_streamrs   H % %(e.>.>x.H.H(((22E22222(u55 (,,x//CaxxecCMM&99:::::566?*!%&&/)))#h--'E (r first_linectD]\}}||r|cStd)aTry to extract the codec (unicode only) by checking for the BOM. For details about BOM see https://unicode.org/faq/utf_bom.html#BOM Args: first_line: the first line of a file Returns: a codec name Raises: ValueError: if no codec was found z-No BOM found. Could not detect Unicode codec.)BOM_SORTED_TO_CODECrNrl ValueError)rrmr8s rextract_codec_from_bomrsX*//11 U   % % LLL  D E EErceZdZdZdZdddddeDZed!d Zed!d Z e d"dZ ed#dZ d$dZ d%dZd%dZd&dZd S)'UnicodeCheckeraCheck characters that could be used to hide bad code to humans. This includes: - Bidirectional Unicode (see https://trojansource.codes/) - Bad ASCII characters (see PEP672) If a programmer requires to use such a character they should use the escaped version, that is also much easier to read and does not depend on the editor used. The Checker also includes a check that UTF-16 and UTF-32 are not used to encode Python files. At the time of writing Python supported only UTF-8. See https://stackoverflow.com/questions/69897842/ and https://bugs.python.org/issue1503789 for background. unicode_checker)z?UTF-16 and UTF-32 aren't backward compatible. Use UTF-8 insteadinvalid-unicode-codeczFor compatibility use UTF-8 instead of UTF-16/UTF-32. See also https://bugs.python.org/issue1503789 for a history of this issue. And https://softwareengineering.stackexchange.com/questions/102205/ for some possible problems when using UTF-16 for instance.)z_Contains control characters that can permit obfuscated code executed differently than displayedbidirectional-unicodeabidirectional unicode are typically not displayed characters required to display right-to-left (RTL) script (i.e. Chinese, Japanese, Arabic, Hebrew, ...) correctly. So can you trust this code? Are you sure it displayed correctly in all editors? If you did not write it or your language is not RTL, remove the special characters, as they could be used to trick you into executing code, that does something else than what it looks like. More Information: https://en.wikipedia.org/wiki/Bidirectional_text https://trojansource.codes/)z2PEP8 recommends UTF-8 as encoding for Python filesbad-file-encodingzsPEP8 recommends UTF-8 default encoding for Python files. See https://peps.python.org/pep-0008/#source-file-encoding)E2501E2502C2503cvi|]6}|j|||jf7Sr#)rrrr)r4bad_chars rr6zUnicodeChecker.nsU    M$$&&##%%"   rr8rrboolcV|dp|dS)NrYrZrurgs r_is_invalid_codecz UnicodeChecker._is_invalid_codecxs)))GU-=-=h-G-GGrc,|dS)Nutfrurgs r _is_unicodezUnicodeChecker._is_unicode|s&&&rr7r>rKc  ||d}t}t||dS#t$r|}i}tD]K}t jt5||t|j|<dddn #1swxYwYLt||td|t|cYSwxYw)zFind all matches of BAD_CHARS within line. Args: line: the input codec: that will be used to convert line/or search string into Return: A dictionary with the column offset and the BadASCIIChar strict)errorsr<N)rJ) r@BAD_ASCII_SEARCH_DICTrWUnicodeDecodeError BAD_CHARS contextlibsuppressryrrv)clsr7r8 line_searchrGline_search_bytesearch_dict_byter5s r_find_line_matchesz!UnicodeChecker._find_line_matchess2 ++eH+==K/K+KdKK K!    $ 68 !  ();<<%-dneDD ,  %dE22 3E : :     s3.10C!B: CB C B 2CCstream io.BytesIOtuple[str, int]cD t|j\}}t|pd}nf#t$rY}|d t |}d}n#t $r}||d}~wwxYwYd}~nd}~wwxYwt||fS)aDetermine the codec from the given stream. first tries https://www.python.org/dev/peps/pep-0263/ and if this fails also checks for BOMs of UTF-16 and UTF-32 to be future-proof. Args: stream: The byte stream to analyse Returns: A tuple consisting of: - normalized codec name - the line in which the codec was found Raises: SyntaxError: if failing to detect codec rFrN)rreadlinerB SyntaxErrorseekrrrh)rr8linescodec_definition_lineeves r_determine_codeczUnicodeChecker._determine_codecs$ +6?;;LE5%(JJO! ! !  KKNNN .v/@/@AA()%%   R &%%%% %U++-BBBs8(+ BB  #A/.B / B9A<<BB  Brr9Nonec|dkrEd}||rd}||||tjjdddSdS)zCheck validity of the codec.rXrrNr7 end_lineno confidence col_offsetend_col_offset)r add_messagepylint interfacesHIGH)rr8rmsgs r _check_codeczUnicodeChecker._check_codecsv G  %C%%e,, .-   +0!,1#        rlinenoc |||}|D]\\}}||||tjj|dz|t|jzdz]dS)zLook for chars considered bad.rFrN) rrNrrrrrrBr)rr7rr8matchesrVr5s r_check_invalid_charsz#UnicodeChecker._check_invalid_charss))$66   IC   !!!!,17"S%8%881<       rc ||sdStD]O}t|||vr;|d||dt ||t jjdSPdS)z2Look for Bidirectional Unicode, if we use unicode.Nrr)r7rrrr)r BIDI_UNICODEryrrErrr)rr7rr8 dangerouss r_check_bidi_charsz UnicodeChecker._check_bidi_charss&&  F%  I$Y66$>>   + % !#/e#<#<%05!   '?  rnode nodes.Modulec|5}||\}}||||dt t ||dD]I\}}|dkrt ||}||||||||J ddddS#1swxYwYdS)z3Perform the actual check by checking module stream.rrF)rTN) rrrr enumeraterr?rr)rrrr8 codec_linerr7s rprocess_modulezUnicodeChecker.process_modules3 [[]] ?f $ 5 5f = = E:   eZ 0 0 0 KKNNN!*)&%88!!! ? ? Q;;&tU33D&&tVU;;;))$>>>>  ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sB-CCCN)r8rrr)r7r>r8rrrK)rrrr)r8rrr9rr)r7r>rr9r8rrr)rrrr)rrr r!rrmsgs staticmethodrr classmethodrrrrrrr#rrrr-sA& D   * G3 3 V  &    W3 DjHHH\H'''\'!!![!F&C&C&C\&CP"    4??????rrlinterpylint.lint.PyLinterrcJ|t|dSr`)register_checkerr)rs rregisterrs$ N62233333r)r7r r8rrr9)rF) r7r rGrHrIr rJr9rrK)r8rrr)rir>rjrrr>)rnrrjrrr>)r8rrr9)rzr{r8rrr{)rr>rr)rrrr)7r! __future__rcodecsriore collectionsrcollections.abcr functoolsrtokenizertypingrr astroidr pylint.interfacesr pylint.lintr rr>r rrrrrErWBOM_UTF8 BOM_UTF16 BOM_UTF32 BOM_UTF16_LE BOM_UTF16_BE BOM_UTF32_LE BOM_UTF32_BErarcompile IGNORECASErerhr?rrrvryrrBaseRawFileCheckerrrr#rrrs #"""""  ######$$$$$$$$$$$$&&&&&&&& 7:sE * *  *00000z000. H     H   %   H  -   H     H   )  H Ca9  tED)DDD    & #####N_#### "k""K""" %"*+2= CCCC ::::      41111 ((((<FFFF*i?i?i?i?i?X0i?i?i?X444444r