Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
asc.py56 linesDownload Raw Back to lexers
1"""2    pygments.lexers.asc3    ~~~~~~~~~~~~~~~~~~~4 5    Lexer for various ASCII armored files.6 7    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10import re11 12from pygments.lexer import RegexLexer, bygroups13from pygments.token import Comment, Generic, Name, Operator, String, Whitespace14 15__all__ = ['AscLexer']16 17 18class AscLexer(RegexLexer):19    """20    Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped21    base64 data.22    """23    name = 'ASCII armored'24    aliases = ['asc', 'pem']25    filenames = [26        '*.asc',  # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary27        '*.pem',  # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary28        'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk',29        'id_rsa',  # SSH private keys30    ]31    mimetypes = ['application/pgp-keys', 'application/pgp-encrypted',32                 'application/pgp-signature', 'application/pem-certificate-chain']33    url = 'https://www.openpgp.org'34    version_added = '2.10'35 36    flags = re.MULTILINE37 38    tokens = {39        'root': [40            (r'\s+', Whitespace),41            (r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'),42            (r'\S+', Comment),43        ],44        'data': [45            (r'\s+', Whitespace),46            (r'^([^:]+)(:)([ \t]+)(.*)',47             bygroups(Name.Attribute, Operator, Whitespace, String)),48            (r'^-----END [^\n]+-----$', Generic.Heading, 'root'),49            (r'\S+', String),50        ],51    }52 53    def analyse_text(text):54        if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text):55            return True56 
codekingpro/portable-devtools · Team Ai