MCPcopy
hub / github.com/mitmproxy/mitmproxy / collect_commands

Method collect_commands

mitmproxy/command.py:174–190  ·  view source on GitHub ↗
(self, addon)

Source from the content-addressed store, hash-verified

172 self.commands = {}
173
174 def collect_commands(self, addon):
175 for i in dir(addon):
176 if not i.startswith("__"):
177 o = getattr(addon, i)
178 try:
179 # hasattr is not enough, see https://github.com/mitmproxy/mitmproxy/issues/3794
180 is_command = isinstance(getattr(o, "command_name", None), str)
181 except Exception:
182 pass # getattr may raise if o implements __getattr__.
183 else:
184 if is_command:
185 try:
186 self.add(o.command_name, o)
187 except exceptions.CommandError as e:
188 logging.warning(
189 f"Could not load command {o.command_name}: {e}"
190 )
191
192 def add(self, path: str, func: Callable):
193 self.commands[path] = Command(self, path, func)

Callers 3

test_collect_commandsFunction · 0.95
test_decoratorFunction · 0.95
registerMethod · 0.80

Calls 1

addMethod · 0.95

Tested by 2

test_collect_commandsFunction · 0.76
test_decoratorFunction · 0.76