MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / _emit_command

Function _emit_command

py/generate_bidi_protocol.py:1019–1043  ·  view source on GitHub ↗
(c: CommandIR)

Source from the content-addressed store, hash-verified

1017
1018
1019def _emit_command(c: CommandIR) -> list[str]:
1020 required = [p for p in c.params if p.required]
1021 optional = [p for p in c.params if not p.required]
1022 sig = ["self"]
1023 sig += [f"{p.name}: {p.py_type}" for p in required]
1024 sig += [f"{p.name}: {p.py_type} | UnsetType = UNSET" for p in optional]
1025 lines = [wrap_call(f" def {c.method}(", sig, f") -> {c.result_type}:", 4)]
1026 if c.spec_href:
1027 lines.append(f' """Execute {c.wire} (internal, unsupported).')
1028 lines.append("")
1029 lines.append(f" See {c.spec_href}")
1030 lines.append(' """')
1031 else:
1032 lines.append(f' """Execute {c.wire} (internal, unsupported)."""')
1033 if c.params_class:
1034 kwargs = [f"{p.name}={p.name}" for p in c.params]
1035 method = "build" if c.union_params else ""
1036 prefix = f" params = {c.params_class}.{method}(" if method else f" params = {c.params_class}("
1037 lines.append(wrap_call(prefix, kwargs, ")", 8))
1038 params_arg = "params=params"
1039 else:
1040 params_arg = "params=None"
1041 result_arg = f"result={c.result_class}" if c.result_class else "result=None"
1042 lines.append(f" return self._execute({lit(c.wire)}, {params_arg}, {result_arg})")
1043 return lines
1044
1045
1046def _emit_domain_class(mod: ModuleIR) -> str:

Calls 3

wrap_callFunction · 0.85
litFunction · 0.70
appendMethod · 0.45