D7061: convert: don't pass bytes to, or expect bytes from, emailparser

Kwan (Ian Moody) phabricator at mercurial-scm.org
Sat Oct 12 10:36:20 EDT 2019


Kwan added inline comments.

INLINE COMMENTS

> martinvonz wrote in gnuarch.py:301
> Is it right to depend on the user's preferred encoding (as I think `unifromlocal()` does)? Would it make sense to instead initialize `self.catlogparser = emailparser.BytesParser()`?

Hmm, I wasn't aware of that drawback of `unifromlocal()` if it's true.  Is there a canonical "Give me unicode from these mercurial bytes" function?  Regardless, `BytesParser` does sound handy, and is even in 3.5 <https://docs.python.org/3.5/library/email.parser.html#email.parser.BytesParser>, but isn't present in 2.7.  Would doing it conditionally be alright?  (and a conditional alias for parsebytes)

  self.catlogparser = (
      emailparser.BytesParser()
      if pycompat.ispy3
      else emailparser.Parser()
  )
  if not pycompat.ispy3:
      self.catlogparser.parsebytes = self.catlogparser.parsestr

  -            catlog = self.catlogparser.parsestr(data)
  +            catlog = self.catlogparser.parsebytes(data)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7061/new/

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

To: Kwan, #hg-reviewers
Cc: martinvonz, mercurial-devel


More information about the Mercurial-devel mailing list