Mercurial > hg
comparison mercurial/mail.py @ 39039:952bf3c948f0
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
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 09 Aug 2018 21:58:43 -0400 |
parents | ede768cfe83e |
children | f68ad9b4a43b |
comparison
equal
deleted
inserted
replaced
39038:2161faf0d24b | 39039:952bf3c948f0 |
---|---|
310 def _addressencode(ui, name, addr, charsets=None): | 310 def _addressencode(ui, name, addr, charsets=None): |
311 name = headencode(ui, name, charsets) | 311 name = headencode(ui, name, charsets) |
312 try: | 312 try: |
313 acc, dom = addr.split(r'@') | 313 acc, dom = addr.split(r'@') |
314 acc = acc.encode('ascii') | 314 acc = acc.encode('ascii') |
315 dom = dom.decode(encoding.encoding).encode('idna') | 315 if isinstance(dom, bytes): |
316 dom = dom.decode(encoding.encoding) | |
317 dom = dom.encode('idna') | |
316 addr = '%s@%s' % (acc, dom) | 318 addr = '%s@%s' % (acc, dom) |
317 except UnicodeDecodeError: | 319 except UnicodeDecodeError: |
318 raise error.Abort(_('invalid email address: %s') % addr) | 320 raise error.Abort(_('invalid email address: %s') % addr) |
319 except ValueError: | 321 except ValueError: |
320 try: | 322 try: |