mail: be more cautious about bytes vs str for py3 compat
authorAugie Fackler <augie@google.com>
Thu, 09 Aug 2018 21:58:43 -0400
changeset 39076 952bf3c948f0
parent 39075 2161faf0d24b
child 39077 f76c1343859d
mail: be more cautious about bytes vs str for py3 compat 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. Differential Revision: https://phab.mercurial-scm.org/D4233
mercurial/mail.py
--- a/mercurial/mail.py	Thu Aug 09 21:57:46 2018 -0400
+++ b/mercurial/mail.py	Thu Aug 09 21:58:43 2018 -0400
@@ -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)