MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / __process

Method __process

mitmproxy/proxy/layer.py:186–222  ·  view source on GitHub ↗

Yield commands from a generator. If a command is blocking, execution is paused and this function returns without processing any further commands.

(self, command_generator: CommandGenerator, send=None)

Source from the content-addressed store, hash-verified

184 # </✂✂✂>
185
186 def __process(self, command_generator: CommandGenerator, send=None):
187 """
188 Yield commands from a generator.
189 If a command is blocking, execution is paused and this function returns without
190 processing any further commands.
191 """
192 try:
193 # Run ._handle_event to the next yield statement.
194 # If you are not familiar with generators and their .send() method,
195 # https://stackoverflow.com/a/12638313/934719 has a good explanation.
196 command = command_generator.send(send)
197 except StopIteration:
198 return
199
200 while True:
201 if self.debug is not None:
202 if not isinstance(command, commands.Log):
203 yield self.__debug(f"<< {command}")
204 if command.blocking is True:
205 # We only want this layer to block, the outer layers should not block.
206 # For example, take an HTTP/2 connection: If we intercept one particular request,
207 # we don't want all other requests in the connection to be blocked a well.
208 # We signal to outer layers that this command is already handled by assigning our layer to
209 # `.blocking` here (upper layers explicitly check for `is True`).
210 command.blocking = self
211 self._paused = Paused(
212 command,
213 command_generator,
214 )
215 yield command
216 return
217 else:
218 yield command
219 try:
220 command = next(command_generator)
221 except StopIteration:
222 return
223
224 def __continue(self, event: events.CommandCompleted):
225 """

Callers 1

__continueMethod · 0.95

Calls 3

__debugMethod · 0.95
PausedClass · 0.85
sendMethod · 0.45

Tested by

no test coverage detected