add option type hints

This commit is contained in:
Maximilian Hils 2017-07-29 20:40:00 +02:00
parent c29c5dbee8
commit 52da46640b
2 changed files with 113 additions and 0 deletions

View File

@ -48,6 +48,85 @@ LISTEN_PORT = 8080
class Options(optmanager.OptManager): class Options(optmanager.OptManager):
if False:
# This provides type hints for IDEs (e.g. PyCharm) and mypy.
# Autogenerated using test/helper_tools/typehints_for_options.py
add_upstream_certs_to_client_chain = None # type: bool
allow_remote = None # type: bool
anticache = None # type: bool
anticomp = None # type: bool
body_size_limit = None # type: Optional[str]
cadir = None # type: str
certs = None # type: Sequence[str]
ciphers_client = None # type: Optional[str]
ciphers_server = None # type: Optional[str]
client_certs = None # type: Optional[str]
client_replay = None # type: Sequence[str]
console_focus_follow = None # type: bool
console_layout = None # type: str
console_layout_headers = None # type: bool
console_mouse = None # type: bool
console_order = None # type: str
console_order_reversed = None # type: bool
console_palette = None # type: str
console_palette_transparent = None # type: bool
default_contentview = None # type: str
flow_detail = None # type: int
http2 = None # type: bool
http2_priority = None # type: bool
ignore_hosts = None # type: Sequence[str]
intercept = None # type: Optional[str]
intercept_active = None # type: bool
keep_host_header = None # type: bool
keepserving = None # type: bool
listen_host = None # type: str
listen_port = None # type: int
mode = None # type: str
onboarding = None # type: bool
onboarding_host = None # type: str
onboarding_port = None # type: int
proxyauth = None # type: Optional[str]
rawtcp = None # type: bool
refresh_server_playback = None # type: bool
replacements = None # type: Sequence[str]
replay_kill_extra = None # type: bool
rfile = None # type: Optional[str]
save_stream_file = None # type: Optional[str]
save_stream_filter = None # type: Optional[str]
scripts = None # type: Sequence[str]
server = None # type: bool
server_replay = None # type: Sequence[str]
server_replay_ignore_content = None # type: bool
server_replay_ignore_host = None # type: bool
server_replay_ignore_params = None # type: Sequence[str]
server_replay_ignore_payload_params = None # type: Sequence[str]
server_replay_nopop = None # type: bool
server_replay_use_headers = None # type: Sequence[str]
setheaders = None # type: Sequence[str]
showhost = None # type: bool
spoof_source_address = None # type: bool
ssl_insecure = None # type: bool
ssl_verify_upstream_trusted_ca = None # type: Optional[str]
ssl_verify_upstream_trusted_cadir = None # type: Optional[str]
ssl_version_client = None # type: str
ssl_version_server = None # type: str
stickyauth = None # type: Optional[str]
stickycookie = None # type: Optional[str]
stream_large_bodies = None # type: Optional[str]
stream_websockets = None # type: bool
tcp_hosts = None # type: Sequence[str]
upstream_auth = None # type: Optional[str]
upstream_bind_address = None # type: str
upstream_cert = None # type: bool
verbosity = None # type: str
view_filter = None # type: Optional[str]
web_debug = None # type: bool
web_iface = None # type: str
web_open_browser = None # type: bool
web_port = None # type: int
websocket = None # type: bool
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
super().__init__() super().__init__()
self.add_option( self.add_option(

View File

@ -0,0 +1,34 @@
import typing
from unittest import mock
from mitmproxy import proxy, options
from mitmproxy.tools import dump, console, web
def print_typehints(opts):
for name, option in sorted(opts.items()):
print(
# For Python 3.6, we can just use "{}: {}".
"{} = None # type: {}".format(
name,
{
int: "int",
str: "str",
bool: "bool",
typing.Optional[str]: "Optional[str]",
typing.Sequence[str]: "Sequence[str]"
}[option.typespec]
)
)
if __name__ == "__main__":
opts = options.Options()
server = proxy.server.DummyServer(None)
# initialize with all three tools here to capture tool-specific options defined in addons.
dump.DumpMaster(opts, server)
with mock.patch("sys.stdout.isatty", lambda: True):
console.master.ConsoleMaster(opts, server)
web.master.WebMaster(opts, server)
print_typehints(opts)