U ʗRe,@sVdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZdd d Zd d d ddgeeeeZiZiZddZddZd)ddZdd ZddZdd Zd*ddZd+ddZd,dd Zd d!Zd-d"d#Zd$d%Z d&dZ!Gd'd(d(ej"Z#ej$e%Z&e#e%Z'e'j()e&j(e'ej$e%<e'`'e'`&e'`e'`dS).z pygments.lexers ~~~~~~~~~~~~~~~ Pygments lexers. :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N)basename)LEXERS)get_filetype_from_buffer)find_plugin_lexers) ClassNotFound guess_decode PythonLexerPythonTracebackLexer) Python3LexerPython3TracebackLexerget_lexer_by_nameget_lexer_for_filenamefind_lexer_class guess_lexerload_lexer_from_filecCs8|tkr*tt|}t|<||St||S)zBReturn whether the supplied file name fn matches pattern filename.)_pattern_cacherecompilefnmatch translatematch)fnglobpatternr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/pygments/lexers/__init__.py _fn_matches"s rcCs4t|dddg}|jD]}t||}|t|j<qdS)z0Load a lexer (and all others in the module too).N__all__) __import__rgetattr _lexer_cachename) module_namemod lexer_nameclsrrr _load_lexers*s  r&TccsFtD]}|ddVq|rBtD]}|j|j|j|jfVq&dS)aReturn a generator of tuples in the form ``(name, aliases, filenames, mimetypes)`` of all know lexers. If *plugins* is true (the default), plugin lexers supplied by entrypoints are also returned. Otherwise, only builtin ones are considered. N)rvaluesrr!aliases filenames mimetypes)pluginsitemlexerrrrget_all_lexers2s   r/cCsf|tkrt|StD]*\}}}}}||krt|t|SqtD]}|j|krJ|SqJdS)zALookup a lexer class by name. Return None if not found. N)r rr(r&rr!)r!r"lnamer)_r%rrrr@s  cCs|std|tD]6\}}}}}||kr|tkrBt|t|SqtD]}||jkrV|SqVtd|dS)zLookup a lexer class by alias. Like `get_lexer_by_name`, but does not instantiate the class. .. versionadded:: 2.2 no lexer for alias %r foundNrrr(lowerr r&rr))_aliasr"r!r)r1r%rrrfind_lexer_class_by_nameRs    r6cKs|std|tD]<\}}}}}||kr|tkrBt|t|f|SqtD] }||jkr\|f|Sq\td|dS)zEGet a lexer by an alias. Raises ClassNotFound if not found. r2Nr3)r5optionsr"r!r)r1r%rrrr hs    CustomLexerc KszTi}t|d}t||W5QRX||krBtd||f||}|f|WStk r}ztd||fW5d}~XYnBtk rYn.tk r}ztd|W5d}~XYnXdS)aLoad a lexer from a file. This method expects a file located relative to the current working directory, which contains a Lexer class. By default, it expects the Lexer to be name CustomLexer; you can specify your own class name as the second argument to this function. Users should be very careful with the input, because this method is equivalent to running eval on the input file. Raises ClassNotFound if there are any problems importing the Lexer. .. versionadded:: 2.2 rbzno valid %s class found in %szcannot read %s: %sNz#error when loading custom lexer: %s)openexecreadrOSError Exception)filename lexernamer7custom_namespacef lexer_classerrrrrr}s    c sg}t|}tD]D\}}}}}|D]0}t||r&|tkrDt||t||fq&qtD](} | jD]}t||rj|| |fqjq`t t rt fdd} |r|j | d|ddSdS)zGet a lexer for a filename. If multiple lexers match the filename pattern, use ``analyse_text()`` to figure out which one is more appropriate. Returns None if not found. cs@|\}}d|krdpd}r0|||jfS|j||jfS)N*g?r) analyse_text__name__priority)infor%r?bonuscoderr get_ratings z1find_lexer_class_for_filename..get_ratingkeyrN) rrr(rr r&appendrr* isinstancebytesrsort) _fnrLmatchesrmodnamer!r1r*r?r%rMrrKrfind_lexer_class_for_filenames$       rXcKs$t||}|std||f|S)zGet a lexer for a filename. If multiple lexers match the filename pattern, use ``analyse_text()`` to figure out which one is more appropriate. Raises ClassNotFound if not found. no lexer for filename %r found)rXr)rUrLr7resrrrr s  cKsvtD]8\}}}}}||kr|tkr.t|t|f|SqtD]}||jkrH|f|SqHtd|dS)zHGet a lexer for a mimetype. Raises ClassNotFound if not found. zno lexer for mimetype %r foundN)rr(r r&rr+r)_mimer7rWr!r1r+r%rrrget_lexer_for_mimetypes  r\ccsPttD]2}t|dd\}}|tkr0t|t|Vq|rLtEdHdS)z*Return an iterator over all lexer classes.N)sortedrr r&r)r,rOr"r!rrr_iter_lexerclassess  r_c  st|}it}tD]T}|jD] }t||r"||d|<q"|jD] }t||rJ||d|<qJq|s~td|t|dkr| f|Sg}|D]2}| |}|dkr|f|S| ||fqfdd} |j | d|d df|S) a Lookup all lexers that handle those filenames primary (``filenames``) or secondary (``alias_filenames``). Then run a text analysis for those lexers and choose the best result. usage:: >>> from pygments.lexers import guess_lexer_for_filename >>> guess_lexer_for_filename('hello.html', '<%= @foo %>') >>> guess_lexer_for_filename('hello.html', '

{{ title|e }}

') >>> guess_lexer_for_filename('style.css', 'a { color: }') TFrYr'?cs$|d|d|dj|djfSNrr')rHrG)tprimaryrr type_sortsz+guess_lexer_for_filename..type_sortrNrP) rsetr_r*raddalias_filenamesrlenpoprFrQrT) rU_textr7rmatching_lexersr.r?resultrvrerrcrguess_lexer_for_filenames2              rocKst|ts<|d|d}|r0||p*d}n t|\}}t|}|dk rpzt|f|WStk rnYnXddg}tD]@}| |}|dkr|f|S||dkr~||f|dd<q~|dr|ddkrtd |df|S) z?Guess a lexer by strong distinctions in the text (eg, shebang). inencodingencodingutf8Ngr`rr'z no lexer matching the text found) rRstrgetdecoderrr rr_rF)rkr7rpr1ft best_lexerr.rnrrrr's*     c@seZdZdZddZdS) _automodulezAutomatically import lexers.cCsXt|}|r6t|dt|d}t||||S|tkrLt|t|St|dSra)rrtr&r setattrCOMPATrAttributeError)selfr!rIr%rrr __getattr__Is    z_automodule.__getattr__N)rG __module__ __qualname____doc__r}rrrrrxFsrx)T)r8)N)N)T)*rrsystypesros.pathr$pip._vendor.pygments.lexers._mappingrpip._vendor.pygments.modelinerpip._vendor.pygments.pluginrpip._vendor.pygments.utilrrrzlistrr rrr&r/rr6r rrXr r\r_ror ModuleTyperxmodulesrGoldmodnewmod__dict__updaterrrrsR       # +  3