MCPcopy Index your code
hub / github.com/bugy/script-server / read

Method read

src/web/streaming_form_reader.py:64–119  ·  view source on GitHub ↗
(self, chunk)

Source from the content-addressed store, hash-verified

62 self.files = {}
63
64 def read(self, chunk):
65 if self._reached_end():
66 return
67
68 self._buffer += chunk
69
70 self._read_bytes += len(chunk)
71
72 if not self._reached_end() and len(self._buffer) < 128:
73 return
74
75 count = 0
76
77 while self._buffer and count < 10000:
78 count += 1
79
80 if not self._current_part:
81 if b'\r\n\r\n' not in self._buffer:
82 break
83
84 if not self._buffer.startswith(self._boundary):
85 raise Exception('Invalid buffer format: ' + str(self._buffer))
86
87 part = self._buffer[len(self._fields_separator):]
88
89 (header, self._buffer) = part.split(b'\r\n\r\n', 1)
90
91 self._current_part = _FormDataPart(header, self._output_files_path)
92
93 if self._fields_separator not in self._buffer:
94 potential_separator_start = self._find_potential_separator_start(self._buffer)
95
96 if potential_separator_start >= 0:
97 body = self._buffer[:potential_separator_start]
98 self._buffer = self._buffer[potential_separator_start:]
99 else:
100 body = self._buffer
101 self._buffer = b''
102
103 self._current_part.write(body)
104 break
105
106 body_end = self._buffer.index(self._fields_separator)
107 body = self._buffer[:body_end]
108 self._buffer = self._buffer[body_end + 2:]
109
110 self._current_part.write(body)
111 self._add_value(self._current_part)
112 self._current_part = None
113
114 if self._reached_end():
115 if self._current_part:
116 self._current_part.write(self._buffer)
117 self._buffer = b''
118 self._add_value(self._current_part)
119 self._current_part = None
120
121 def _reached_end(self):

Callers 9

download_web_filesFunction · 0.80
read_fileFunction · 0.80
try_encoded_readFunction · 0.80
is_binaryFunction · 0.80
_read_bodyMethod · 0.80
read_by_chunksMethod · 0.80
data_receivedMethod · 0.80
pipe_process_outputMethod · 0.80
pipe_process_outputMethod · 0.80

Calls 5

_reached_endMethod · 0.95
_add_valueMethod · 0.95
_FormDataPartClass · 0.85
writeMethod · 0.45

Tested by 2

_read_bodyMethod · 0.64
read_by_chunksMethod · 0.64