Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHGf0c445a8e324: mail: delete conditional code for Python 2
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
| Alphare |
| hg-reviewers |
| No Linters Available |
| No Unit Test Coverage |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/mail.py (50 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 488b620d5e7a | ae477d71d9c2 | Gregory Szorc | Feb 21 2022, 12:20 PM |
| """creates mime text object, encodes it if needed, and sets | """creates mime text object, encodes it if needed, and sets | ||||
| charset and transfer-encoding accordingly.""" | charset and transfer-encoding accordingly.""" | ||||
| cs = 'us-ascii' | cs = 'us-ascii' | ||||
| if not display: | if not display: | ||||
| s, cs = _encode(ui, s, charsets) | s, cs = _encode(ui, s, charsets) | ||||
| return mimetextqp(s, 'plain', cs) | return mimetextqp(s, 'plain', cs) | ||||
| if pycompat.ispy3: | |||||
| Generator = email.generator.BytesGenerator | Generator = email.generator.BytesGenerator | ||||
| def parse(fp): | def parse(fp): | ||||
| # type: (Any) -> email.message.Message | # type: (Any) -> email.message.Message | ||||
| ep = email.parser.Parser() | ep = email.parser.Parser() | ||||
| # disable the "universal newlines" mode, which isn't binary safe. | # disable the "universal newlines" mode, which isn't binary safe. | ||||
| # I have no idea if ascii/surrogateescape is correct, but that's | # I have no idea if ascii/surrogateescape is correct, but that's | ||||
| # what the standard Python email parser does. | # what the standard Python email parser does. | ||||
| fp = io.TextIOWrapper( | fp = io.TextIOWrapper( | ||||
| fp, encoding='ascii', errors='surrogateescape', newline=chr(10) | fp, encoding='ascii', errors='surrogateescape', newline=chr(10) | ||||
| ) | ) | ||||
| try: | try: | ||||
| return ep.parse(fp) | return ep.parse(fp) | ||||
| finally: | finally: | ||||
| fp.detach() | fp.detach() | ||||
| def parsebytes(data): | def parsebytes(data): | ||||
| # type: (bytes) -> email.message.Message | # type: (bytes) -> email.message.Message | ||||
| ep = email.parser.BytesParser() | ep = email.parser.BytesParser() | ||||
| return ep.parsebytes(data) | return ep.parsebytes(data) | ||||
| else: | |||||
| Generator = email.generator.Generator | |||||
| 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 headdecode(s): | def headdecode(s): | ||||
| # type: (Union[email.header.Header, bytes]) -> bytes | # type: (Union[email.header.Header, bytes]) -> bytes | ||||
| '''Decodes RFC-2047 header''' | '''Decodes RFC-2047 header''' | ||||
| uparts = [] | uparts = [] | ||||
| for part, charset in email.header.decode_header(s): | for part, charset in email.header.decode_header(s): | ||||
| if charset is not None: | if charset is not None: | ||||
| try: | try: | ||||