MCPcopy
hub / github.com/benoitc/gunicorn / read

Method read

gunicorn/http/unreader.py:19–49  ·  view source on GitHub ↗
(self, size=None)

Source from the content-addressed store, hash-verified

17 raise NotImplementedError()
18
19 def read(self, size=None):
20 if size is not None and not isinstance(size, int):
21 raise TypeError("size parameter must be an int or long.")
22
23 if size is not None:
24 if size == 0:
25 return b""
26 if size < 0:
27 size = None
28
29 self.buf.seek(0, os.SEEK_END)
30
31 if size is None and self.buf.tell():
32 ret = self.buf.getvalue()
33 self.buf = io.BytesIO()
34 return ret
35 if size is None:
36 d = self.chunk()
37 return d
38
39 while self.buf.tell() < size:
40 chunk = self.chunk()
41 if not chunk:
42 ret = self.buf.getvalue()
43 self.buf = io.BytesIO()
44 return ret
45 self.buf.write(chunk)
46 data = self.buf.getvalue()
47 self.buf = io.BytesIO()
48 self.buf.write(data[size:])
49 return data[:size]
50
51 def unread(self, data):
52 rest = self.buf.getvalue()

Calls 3

chunkMethod · 0.95
seekMethod · 0.80
writeMethod · 0.45