jf8dZddlmZ ddlZddlmZddlmZdZn #e $rdZYnwxYwgdZ Gd d eZ Gd d Z Gd dZ dS)z@Lexical analysis of formal languages (i.e. code) using Pygments.)ApplicationErrorN)get_lexer_by_name)_get_ttype_classTF)tokentextceZdZdS) LexerErrorN)__name__ __module__ __qualname__|/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/code_analyzer.pyr r sDrr c&eZdZdZddZdZdZdS)LexeraParse `code` lines and yield "classified" tokens. Arguments code -- string of source code to parse, language -- formal language the code is written in, tokennames -- either 'long', 'short', or 'none' (see below). Merge subsequent tokens of the same token-type. Iterating over an instance yields the tokens as ``(tokentype, value)`` tuples. The value of `tokennames` configures the naming of the tokentype: 'long': downcased full token type name, 'short': short name defined by pygments.token.STANDARD_TYPES (= class argument used in pygments html output), 'none': skip lexical analysis. shortc ||_||_||_d|_|dvs|dkrdStst d t |j|_dS#tjj $rt d|zwxYw)zE Set up a lexical analyzer for `code` in `language`. N)rrnonez0Cannot analyze code. Pygments package not found.z6Cannot analyze code. No Pygments lexer found for "%s".) codelanguage tokennameslexer with_pygmentsr rpygmentsutil ClassNotFound)selfrrrs r__init__zLexer.__init__/s   $ | # #zV';'; F <;<< < M*4=99DJJJ}* M M MACKLMM M Ms A'Bc#Kt|}t|\}}|D]\}}||ur||z }||fV||}}|dr |dd}|r||fVdSdS)zrMerge subsequent tokens of same token-type. Also strip the final newline (added by pygments).  N)iternextendswith)rtokenslasttypelastvalttypevalues rmergez Lexer.mergeJs f"6ll7" 5 5LE5  5 ''''',e7   D ! ! #crclG  $G# # # # # # $ $rc#jK|j g|jfVdStj|j|j}||D]g\}}|jdkr5t |d}nt|g}d|D}||fVhdS)z7Parse self.code and yield "classified" tokens. Nlong.c$g|] }|tv |Sr)unstyled_tokens).0clss r z"Lexer.__iter__..hs"LLLsO1K1Ks1K1K1Kr) rrrlexr+rstrlowersplitr)rr& tokentyper*classess r__iter__zLexer.__iter__\s : di-    Fdi44 $ 6 2 2 ! ! Iu&((i....0066s;;+I667LLgLLLG5.  ! !rN)r)r r r __doc__rr+r:rrrrrsT&MMMM6$$$$ ! ! ! ! !rrceZdZdZdZdZdS) NumberLinesaqInsert linenumber-tokens at the start of every code line. Arguments tokens -- iterable of ``(classes, value)`` tuples startline -- first line number endline -- last line number Iterating over an instance yields the tokens with a ``(['ln'], '')`` token added for every code line. Multi-line tokens are split.cj||_||_dtt|z|_dS)Nz%%%dd )r& startlinelenr5fmt_str)rr&r?endlines rrzNumberLines.__init__ys. "#c'll"3"33 rc#K|j}dg|j|zfV|jD]P\}}|d}|ddD]}||dzfV|dz }dg|j|zfV ||dfVQdS)Nlnr!r")r?rAr&r7)rlinenor)r*lineslines rr:zNumberLines.__iter__sfdlV+++++ K # #LE5KK%%Ecrc  4 4TD[((((! fdlV333333r" " " " "  # #rN)r r r r;rr:rrrr=r=ls< $ $444 # # # # #rr=)r;docutilsrrpygments.lexersrpygments.formatters.htmlrr ImportErrorr0r rr=rrrrMs GF%%%%%%OOO111111999999MMMMM      !   N!N!N!N!N!N!N!N!b##########s ''