A loader object is passed to the load() event when addons start up.
| 60 | |
| 61 | |
| 62 | class Loader: |
| 63 | """ |
| 64 | A loader object is passed to the load() event when addons start up. |
| 65 | """ |
| 66 | |
| 67 | def __init__(self, master): |
| 68 | self.master = master |
| 69 | |
| 70 | def add_option( |
| 71 | self, |
| 72 | name: str, |
| 73 | typespec: type, |
| 74 | default: Any, |
| 75 | help: str, |
| 76 | choices: Sequence[str] | None = None, |
| 77 | ) -> None: |
| 78 | """ |
| 79 | Add an option to mitmproxy. |
| 80 | |
| 81 | Help should be a single paragraph with no linebreaks - it will be |
| 82 | reflowed by tools. Information on the data type should be omitted - |
| 83 | it will be generated and added by tools as needed. |
| 84 | """ |
| 85 | assert not isinstance(choices, str) |
| 86 | if name in self.master.options: |
| 87 | existing = self.master.options._options[name] |
| 88 | same_signature = ( |
| 89 | existing.name == name |
| 90 | and existing.typespec == typespec |
| 91 | and existing.default == default |
| 92 | and existing.help == help |
| 93 | and existing.choices == choices |
| 94 | ) |
| 95 | if same_signature: |
| 96 | return |
| 97 | else: |
| 98 | logger.warning("Over-riding existing option %s" % name) |
| 99 | self.master.options.add_option(name, typespec, default, help, choices) |
| 100 | |
| 101 | def add_command(self, path: str, func: Callable) -> None: |
| 102 | """Add a command to mitmproxy. |
| 103 | |
| 104 | Unless you are generating commands programatically, |
| 105 | this API should be avoided. Decorate your function with `@mitmproxy.command.command` instead. |
| 106 | """ |
| 107 | self.master.commands.add(path, func) |
| 108 | |
| 109 | |
| 110 | def traverse(chain): |
no outgoing calls
no test coverage detected
searching dependent graphs…