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
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
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
--
__
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
<http://bugs.python.org/is
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
<http://bugs.python.org/is
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
&l
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
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 defin