# HG changeset patch # User Augie Fackler # Date 1533866323 14400 # Node ID 952bf3c948f0e4ec7ba5a2a7a1c441db3166f5d9 # Parent 2161faf0d24bbb0d4efc9a0aec0bfa1bd8aff8bd 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 diff -r 2161faf0d24b -r 952bf3c948f0 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)