| | """ |
| | pygments.lexers.asc |
| | ~~~~~~~~~~~~~~~~~~~ |
| | |
| | Lexer for various ASCII armored files. |
| | |
| | :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. |
| | :license: BSD, see LICENSE for details. |
| | """ |
| | import re |
| |
|
| | from pygments.lexer import RegexLexer, bygroups |
| | from pygments.token import Comment, Generic, Name, Operator, String, Whitespace |
| |
|
| | __all__ = ['AscLexer'] |
| |
|
| |
|
| | class AscLexer(RegexLexer): |
| | """ |
| | Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped |
| | base64 data. |
| | |
| | .. versionadded:: 2.10 |
| | """ |
| | name = 'ASCII armored' |
| | aliases = ['asc', 'pem'] |
| | filenames = [ |
| | '*.asc', |
| | '*.pem', |
| | 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', |
| | 'id_rsa', |
| | ] |
| | mimetypes = ['application/pgp-keys', 'application/pgp-encrypted', |
| | 'application/pgp-signature', 'application/pem-certificate-chain'] |
| |
|
| | flags = re.MULTILINE |
| |
|
| | tokens = { |
| | 'root': [ |
| | (r'\s+', Whitespace), |
| | (r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'), |
| | (r'\S+', Comment), |
| | ], |
| | 'data': [ |
| | (r'\s+', Whitespace), |
| | (r'^([^:]+)(:)([ \t]+)(.*)', |
| | bygroups(Name.Attribute, Operator, Whitespace, String)), |
| | (r'^-----END [^\n]+-----$', Generic.Heading, 'root'), |
| | (r'\S+', String), |
| | ], |
| | } |
| |
|
| | def analyse_text(text): |
| | if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text): |
| | return True |
| |
|