MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _Unframer

Class _Unframer

tools/python-3.11.9-amd64/Lib/pickle.py:263–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261
262
263class _Unframer:
264
265 def __init__(self, file_read, file_readline, file_tell=None):
266 self.file_read = file_read
267 self.file_readline = file_readline
268 self.current_frame = None
269
270 def readinto(self, buf):
271 if self.current_frame:
272 n = self.current_frame.readinto(buf)
273 if n == 0 and len(buf) != 0:
274 self.current_frame = None
275 n = len(buf)
276 buf[:] = self.file_read(n)
277 return n
278 if n < len(buf):
279 raise UnpicklingError(
280 "pickle exhausted before end of frame")
281 return n
282 else:
283 n = len(buf)
284 buf[:] = self.file_read(n)
285 return n
286
287 def read(self, n):
288 if self.current_frame:
289 data = self.current_frame.read(n)
290 if not data and n != 0:
291 self.current_frame = None
292 return self.file_read(n)
293 if len(data) < n:
294 raise UnpicklingError(
295 "pickle exhausted before end of frame")
296 return data
297 else:
298 return self.file_read(n)
299
300 def readline(self):
301 if self.current_frame:
302 data = self.current_frame.readline()
303 if not data:
304 self.current_frame = None
305 return self.file_readline()
306 if data[-1] != b'\n'[0]:
307 raise UnpicklingError(
308 "pickle exhausted before end of frame")
309 return data
310 else:
311 return self.file_readline()
312
313 def load_frame(self, frame_size):
314 if self.current_frame and self.current_frame.read() != b'':
315 raise UnpicklingError(
316 "beginning of a new frame before end of current frame")
317 self.current_frame = io.BytesIO(self.file_read(frame_size))
318
319
320# Tools used for pickling.

Callers 1

loadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected