[Updated] [+-- ] D12286: mail: delete conditional code for Python 2
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Thu Mar 3 16:09:16 UTC 2022
indygreg updated this revision to Diff 32463.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12286?vs=32411&id=32463
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12286/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12286
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
@@ -467,43 +467,28 @@
return mimetextqp(s, 'plain', cs)
-if pycompat.ispy3:
-
- Generator = email.generator.BytesGenerator
-
- def parse(fp):
- # type: (Any) -> email.message.Message
- ep = email.parser.Parser()
- # disable the "universal newlines" mode, which isn't binary safe.
- # I have no idea if ascii/surrogateescape is correct, but that's
- # what the standard Python email parser does.
- fp = io.TextIOWrapper(
- fp, encoding='ascii', errors='surrogateescape', newline=chr(10)
- )
- try:
- return ep.parse(fp)
- finally:
- fp.detach()
-
- def parsebytes(data):
- # type: (bytes) -> email.message.Message
- ep = email.parser.BytesParser()
- return ep.parsebytes(data)
+Generator = email.generator.BytesGenerator
-else:
-
- Generator = email.generator.Generator
+def parse(fp):
+ # type: (Any) -> email.message.Message
+ ep = email.parser.Parser()
+ # disable the "universal newlines" mode, which isn't binary safe.
+ # I have no idea if ascii/surrogateescape is correct, but that's
+ # what the standard Python email parser does.
+ fp = io.TextIOWrapper(
+ fp, encoding='ascii', errors='surrogateescape', newline=chr(10)
+ )
+ try:
+ return ep.parse(fp)
+ finally:
+ fp.detach()
- def parse(fp):
- # type: (Any) -> email.message.Message
- ep = email.parser.Parser()
- return ep.parse(fp)
- def parsebytes(data):
- # type: (str) -> email.message.Message
- ep = email.parser.Parser()
- return ep.parsestr(data)
+def parsebytes(data):
+ # type: (bytes) -> email.message.Message
+ ep = email.parser.BytesParser()
+ return ep.parsebytes(data)
def headdecode(s):
To: indygreg, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220303/181c1d5e/attachment-0002.html>
More information about the Mercurial-patches
mailing list