[issue10574] email.header.decode_header fails if the string contains multiple directives
Roy Hyunjin Han added the comment: Currently using the following workaround. import re import email.header def decodeSafely(x): match = re.search('(=\?.*?\?B\?)', x) if not match: return x encoding = match.group(1) return email.header.decode_header('%s%s==?=' % (encoding, x.replace(encoding, '').replace('?', '').replace('=', ''))) -- ___ Python tracker <http://bugs.python.org/issue10574> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10574] email.header.decode_header fails if the string contains multiple directives
Roy Hyunjin Han added the comment: Improved workaround to handle another degenerate case where the encoded string is in between non-encoded strings. import re import email.header pattern_ecre = re.compile(r'((=\?.*?\?[qb]\?).*\?=)', re.VERBOSE | re.IGNORECASE | re.MULTILINE) def decodeSafely(x): match = pattern_ecre.search(x) if not match: return x string, encoding = match.groups() stringBefore, string, stringAfter = x.partition(string) return stringBefore + email.header.decode_header('%s%s==?=' % (encoding, string.replace(encoding, '').replace('?', '').replace('=', '')))[0][0] + stringAfter print decodeSafely('=?UTF-8?B?MjAxMSBBVVRNIENBTEwgZm9yIE5PTUlO?==?UTF-8?B?QVRJT05TIG9mIFZQIGZvciBNZW1iZXJz?==?UTF-8?B?aGlw?=') print decodeSafely('"=?UTF-8?B?QVVUTSBIZWFkcXVhcnRlcnM=?="') -- ___ Python tracker <http://bugs.python.org/issue10574> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10574] email.header.decode_header fails if the string contains multiple directives
Roy Hyunjin Han added the comment: The following code seems to solve the first case just as well. It seems that it is a problem of missing whitespace. email.header.decode_header('=?UTF-8?B?MjAxMSBBVVRNIENBTEwgZm9yIE5PTUlO?==?UTF-8?B?QVRJT05TIG9mIFZQIGZvciBNZW1iZXJz?==?UTF-8?B?aGlw?='.replace('?==?', '?= =?')) -- ___ Python tracker <http://bugs.python.org/issue10574> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10574] email.header.decode_header fails if the string contains multiple directives
Roy Hyunjin Han added the comment: 2010/11/30 R. David Murray : > Out of curiosity, which email program is it that is producing these invalid > headers? I lost the headers for the original email, so I don't know which email program created the invalid headers. On searching for messages from the same address, it seems most of the messages originate from a marketing company called informz.net, but in rare instances there is a non-standard X-Mailer header: - ColdFusion 8 Application Server (via JavaMail) - IBM Lotus Domino Access for MS Outlook (2003) Release 7.0.2 September 26, 2006 Messages sent via informz.net generally parse correctly, so I am guessing it might have been one of the X-Mailers above. -- ___ Python tracker <http://bugs.python.org/issue10574> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10574] email.header.decode_header fails if the string contains multiple directives
Roy Hyunjin Han added the comment: > This is fixed by the fix to issue 1079, but we have decided that fix can't be > backported because it is a behavior change that might break existing working > programs. Thanks for this update. -- ___ Python tracker <http://bugs.python.org/issue10574> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1598] unexpected response in imaplib
Roy Hyunjin Han added the comment: Is imaplib choking on the IBM-specific X-MIMETrack header? Is Lotus Notes properly formatting the multi-line headers? Can RFC822 headers contain the PIPE | symbol? -- ___ Python tracker <http://bugs.python.org/issue1598> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1598] unexpected response in imaplib
Roy Hyunjin Han added the comment: Hi Lita, I no longer have access to a Domino server. I'm not sure whether there are enough users trying to access Domino with imaplib for this to warrant investigation. RHH -- ___ Python tracker <http://bugs.python.org/issue1598> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1598] unexpected response in imaplib
Roy Hyunjin Han added the comment: Yes, I think closing this issue is reasonable. If the error reappears, we can just reopen it. -- ___ Python tracker <http://bugs.python.org/issue1598> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24070] Exceptions and arguments disappear when using argparse inside with statement
New submission from Roy Hyunjin Han: Exceptions and arguments disappear when using argparse inside a "with" statement. The behavior was confusing and frustrating because I could not pinpoint why certain arguments were missing or unrecognized. Unhandled exceptions inside the with statement typically trigger a traceback, unless __exit__ returns True, in which the exception is "swallowed" (https://www.python.org/dev/peps/pep-0343/). However, the NameError exception and tile_indices argument disappear because of a premature sys.exit (https://hg.python.org/cpython/file/default/Lib/argparse.py#l2385). ``` """ $ python exception-in-with.py EXPECTED Traceback (most recent call last): File "exception-in-with.py", line 51, in abc # !!! NameError: name 'abc' is not defined ACTUAL usage: exception-in-with.py [-h] --image_path PATH exception-in-with.py: error: argument --image_path is required $ python exception-in-with.py --image_path x EXPECTED == ACTUAL Traceback (most recent call last): File "exception-in-with.py", line 51, in abc # !!! NameError: name 'abc' is not defined $ python exception-in-with.py --image_path x --tile_indices 1 EXPECTED Traceback (most recent call last): File "exception-in-with.py", line 51, in abc # !!! NameError: name 'abc' is not defined ACTUAL usage: exception-in-with.py [-h] --image_path PATH exception-in-with.py: error: unrecognized arguments: --tile_indices 1 """ from argparse import ArgumentParser class Starter(object): def __init__(self): self.argument_parser = ArgumentParser() def __enter__(self): return self def __exit__(self, exception_type, exception_value, exception_traceback): self.argument_parser.parse_args() def add_argument(self, *args, **kw): self.argument_parser.add_argument(*args, **kw) with Starter() as starter: starter.add_argument('--image_path', metavar='PATH', required=True) abc # !!! starter.add_argument('--tile_indices', metavar='INTEGER') ``` -- components: Library (Lib) files: argparse-with-exception.py messages: 242192 nosy: invisibleroads priority: normal severity: normal status: open title: Exceptions and arguments disappear when using argparse inside with statement type: behavior versions: Python 2.7, Python 3.3 Added file: http://bugs.python.org/file39227/argparse-with-exception.py ___ Python tracker <http://bugs.python.org/issue24070> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24070] Exceptions and arguments disappear when using argparse inside with statement
Roy Hyunjin Han added the comment: The behavior may not be surprising from a technical perspective, but it is unintuitive. I think exceptions inside a with statement should trigger a traceback, unless you are saying that it is the responsibility of the author to catch and raise the exception inside __exit__, which feels to me like a workaround that is specific to parse_args. -- ___ Python tracker <http://bugs.python.org/issue24070> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com