Aaryn Tonita <[email protected]> added the comment:
Although I am not personally interested in backporting a fix for this issue,
anyone that experiences this issue in python 3.5 can execute the following
monkey patch to solve the issue:
def _fix_issue_36041_3_5():
from email._header_value_parser import QuotedString, ValueTerminal,
quote_string
import email._header_value_parser
class BareQuotedString(QuotedString):
token_type = 'bare-quoted-string'
def __str__(self):
return quote_string(''.join(str(x) for x in self))
@property
def value(self):
return ''.join(str(x) for x in self)
@property
def parts(self):
parts = list(self)
escaped_parts = []
for part in parts:
if isinstance(part, ValueTerminal):
escaped = quote_string(str(part))[1:-1]
escaped_parts.append(ValueTerminal(escaped, 'ptext'))
else:
escaped_parts.append(part)
# Add quotes to the first and last parts.
escaped_parts[0] = ValueTerminal('"' + str(escaped_parts[0]),
'ptext')
escaped_parts[-1] = ValueTerminal(str(escaped_parts[-1] + '"'),
'ptext')
return escaped_parts
email._header_value_parser.BareQuotedString = BareQuotedString
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36041>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com