Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/asc.py: 86%

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-03 06:10 +0000

1""" 

2 pygments.lexers.asc 

3 ~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for various ASCII armored files. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10import re 

11 

12from pygments.lexer import RegexLexer, bygroups 

13from pygments.token import Comment, Generic, Name, Operator, String, Whitespace 

14 

15__all__ = ['AscLexer'] 

16 

17 

18class AscLexer(RegexLexer): 

19 """ 

20 Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped 

21 base64 data. 

22 

23 .. versionadded:: 2.10 

24 """ 

25 name = 'ASCII armored' 

26 aliases = ['asc', 'pem'] 

27 filenames = [ 

28 '*.asc', # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary 

29 '*.pem', # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary 

30 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 

31 'id_rsa', # SSH private keys 

32 ] 

33 mimetypes = ['application/pgp-keys', 'application/pgp-encrypted', 

34 'application/pgp-signature'] 

35 

36 flags = re.MULTILINE 

37 

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 True