[issue34220] Serialization of email message without header line length limit and a non-ASCII subject fails with TypeError

2018-07-25 Thread Grigory Statsenko
New submission from Grigory Statsenko : I have the following code that creates a simple email message with a) a pure-ASCII subject, b) non-ASCII subject (I made it into a unittest): import email.generator import email.policy from email.mime.multipart import MIMEMultipart from email.mime.text

[issue34222] Email message serialization enters an infinite loop when folding non-ASCII headers with long words

2018-07-25 Thread Grigory Statsenko
New submission from Grigory Statsenko : (Discovered together with https://bugs.python.org/msg322348) Email message serialization (in function _fold_as_ew) enters an infinite loop when folding non-ASCII headers whose words (after encoding) are longer than the given maxlen. Besides being stuck

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
Grigory Statsenko added the comment: With streaming you never know the real length before you're done iterating. Anyway, the fix really shouldn't be that complicated: In _iterencode_list just yield the '[' instead of saving it to buf -- ___ Python

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
Grigory Statsenko added the comment: If __len__ is not defined, then the iterator is considered empty and is always rendered as [] even if it really isn't empty -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/i

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
Grigory Statsenko added the comment: My bad - it doesn't work with non-empty iterators if you set len to 0, so not a solution -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/i

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
Grigory Statsenko added the comment: Actually, it does work with len = 0 even if the iterator is not empty. So, I guess that is a solution. But still, I think the more correct way would be to make it work with > 0 -- ___ Python tracker &

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
Grigory Statsenko added the comment: I can't do that if I don't know how many entries there will be ahead of time. In my real-life situation I'm fetching the data from a database not knowing how many entries I'll get before I actually get them (in the iterator). In most cases there are huge

[issue27613] Empty iterator is rendered as a single bracket ] when using json's iterencode

2016-07-25 Thread Grigory Statsenko
New submission from Grigory Statsenko: JSONEncoder.iterencode doesn't work with empty iterators correctly. Steps: 1. Define an iterator that is recognized by json as a list (inherit from list and define nonzero __len__). 2. Use json.dump with data containing an empty iterator defined