This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: repr of email policies is wrong
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, python-dev, r.david.murray
Priority: low Keywords:

Created on 2012-03-17 02:54 by eric.araujo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg156130 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-17 02:54
>>> import email.policy as p
>>> p.default
Policy()
>>> p.HTTP
Policy(["linesep='\\r\\n'", 'max_line_length=None'])

I think you wanted Policy(linesep='\r\n', max_line_length=None); the problem comes from __repr__ where a format field is replaced by a list, which should have been something ', '.join(args) instead.

I can commit this minor thing if you want, I just wanted to check if I was right first.
msg156159 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-17 14:03
That doesn't produce an evalable repr, though.  The repr should actually be

   Policy(linesep='\\r\\n', max_line_length=None)

I'm not immediately seeing how to get that to happen.
msg156162 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-17 15:54
I don’t understand why the repr should use \\r instead of \r.  It seems to work:

>>> from email.policy import Policy, HTTP, strict
>>> strict
Policy(raise_on_defect=True)
>>> eval(repr(strict))
Policy(raise_on_defect=True)
>>> HTTP
Policy(linesep='\r\n', max_line_length=None)
>>> eval(repr(HTTP))
Policy(linesep='\r\n', max_line_length=None)
>>> HTTP.__dict__
{'max_line_length': None, 'linesep': '\r\n'}
>>> eval(repr(HTTP)).__dict__
{'max_line_length': None, 'linesep': '\r\n'}
msg156190 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-17 19:05
Ach, I screwed up my testing at the interactive interpreter.  Yes, it does work, and I will commit the fix.  Thanks for the report.
msg156191 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-03-17 19:12
New changeset 97b0cf9df420 by R David Murray in branch 'default':
#14344: fixed the repr of email.policy objects.
http://hg.python.org/cpython/rev/97b0cf9df420
msg156192 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-03-17 19:12
Committed.
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58552
2012-03-17 19:12:52r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg156192

stage: resolved
2012-03-17 19:12:15python-devsetnosy: + python-dev
messages: + msg156191
2012-03-17 19:05:07r.david.murraysetmessages: + msg156190
2012-03-17 15:54:08eric.araujosetmessages: + msg156162
2012-03-17 14:03:47r.david.murraysetmessages: + msg156159
2012-03-17 02:54:57eric.araujocreate