MCPcopy
hub / github.com/pallets/werkzeug / _parse_data

Method _parse_data

src/werkzeug/sansio/multipart.py:238–269  ·  view source on GitHub ↗
(
        self, data: bytes | bytearray, *, start: bool
    )

Source from the content-addressed store, hash-verified

236 return Headers(headers)
237
238 def _parse_data(
239 self, data: bytes | bytearray, *, start: bool
240 ) -> tuple[bytes, int, bool]:
241 # Body parts must start with CRLF (or CR or LF)
242 if start:
243 match = LINE_BREAK_RE.match(data)
244 data_start = t.cast(t.Match[bytes], match).end()
245 else:
246 data_start = 0
247
248 if self.buffer.find(b"--" + self.boundary) == -1:
249 # No complete boundary in the buffer, but there may be
250 # a partial boundary at the end.
251 data_end = del_index = (
252 self._last_partial_boundary_index(data[data_start:]) + data_start
253 )
254 more_data = True
255 else:
256 match = self.boundary_re.search(data)
257 if match is not None:
258 if match.group(1).startswith(b"--"):
259 self.state = State.EPILOGUE
260 else:
261 self.state = State.PART
262 data_end = match.start()
263 del_index = match.end()
264 else:
265 data_end = del_index = (
266 self._last_partial_boundary_index(data[data_start:]) + data_start
267 )
268 more_data = match is None
269 return bytes(data[data_start:data_end]), del_index, more_data
270
271 def _last_partial_boundary_index(self, data: bytes | bytearray) -> int:
272 # Find the last index following which a partial boundary

Callers 1

next_eventMethod · 0.95

Calls 3

matchMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected