Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/future/backports/email/__init__.py: 57%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

21 statements  

1# Copyright (C) 2001-2007 Python Software Foundation 

2# Author: Barry Warsaw 

3# Contact: email-sig@python.org 

4 

5""" 

6Backport of the Python 3.3 email package for Python-Future. 

7 

8A package for parsing, handling, and generating email messages. 

9""" 

10from __future__ import unicode_literals 

11from __future__ import division 

12from __future__ import absolute_import 

13 

14# Install the surrogate escape handler here because this is used by many 

15# modules in the email package. 

16from future.utils import surrogateescape 

17surrogateescape.register_surrogateescape() 

18# (Should this be done globally by ``future``?) 

19 

20 

21__version__ = '5.1.0' 

22 

23__all__ = [ 

24 'base64mime', 

25 'charset', 

26 'encoders', 

27 'errors', 

28 'feedparser', 

29 'generator', 

30 'header', 

31 'iterators', 

32 'message', 

33 'message_from_file', 

34 'message_from_binary_file', 

35 'message_from_string', 

36 'message_from_bytes', 

37 'mime', 

38 'parser', 

39 'quoprimime', 

40 'utils', 

41 ] 

42 

43 

44 

45# Some convenience routines. Don't import Parser and Message as side-effects 

46# of importing email since those cascadingly import most of the rest of the 

47# email package. 

48def message_from_string(s, *args, **kws): 

49 """Parse a string into a Message object model. 

50 

51 Optional _class and strict are passed to the Parser constructor. 

52 """ 

53 from future.backports.email.parser import Parser 

54 return Parser(*args, **kws).parsestr(s) 

55 

56def message_from_bytes(s, *args, **kws): 

57 """Parse a bytes string into a Message object model. 

58 

59 Optional _class and strict are passed to the Parser constructor. 

60 """ 

61 from future.backports.email.parser import BytesParser 

62 return BytesParser(*args, **kws).parsebytes(s) 

63 

64def message_from_file(fp, *args, **kws): 

65 """Read a file and parse its contents into a Message object model. 

66 

67 Optional _class and strict are passed to the Parser constructor. 

68 """ 

69 from future.backports.email.parser import Parser 

70 return Parser(*args, **kws).parse(fp) 

71 

72def message_from_binary_file(fp, *args, **kws): 

73 """Read a binary file and parse its contents into a Message object model. 

74 

75 Optional _class and strict are passed to the Parser constructor. 

76 """ 

77 from future.backports.email.parser import BytesParser 

78 return BytesParser(*args, **kws).parse(fp)