File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import io
34import pickle
45import socket
56from email .errors import MessageDefect
1617 HeaderParsingError ,
1718 HostChangedError ,
1819 HTTPError ,
20+ InvalidChunkLength ,
1921 LocationParseError ,
2022 MaxRetryError ,
2123 NameResolutionError ,
2224 NewConnectionError ,
2325 ReadTimeoutError ,
2426)
27+ from urllib3 .response import HTTPResponse
2528
2629
2730class TestPickle :
@@ -65,6 +68,24 @@ def test_exceptions(self, exception: Exception) -> None:
6568 # reason is likely an exception so do string comparison instead
6669 assert str (exception ._reason ) == str (result ._reason ) # type: ignore[attr-defined]
6770
71+ def test_invalid_chunk_length (self ) -> None :
72+ response = HTTPResponse (
73+ body = io .BytesIO (b"abcdef" ),
74+ headers = {"Content-Length" : "10" },
75+ preload_content = False ,
76+ )
77+ response .read (3 )
78+ exception = InvalidChunkLength (response , b"zz" )
79+ assert exception .partial == 3
80+ assert exception .expected == 7
81+
82+ result = pickle .loads (pickle .dumps (exception ))
83+ assert isinstance (result , InvalidChunkLength )
84+ assert result .partial == exception .partial
85+ assert result .expected == exception .expected
86+ assert result .length == exception .length
87+ assert repr (result ) == repr (exception )
88+
6889
6990class TestFormat :
7091 def test_header_parsing_errors (self ) -> None :
You can’t perform that action at this time.
0 commit comments