classification
Title: MIMEApplication cannot access
Type: Stage: resolved
Components: email, Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: barry, r.david.murray, yinian1992
Priority: normal Keywords: patch

Created on 2012-10-05 20:10 by yinian1992, last changed 2012-10-06 05:38 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
__init__.patch yinian1992, 2012-10-05 20:10 patch review
Messages (4)
msg172126 - (view) Author: Aifen Qin (yinian1992) * Date: 2012-10-05 20:10
I have a python 2.7.3 installation both on Debian 6 and Windows 7. And under both environment email.mime.application cannot access.

>>> email.mime.application
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'application'

It seems that the import list of email module's __init__.py doesn't include it.
msg172131 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-10-05 20:24
This is by design.  If you want to load the application module, you have to do so explicitly:

  import email.mime.application

This is similar to the way many other packages are organized.  An __init__ file importing a submodule is the (relatively) exceptional case rather than the common case.  This is so that applications that do not need particular submodules do not incur the performance and memory hit of importing those submodules implicitly.
msg172169 - (view) Author: Aifen Qin (yinian1992) * Date: 2012-10-06 05:02
These MIME except MIMEApplication can be directly accessed.

>>> import email
>>> email.mime.Text
<email.LazyImporter object at 0xb755d20c>
>>> email.mime.Application
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Application'

According to Lib\email\__init__.py, it uses LazyImporter to deal with name mapping from new-style names to old-style name, and the _MIMENAMES list just doesn't include 'Application'. This causes the behavior inconformity. As issue1424065, the MIMEApplication added after other MIME class.
msg172170 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-10-06 05:38
Ah, I'd forgotten python2 email used the lazy importer.  We dropped that in python3.

I don't think that I want to fix this, since you have to do the import in python3 anyway.
History
Date User Action Args
2012-10-06 05:38:19r.david.murraysetnosy: + barry
messages: + msg172170
components: + email
2012-10-06 05:02:40yinian1992setmessages: + msg172169
2012-10-05 20:24:38r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg172131

resolution: not a bug
stage: resolved
2012-10-05 20:10:49yinian1992create