This code appears to be on the wrong side of the law in Python 2, at
least some of the time. In Python 3, it's definitely wrong in places,
but fortunately that's easy to fix.
Details
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHG858fe9625dab: mail: fix _encode to be more correct on Python 3
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
mercurial/mail.py | ||
---|---|---|
249–272 | Maybe this should be renamed _encodelossy to avoid surprises? |
Comment Actions
def _encode(ui, s, charsets):
'''Returns (converted) string, charset tuple. Finds out best charset by cycling through sendcharsets in descending order. Tries both encoding and fallbackencoding for input. Only as last resort send as is in fake ascii. Caveat: Do not use for mail parts containing patches!'''Maybe this should be renamed _encodelossy to avoid surprises?
It isn't lossy in that any input bytes will never be dropped. If no reasonable
charset found, it falls back to 'us-ascii' to send bytes transparently.
Maybe this should be renamed _encodelossy to avoid surprises?