The following code first sets the value of the variable maxsize to 8. The code then constructs a sample email message string t, consisting of multiple header fields and their values. The Parser class is then used to parse this message string into an email message object. The keys() method of this object is called to retrieve the list of header field names, which is then printed to the console. The output of this case is ['From', 'Foo'] on RustPython, while it is ['From', 'Foo', 'Bar'] on CPython.
Moreover, if we set the maxsize as 8192, i.e., maxsize = 8192, CPython can still work normally, RustPython reports a ValueError.
test.py
from email.parser import Parser
maxsize = 8
t = 'From: <e@example.com>\nFoo: '
t += 'x' * ((-len(t) - 1) % maxsize) + '\rBar: '
t += 'y' * ((-len(t) - 1) % maxsize) + '\x85Baz: '
t += 'z' * ((-len(t) - 1) % maxsize) + '\n\n'
print(Parser().parsestr(t).keys())
Behaviors on CPython 3.8.0,3.9.0,3.11.3:
['From', 'Foo', 'Bar']
Behaviors on RustPython 0.2.0:
['From', 'Foo']
After setting the maxsize as 8192, the behavior on RustPython 0.2.0 is as follows:
Traceback (most recent call last):
File "/home/xxm/Desktop/RustPython/test.py", line 586, in <module>
print(Parser().parsestr(t).keys())
File "/home/xxm/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/0284059/pylib/Lib/email/parser.py", line 68, in parsestr
return self.parse(StringIO(text), headersonly=headersonly)
File "/home/xxm/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/0284059/pylib/Lib/email/parser.py", line 54, in parse
data = fp.read(8192)
ValueError: Error Retrieving Value
Environment:
Ubuntu 18.04
RustPython 0.2.0 0284059
CPython 3.8.0, 3.9.0, 3.11.3
The following code first sets the value of the variable maxsize to 8. The code then constructs a sample email message string t, consisting of multiple header fields and their values. The Parser class is then used to parse this message string into an email message object. The keys() method of this object is called to retrieve the list of header field names, which is then printed to the console. The output of this case is ['From', 'Foo'] on RustPython, while it is ['From', 'Foo', 'Bar'] on CPython.
Moreover, if we set the maxsize as 8192, i.e., maxsize = 8192, CPython can still work normally, RustPython reports a ValueError.
test.py
Behaviors on CPython 3.8.0,3.9.0,3.11.3:
['From', 'Foo', 'Bar']
Behaviors on RustPython 0.2.0:
['From', 'Foo']
After setting the maxsize as 8192, the behavior on RustPython 0.2.0 is as follows:
Environment:
Ubuntu 18.04
RustPython 0.2.0 0284059
CPython 3.8.0, 3.9.0, 3.11.3