@@ -32,13 +32,13 @@ def dumps(
32
32
# also update the response with a new file handler to be
33
33
# sure it acts as though it was never read.
34
34
body = response .read (decode_content = False )
35
- response ._fp = io .BytesIO (body ) # type: ignore[attr-defined ]
35
+ response ._fp = io .BytesIO (body ) # type: ignore[assignment ]
36
36
response .length_remaining = len (body )
37
37
38
38
data = {
39
39
"response" : {
40
40
"body" : body , # Empty bytestring if body is stored separately
41
- "headers" : {str (k ): str (v ) for k , v in response .headers .items ()}, # type: ignore[no-untyped-call]
41
+ "headers" : {str (k ): str (v ) for k , v in response .headers .items ()},
42
42
"status" : response .status ,
43
43
"version" : response .version ,
44
44
"reason" : str (response .reason ),
@@ -72,31 +72,14 @@ def loads(
72
72
if not data :
73
73
return None
74
74
75
- # Determine what version of the serializer the data was serialized
76
- # with
77
- try :
78
- ver , data = data .split (b"," , 1 )
79
- except ValueError :
80
- ver = b"cc=0"
81
-
82
- # Make sure that our "ver" is actually a version and isn't a false
83
- # positive from a , being in the data stream.
84
- if ver [:3 ] != b"cc=" :
85
- data = ver + data
86
- ver = b"cc=0"
87
-
88
- # Get the version number out of the cc=N
89
- verstr = ver .split (b"=" , 1 )[- 1 ].decode ("ascii" )
90
-
91
- # Dispatch to the actual load method for the given version
92
- try :
93
- return getattr (self , f"_loads_v{ verstr } " )(request , data , body_file ) # type: ignore[no-any-return]
94
-
95
- except AttributeError :
96
- # This is a version we don't have a loads function for, so we'll
97
- # just treat it as a miss and return None
75
+ # Previous versions of this library supported other serialization
76
+ # formats, but these have all been removed.
77
+ if not data .startswith (f"cc={ self .serde_version } ," .encode ()):
98
78
return None
99
79
80
+ data = data [5 :]
81
+ return self ._loads_v4 (request , data , body_file )
82
+
100
83
def prepare_response (
101
84
self ,
102
85
request : PreparedRequest ,
@@ -149,49 +132,6 @@ def prepare_response(
149
132
150
133
return HTTPResponse (body = body , preload_content = False , ** cached ["response" ])
151
134
152
- def _loads_v0 (
153
- self ,
154
- request : PreparedRequest ,
155
- data : bytes ,
156
- body_file : IO [bytes ] | None = None ,
157
- ) -> None :
158
- # The original legacy cache data. This doesn't contain enough
159
- # information to construct everything we need, so we'll treat this as
160
- # a miss.
161
- return None
162
-
163
- def _loads_v1 (
164
- self ,
165
- request : PreparedRequest ,
166
- data : bytes ,
167
- body_file : IO [bytes ] | None = None ,
168
- ) -> HTTPResponse | None :
169
- # The "v1" pickled cache format. This is no longer supported
170
- # for security reasons, so we treat it as a miss.
171
- return None
172
-
173
- def _loads_v2 (
174
- self ,
175
- request : PreparedRequest ,
176
- data : bytes ,
177
- body_file : IO [bytes ] | None = None ,
178
- ) -> HTTPResponse | None :
179
- # The "v2" compressed base64 cache format.
180
- # This has been removed due to age and poor size/performance
181
- # characteristics, so we treat it as a miss.
182
- return None
183
-
184
- def _loads_v3 (
185
- self ,
186
- request : PreparedRequest ,
187
- data : bytes ,
188
- body_file : IO [bytes ] | None = None ,
189
- ) -> None :
190
- # Due to Python 2 encoding issues, it's impossible to know for sure
191
- # exactly how to load v3 entries, thus we'll treat these as a miss so
192
- # that they get rewritten out as v4 entries.
193
- return None
194
-
195
135
def _loads_v4 (
196
136
self ,
197
137
request : PreparedRequest ,
0 commit comments