o a+@sNdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZdd d Zgd eeeeZiZiZd d ZddZddZddZddZddZd*ddZd+ddZd+ddZdd Zd,d"d#Zd$d%Z d&d'Z!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-2021 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) Python3LexerPython3TracebackLexer)get_lexer_by_nameget_lexer_for_filenamefind_lexer_class guess_lexerload_lexer_from_filecCs8|tvrtt|}t|<||St||S)zBReturn whether the supplied file name fn matches pattern filename.)_pattern_cacherecompilefnmatch translatematch)fnglobpatternr:/usr/lib/python3/dist-packages/pygments/lexers/__init__.py _fn_matches"s rcCs4t|dddg}|jD] }t||}|t|j<q dS)z0Load a lexer (and all others in the module too).N__all__) __import__rgetattr _lexer_cachename) module_namemod lexer_nameclsrrr _load_lexers*s    r&ccsDtD] }|ddVqtD] }|j|j|j|jfVqdS)zoReturn a generator of tuples in the form ``(name, aliases, filenames, mimetypes)`` of all know lexers. N)rvaluesrr!aliases filenames mimetypes)itemlexerrrrget_all_lexers2s   r.cCsf|tvrt|StD]\}}}}}||kr!t|t|Sq tD] }|j|kr0|Sq%dS)zALookup a lexer class by name. Return None if not found. N)r rr(r&rr!)r!r"lnamer)_r%rrrr<s   rcCs~|std|tD]\}}}}}||vr'|tvr!t|t|Sq tD] }||jvr8|Sq+td|)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 foundrrr(lowerr r&rr))_aliasr"r!r)r0r%rrrfind_lexer_class_by_nameNs     r5cKs|std|tD] \}}}}}||vr,|tvr!t|t|di|Sq tD]}||jvrB|di|Sq0td|)zEGet a lexer by an alias. Raises ClassNotFound if not found. r1Nrr2)r4optionsr"r!r)r0r%rrrr ds    r CustomLexerc Ksz6i}t|d}t||Wdn1swY||vr+td||f||}|di|WStyJ}ztd||fd}~wtyQtyb}ztd|d}~ww)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 rbNzno valid %s class found in %szcannot read %s: %sz#error when loading custom lexer: %sr)openexecreadrOSError Exception)filename lexernamer6custom_namespacef lexer_classerrrrrrys(   rc sg}t|}tD]"\}}}}}|D]}t||r+|tvr"t||t||fqq tD]} | jD]}t||rC|| |fq5q0t t rNt fdd} |rb|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|vr dp d}r|||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) _fnrKmatchesrmodnamer!r0r*r>r%rLrrJrfind_lexer_class_for_filenames.        rWcKs(t||}|s td||di|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 foundNr)rWr)rTrKr6resrrrr s  r cKsztD]\}}}}}||vr"|tvrt|t|di|SqtD]}||jvr6|di|Sq&td|)zHGet a lexer for a mimetype. Raises ClassNotFound if not found. zno lexer for mimetype %r foundNr)rr(r r&rr+r)_mimer6rVr!r0r+r%rrrget_lexer_for_mimetypes   r[TccsVttD]}t|dd\}}|tvrt|t|Vq|r)tEdHdSdS)z*Return an iterator over all lexer classes.N)sortedrr r&r)pluginsrNr"r!rrr_iter_lexerclassess  r_c  s t|}it}tD]*}|jD]}t||r!||d|<q|jD]}t||r5||d|<q%q |s?td|t|dkrN| d i|Sg}|D]}| |}|dkrf|d i|S| ||fqRfdd} |j | d|d dd i|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: }') TFrXr'?cs$|d|d|dj|djfSNrr')rGrF)tprimaryrr type_sorts$z+guess_lexer_for_filename..type_sortrMrONr) rsetr_r*raddalias_filenamesrlenpoprErPrS) rT_textr6rmatching_lexersr-r>resultrvrerrcrguess_lexer_for_filenames8            rocKst|ts|d|d}|r||pd}nt|\}}t|}|dur9z t|fi|WSty8Ynwddg}tD]"}| |}|dkrT|d i|S||dkrb||f|dd<q@|drm|ddurqtd |dd i|S) z?Guess a lexer by strong distinctions in the text (eg, shebang). inencodingencodingutf8Ngr`rr'z no lexer matching the text foundr) rQstrgetdecoderrr rr_rE)rkr6rpr0ft best_lexerr-rnrrrr#s.      rc@seZdZdZddZdS) _automodulezAutomatically import lexers.cCsTt|}|rt|dt|d}t||||S|tvr&t|t|St|ra)rrtr&r setattrCOMPATrAttributeError)selfr!rHr%rrr __getattr__Es    z_automodule.__getattr__N)rF __module__ __qualname____doc__r}rrrrrxBs rx)r7)N)T)*rrsystypesros.pathrpygments.lexers._mappingrpygments.modelinerpygments.pluginr pygments.utilrrrzlistrr rrr&r.rr5r rrWr r[r_ror ModuleTyperxmodulesrFoldmodnewmod__dict__updaterrrrsN        # +  3