D4233: mail: be more cautious about bytes vs str for py3 compat

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Fri Aug 10 02:07:13 UTC 2018


durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It's suboptimal that we get a bytes on 2 and a unicode on 3, but it's
  easy to work with and I'm disinclined to change anything unless we
  start using some sort of type inferencer.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4233

AFFECTED FILES
  mercurial/mail.py

CHANGE DETAILS

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -312,7 +312,9 @@
     try:
         acc, dom = addr.split(r'@')
         acc = acc.encode('ascii')
-        dom = dom.decode(encoding.encoding).encode('idna')
+        if isinstance(dom, bytes):
+            dom = dom.decode(encoding.encoding)
+        dom = dom.encode('idna')
         addr = '%s@%s' % (acc, dom)
     except UnicodeDecodeError:
         raise error.Abort(_('invalid email address: %s') % addr)



To: durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list