Register an addon, call its load event, and then register all its sub-addons. This should be used by addons that dynamically manage addons. If the calling addon is already running, it should follow with running and configure events. Must be called within a c
(self, addon)
| 156 | return self.lookup.get(name, None) |
| 157 | |
| 158 | def register(self, addon): |
| 159 | """ |
| 160 | Register an addon, call its load event, and then register all its |
| 161 | sub-addons. This should be used by addons that dynamically manage |
| 162 | addons. |
| 163 | |
| 164 | If the calling addon is already running, it should follow with |
| 165 | running and configure events. Must be called within a current |
| 166 | context. |
| 167 | """ |
| 168 | api_changes = { |
| 169 | # mitmproxy 6 -> mitmproxy 7 |
| 170 | "clientconnect": f"The clientconnect event has been removed, use client_connected instead", |
| 171 | "clientdisconnect": f"The clientdisconnect event has been removed, use client_disconnected instead", |
| 172 | "serverconnect": "The serverconnect event has been removed, use server_connect and server_connected instead", |
| 173 | "serverdisconnect": f"The serverdisconnect event has been removed, use server_disconnected instead", |
| 174 | # mitmproxy 8 -> mitmproxy 9 |
| 175 | "add_log": "The add_log event has been deprecated, use Python's builtin logging module instead", |
| 176 | } |
| 177 | for a in traverse([addon]): |
| 178 | for old, msg in api_changes.items(): |
| 179 | if hasattr(a, old): |
| 180 | logger.warning( |
| 181 | f"{msg}. For more details, see https://docs.mitmproxy.org/dev/addons-api-changelog/." |
| 182 | ) |
| 183 | name = _get_name(a) |
| 184 | if name in self.lookup: |
| 185 | raise exceptions.AddonManagerError( |
| 186 | "An addon called '%s' already exists." % name |
| 187 | ) |
| 188 | loader = Loader(self.master) |
| 189 | self.invoke_addon_sync(addon, LoadHook(loader)) |
| 190 | for a in traverse([addon]): |
| 191 | name = _get_name(a) |
| 192 | self.lookup[name] = a |
| 193 | for a in traverse([addon]): |
| 194 | self.master.commands.collect_commands(a) |
| 195 | self.master.options.process_deferred() |
| 196 | return addon |
| 197 | |
| 198 | def add(self, *addons): |
| 199 | """ |
no test coverage detected