Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f30a8a

Browse files
committed
__version__: Bump to 2.4
Move the imports of Parser and Message inside the message_from_string() and message_from_file() functions. This way just "import email" won't suck in most of the submodules of the package. Note: this will break code that relied on "import email" giving you a bunch of the submodules, but that was never documented and should not have been relied on.
1 parent d80032b commit 6f30a8a

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Lib/email/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""A package for parsing, handling, and generating email messages.
55
"""
66

7-
__version__ = '2.3.1'
7+
__version__ = '2.4'
88

99
__all__ = ['Charset',
1010
'Encoders',
@@ -28,12 +28,19 @@
2828

2929

3030

31-
# Some convenience routines
32-
from email.Parser import Parser as _Parser
33-
from email.Message import Message as _Message
31+
# Some convenience routines. Don't import Parser and Message as side-effects
32+
# of importing email since those cascadingly import most of the rest of the
33+
# email package.
34+
def message_from_string(s, _class=None, strict=0):
35+
from email.Parser import Parser
36+
if _class is None:
37+
from email.Message import Message
38+
_class = Message
39+
return Parser(_class, strict=strict).parsestr(s)
3440

35-
def message_from_string(s, _class=_Message, strict=0):
36-
return _Parser(_class, strict=strict).parsestr(s)
37-
38-
def message_from_file(fp, _class=_Message, strict=0):
39-
return _Parser(_class, strict=strict).parse(fp)
41+
def message_from_file(fp, _class=None, strict=0):
42+
from email.Parser import Parser
43+
if _class is None:
44+
from email.Message import Message
45+
_class = Message
46+
return Parser(_class, strict=strict).parse(fp)

0 commit comments

Comments
 (0)