From 2211bd98cbcbf6f2a5f82f45ad3dcb468870806f Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 21:46:17 -0500 Subject: [PATCH 01/12] Add xmlrpc client module --- stdlib/3/xmlrpc/__init__.pyi | 0 stdlib/3/xmlrpc/client.pyi | 277 +++++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+) create mode 100644 stdlib/3/xmlrpc/__init__.pyi create mode 100644 stdlib/3/xmlrpc/client.pyi diff --git a/stdlib/3/xmlrpc/__init__.pyi b/stdlib/3/xmlrpc/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi new file mode 100644 index 000000000000..d3afb4ab86f8 --- /dev/null +++ b/stdlib/3/xmlrpc/client.pyi @@ -0,0 +1,277 @@ +import io +import sys +import time +import gzip +import http.client + +from typing import Any, Callable, Dict, IO, Iterable, List, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload +from types import TracebackType +from datetime import datetime + +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + +_T = TypeVar("_T") +class _HasTimeTuple(Protocol): + def timetuple(self) -> time.struct_time: ... +_DateTimeComparable = Union[DateTime, datetime, str, _HasTimeTuple] +_Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime, DateTime, Binary] +_XMLDate = Union[int, datetime, Tuple[int, ...], time.struct_time] +_HostType = Union[Tuple[str, Dict[str, str]], str] + +def escape(s: str) -> str: ... # undocumented + +PARSE_ERROR: int # undocumented +SERVER_ERROR: int # undocumented +APPLICATION_ERROR: int # undocumented +SYSTEM_ERROR: int # undocumented +TRANSPORT_ERROR: int # undocumented + +NOT_WELLFORMED_ERROR: int # undocumented +UNSUPPORTED_ENCODING: int # undocumented +INVALID_ENCODING_CHAR: int # undocumented +INVALID_XMLRPC: int # undocumented +METHOD_NOT_FOUND: int # undocumented +INVALID_METHOD_PARAMS: int # undocumented +INTERNAL_ERROR: int # undocumented + +class Error(Exception): ... + +class ProtocolError(Error): + + url: str + errcode: int + errmsg: str + headers: Dict[str, str] + + def __init__(self, url: str, errcode: int, errmsg: str, headers: Dict[str, str]) -> None: ... + def __repr__(self) -> str: ... + +class ResponseError(Error): ... + +class Fault(Error): + + faultCode: str + faultString: str + + def __init__(self, faultCode: str, faultString: str, **extra: Any) -> None: ... + def __repr__(self) -> str: ... + + +boolean = bool +Boolean = bool + +def _iso8601_format(value: datetime) -> str: ... # undocumented +def _strftime(value: _XMLDate) -> str: ... # undocumented + +class DateTime: + + value: str # undocumented + + def __init__(self, value: Union[int, str, datetime, time.struct_time, Tuple[int, ...]] = ...): ... + def __lt__(self, other: _DateTimeComparable) -> bool: ... + def __le__(self, other: _DateTimeComparable) -> bool: ... + def __gt__(self, other: _DateTimeComparable) -> bool: ... + def __ge__(self, other: _DateTimeComparable) -> bool: ... + def __eq__(self, other: _DateTimeComparable) -> bool: ... # type: ignore + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def make_comparable(self, other: _DateTimeComparable) -> Tuple[str, str]: ... # undocumented + def timetuple(self) -> time.struct_time: ... # undocumented + def decode(self, data: Any) -> None: ... + def encode(self, out: IO[str]) -> None: ... + +def _datetime(data: Any) -> DateTime: ... # undocumented +def _datetime_type(data: str) -> datetime: ... # undocumented + +class Binary: + + data: bytes + + def __init__(self, data: Optional[bytes] = ...) -> None: ... + def __str__(self) -> str: ... + def __eq__(self, other: Union[Binary, bytes]) -> bool: ... # type: ignore + def decode(self, data: bytes) -> None: ... + def encode(self, out: IO[str]) -> None: ... + +def _binary(data: bytes) -> Binary: ... # undocumented + +WRAPPERS: Tuple[Type[DateTime], Type[Binary]] # undocumented + +class ExpatParser: # undocumented + + def __init__(self, target: Unmarshaller) -> None: ... + def feed(self, data: Union[Text, bytes]) -> None: ... + def close(self) -> None: ... + +class Marshaller: + + dispatch: Dict[Type[Any], Callable[[Marshaller, Any, IO[str]], None]] = ... # TODO: Replace 'Any' with some kind of binding + + memo: Dict[Any, None] + data: None + encoding: Optional[str] + allow_none: bool + + def __init__(self, encoding: Optional[str] = ..., allow_none: bool = ...) -> None: ... + def dumps(self, values: Union[Fault, Iterable[_Marshallable]]) -> str: ... + def __dump(self, value: Union[_Marshallable]) -> None: ... # undocumented + def dump_nil(self, value: None, write: IO[str]) -> None: ... + def dump_bool(self, value: bool, write: IO[str]) -> None: ... + def dump_long(self, value: int, write: IO[str]) -> None: ... + def dump_int(self, value: int, write: IO[str]) -> None: ... + def dump_double(self, value: float, write: IO[str]) -> None: ... + def dump_unicode(self, value: str, write: IO[str], escape: Callable[[str], str] = ...) -> None: ... + def dump_bytes(self, value: bytes, write: IO[str]) -> None: ... + def dump_array(self, value: Union[Iterable[_Marshallable]], write: IO[str]) -> None: ... + def dump_struct(self, value: Dict[str, _Marshallable], write: IO[str], escape: Callable[[str], str] = ...) -> None: ... + def dump_datetime(self, value: _XMLDate, write: IO[str]) -> None: ... + def dump_instance(self, value: Union[DateTime, Binary], write: IO[str]) -> None: ... + +class Unmarshaller: + + dispatch: Dict[str, Callable[['Unmarshaller', str], None]] = ... + + _type: Optional[str] + _stack: List[_Marshallable] + _marks: List[int] + _data: List[str] + _value: bool + _methodname: Optional[str] + _encoding: str + append: Callable[[Any], None] + _use_datetime: bool + _use_builtin_types: bool + + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ...) -> None: ... + def close(self) -> Tuple[_Marshallable, ...]: ... + def getmethodname(self) -> Optional[str]: ... + def xml(self, encoding: str, standalone: Any) -> None: ... # Standalone is ignored + def start(self, tag: str, attrs: Dict[str, str]) -> None: ... + def data(self, text: str) -> None: ... + def end(self, tag: str) -> None: ... + def end_dispatch(self, tag: str, data: str) -> Any: ... + def end_nil(self, data: str) -> None: ... + def end_boolean(self, data: str) -> None: ... + def end_int(self, data: str) -> None: ... + def end_double(self, data: str) -> None: ... + def end_bigdecimal(self, data: str) -> None: ... + def end_string(self, data: str) -> None: ... + def end_array(self, data: str) -> None: ... + def end_struct(self, data: str) -> None: ... + def end_base64(self, data: str) -> None: ... + def end_dateTime(self, data: str) -> None: ... + def end_value(self, data: str) -> None: ... + def end_params(self, data: str) -> None: ... + def end_fault(self, data: str) -> None: ... + def end_methodName(self, data: str) -> None: ... + +class _MultiCallMethod: # undocumented + + __call_list: List[Tuple[str, Tuple[_Marshallable, ...]]] + __name: str + + def __init__(self, call_list: List[Tuple[str, _Marshallable]], name: str) -> None: ... + def __getattr__(self, name: str) -> _MultiCallMethod: ... + def __call__(self, *args: _Marshallable) -> None: ... + +class MultiCallIterator: # undocumented + + results: List[List[_Marshallable]] + + def __init__(self, results: List[List[_Marshallable]]) -> None: ... + def __getitem__(self, i: int) -> _Marshallable: ... + +class MultiCall: + + __server: ServerProxy + __call_list: List[Tuple[str, Tuple[_Marshallable, ...]]] + + def __init__(self, server: ServerProxy) -> None: ... + def __repr__(self) -> str: ... + def __getattr__(self, item: str) -> _MultiCallMethod: ... + def __call__(self) -> MultiCallIterator: ... + +# A little white lie +FastMarshaller: Optional[Marshaller] +FastParser: Optional[ExpatParser] +FastUnmarshaller: Optional[Unmarshaller] + +def getparser(use_datetime: bool = ..., use_builtin_types: bool = ...) -> Tuple[ExpatParser, Unmarshaller]: ... +def dumps(params: Union[Fault, Tuple[_Marshallable]], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... +def loads(data: str, use_datetime: bool = ..., use_builtin_types: bool = ...) -> Tuple[Tuple[_Marshallable, ...], Optional[str]]: ... + +def gzip_encode(data: bytes) -> bytes: ... # undocumented +def gzip_decode(data: bytes, max_decode: int = ...) -> bytes: ... # undocumented + +class GzipDecodedResponse(gzip.GzipFile): # undocumented + + io: io.BytesIO + + def __init__(self, response: IO[bytes]) -> None: ... + def close(self) -> None: ... + +class _Method: # undocumented + + __send: Callable[[str, Tuple[_Marshallable, ...]], _Marshallable] + __name: str + + def __init__(self, send: Callable[[str, Tuple[_Marshallable, ...]], _Marshallable], name: str) -> None: ... + def __getattr__(self, name: str) -> _Method: ... + def __call__(self, args: _Marshallable) -> None: ... + +class Transport: + + user_agent: str = ... + accept_gzip_encoding: bool = ... + encode_threshold: Optional[int] = ... + + _use_datetime: bool + _use_builtin_types: bool + _connection: Tuple[Optional[_HostType], Optional[http.client.HTTPConnection]] + _headers: List[Tuple[str, str]] + _extra_headers: List[Tuple[str, str]] + + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ...) -> None: ... + def request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... + def single_request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... + def getparser(self) -> Tuple[ExpatParser, Unmarshaller]: ... + def get_host_info(self, host: _HostType) -> Tuple[str, List[Tuple[str, str]], Dict[str, str]]: ... + def make_connection(self, host: _HostType) -> http.client.HTTPConnection: ... + def close(self) -> None: ... + def send_request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], debug: bool) -> http.client.HTTPConnection: ... + def send_headers(self, connection: http.client.HTTPConnection, headers: List[Tuple[str, str]]) -> None: ... + def send_content(self, connection: http.client.HTTPConnection, request_body: Union[bytes, Iterable[bytes], str]) -> None: ... + def parse_response(self, response: http.client.HTTPResponse) -> Tuple[_Marshallable, ...]: ... + +class SafeTransport(Transport): + + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + def make_connection(self, host: _HostType) -> http.client.HTTPSConnection: ... + +class ServerProxy: + + __host: str + __handler: str + __transport: Transport + __encoding: str + __verbose: bool + __allow_none: bool + + def __init__(self, uri, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + def __repr__(self) -> str: ... + def __getattr__(self, name: str) -> _Method: ... + @overload + def __call__(self, attr: Literal["close"]) -> Callable[[], None]: ... + @overload + def __call__(self, attr: Literal["transport"]) -> Transport: ... + @overload + def __call__(self, attr: str) -> Union[Callable[[], None], Transport]: ... + def __enter__(self) -> ServerProxy: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> None: ... + def __close(self) -> None: ... # undocumented + def __request(self, methodname: str, params: Tuple[_Marshallable, ...]) -> Tuple[_Marshallable, ...]: ... # undocumented + +Server = ServerProxy From 0a904a2d5e4d51eab18ce553f0b0c00f1d7106fa Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 22:28:15 -0500 Subject: [PATCH 02/12] Add xmlrpc server module, update client --- stdlib/3/xmlrpc/client.pyi | 2 +- stdlib/3/xmlrpc/server.pyi | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 stdlib/3/xmlrpc/server.pyi diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index d3afb4ab86f8..43ea37d7463e 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -200,7 +200,7 @@ FastParser: Optional[ExpatParser] FastUnmarshaller: Optional[Unmarshaller] def getparser(use_datetime: bool = ..., use_builtin_types: bool = ...) -> Tuple[ExpatParser, Unmarshaller]: ... -def dumps(params: Union[Fault, Tuple[_Marshallable]], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... +def dumps(params: Union[Fault, Tuple[_Marshallable, ...]], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... def loads(data: str, use_datetime: bool = ..., use_builtin_types: bool = ...) -> Tuple[Tuple[_Marshallable, ...], Optional[str]]: ... def gzip_encode(data: bytes) -> bytes: ... # undocumented diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi new file mode 100644 index 000000000000..04815d22bb51 --- /dev/null +++ b/stdlib/3/xmlrpc/server.pyi @@ -0,0 +1,99 @@ +import http.server +import socketserver +import pydoc + +from xmlrpc.client import Fault +from typing import Any, Callable, Dict, Iterable, List, Optional, Pattern, Tuple, Type, Union +from datetime import datetime + +_Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime] + +def resolve_dotted_attribute(obj: Any, attr: str, allow_dotted_names: bool = ...) -> Any: ... # undocumented +def list_public_methods(obj: Any) -> List[str]: ... # undocumented + +class SimpleXMLRPCDispatcher: # undocumented + + funcs: Dict[str, Callable[[_Marshallable, ...], _Marshallable]] + instance: Optional[Any] + allow_none: bool + encoding: str + use_builtin_types: bool + + def __init__(self, allow_none: bool = ..., encoding: Optional[str] = ..., use_builtin_types: bool = ...) -> None: ... + def register_instance(self, instance: Any, allow_dotted_names: bool = ...) -> None: ... + def register_function(self, function: Optional[Callable[[_Marshallable, ...], _Marshallable]] = ..., name: Optional[str] = ...) -> Callable[[...], Any]: ... + def register_introspection_functions(self) -> None: ... + def register_multicall_functions(self) -> None: ... + def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... # undocumented + def system_listMethods(self) -> List[str]: ... # undocumented + def system_methodSignature(self, method_name: str) -> List[Type[Any]]: ... # undocumented + def system_methodHelp(self, method_name: str) -> str: ... # undocumented + def system_multicall(self, call_list: List[Dict[str, _Marshallable]]) -> List[_Marshallable]: ... # undocumented + def _dispatch(self, method: str, params: Iterable[_Marshallable]) -> _Marshallable: ... # undocumented + +class SimpleXMLRPCRequestHandler(http.server.BaseHTTPRequestHandler): + + rpc_paths: Tuple[str, str] = ... + encode_threshold: int = ... # undocumented + wbufsize: int = ... + disable_nagle_algorithm: bool = ... + aepattern: Pattern[str] # undocumented + + def accept_encodings(self) -> Dict[str, float]: ... + def is_rpc_path_valid(self) -> bool: ... + def do_POST(self) -> None: ... + def decode_request_content(self, data: bytes) -> bytes: ... + def report_404(self) -> None: ... + def log_request(self, code: Union[int, str] = ..., size: Union[int, str] = ...) -> None: ... + +class SimpleXMLRPCServer(socketserver.TCPServer, SimpleXMLRPCDispatcher): + + allow_reuse_address: bool = ... + _send_traceback_handler: bool = ... + + def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + +class MultiPathXMLRPCServer(SimpleXMLRPCServer): # undocumented + + dispatchers: Dict[str, ] + allow_none: bool + encoding: str + + def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + def add_dispatcher(self, path: str, dispatcher: SimpleXMLRPCDispatcher) -> SimpleXMLRPCDispatcher: ... + def get_dispatcher(self, path: str) -> SimpleXMLRPCDispatcher: ... + def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... + +class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): + + def __init__(self, allow_none: bool = ..., encoding: Optional[str] = ..., use_builtin_types: bool = ...) -> None: ... + def handle_xmlrpc(self, request_text: str) -> None: ... + def handle_get(self) -> None: ... + def handle_request(self, request_text: Optional[str] = ...) -> None: ... + +class ServerHTMLDoc(pydoc.HTMLDoc): # undocumented + + def docserver(self, server_name: str, package_documentation: str, methods: Dict[str, str]) -> str: ... + +class XMLRPCDocGenerator: # undocumented + + server_name: str + server_documentation: str + server_title: str + + def __init__(self) -> None: ... + def set_server_title(self, server_title: str) -> None: ... + def set_server_documentation(self, server_documentation: str) -> None: ... + def generate_html_documentation(self) -> str: ... + +class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): + + def do_GET(self) -> None: ... + +class DocXMLRPCServer(SimpleXMLRPCServer, XMLRPCDocGenerator): + + def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + +class DocCGIXMLRPCRequestHandler(CGIXMLRPCRequestHandler, XMLRPCDocGenerator): + + def __init__(self) -> None: ... From a21e1fb709e305cd1b542ea7edeb72c5552c3356 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 22:36:30 -0500 Subject: [PATCH 03/12] Fix mypy errors with protocol and Dict fix --- stdlib/3/xmlrpc/server.pyi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index 04815d22bb51..4eced9aa6a09 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -3,17 +3,19 @@ import socketserver import pydoc from xmlrpc.client import Fault -from typing import Any, Callable, Dict, Iterable, List, Optional, Pattern, Tuple, Type, Union +from typing import Any, Callable, Dict, Iterable, List, Optional, Pattern, Protocol, Tuple, Type, Union from datetime import datetime _Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime] +class _DispatchProtocol(Protocol): + def __call__(self, *args: _Marshallable) -> _Marshallable: ... def resolve_dotted_attribute(obj: Any, attr: str, allow_dotted_names: bool = ...) -> Any: ... # undocumented def list_public_methods(obj: Any) -> List[str]: ... # undocumented class SimpleXMLRPCDispatcher: # undocumented - funcs: Dict[str, Callable[[_Marshallable, ...], _Marshallable]] + funcs: Dict[str, _DispatchProtocol] instance: Optional[Any] allow_none: bool encoding: str @@ -21,7 +23,7 @@ class SimpleXMLRPCDispatcher: # undocumented def __init__(self, allow_none: bool = ..., encoding: Optional[str] = ..., use_builtin_types: bool = ...) -> None: ... def register_instance(self, instance: Any, allow_dotted_names: bool = ...) -> None: ... - def register_function(self, function: Optional[Callable[[_Marshallable, ...], _Marshallable]] = ..., name: Optional[str] = ...) -> Callable[[...], Any]: ... + def register_function(self, function: Optional[_DispatchProtocol] = ..., name: Optional[str] = ...) -> Callable[..., Any]: ... def register_introspection_functions(self) -> None: ... def register_multicall_functions(self) -> None: ... def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... # undocumented @@ -55,7 +57,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer, SimpleXMLRPCDispatcher): class MultiPathXMLRPCServer(SimpleXMLRPCServer): # undocumented - dispatchers: Dict[str, ] + dispatchers: Dict[str, SimpleXMLRPCDispatcher] allow_none: bool encoding: str From 8b0f6ccfc1776353c033665c27975adfe0b1cbf9 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 22:58:31 -0500 Subject: [PATCH 04/12] Add Type[] around requestHandler --- stdlib/3/xmlrpc/server.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index 4eced9aa6a09..d9fb51fd6af2 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -53,7 +53,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer, SimpleXMLRPCDispatcher): allow_reuse_address: bool = ... _send_traceback_handler: bool = ... - def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + def __init__(self, addr: Tuple[str, int], requestHandler: Type[SimpleXMLRPCRequestHandler] = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... class MultiPathXMLRPCServer(SimpleXMLRPCServer): # undocumented @@ -61,7 +61,7 @@ class MultiPathXMLRPCServer(SimpleXMLRPCServer): # undocumented allow_none: bool encoding: str - def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + def __init__(self, addr: Tuple[str, int], requestHandler: Type[SimpleXMLRPCRequestHandler] = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... def add_dispatcher(self, path: str, dispatcher: SimpleXMLRPCDispatcher) -> SimpleXMLRPCDispatcher: ... def get_dispatcher(self, path: str) -> SimpleXMLRPCDispatcher: ... def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... @@ -94,7 +94,7 @@ class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): class DocXMLRPCServer(SimpleXMLRPCServer, XMLRPCDocGenerator): - def __init__(self, addr: Tuple[str, int], requestHandler: SimpleXMLRPCRequestHandler = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... + def __init__(self, addr: Tuple[str, int], requestHandler: Type[SimpleXMLRPCRequestHandler] = ..., logRequests: bool = ..., allow_none: bool = ..., encoding: Optional[str] = ..., bind_and_activate: bool = ..., use_builtin_types: bool = ...) -> None: ... class DocCGIXMLRPCRequestHandler(CGIXMLRPCRequestHandler, XMLRPCDocGenerator): From a2cefc92f6af313868d34298e280510dbf873c3c Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 23:00:38 -0500 Subject: [PATCH 05/12] Fix docroutine incompatible override --- stdlib/3/xmlrpc/server.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index d9fb51fd6af2..b32b19517b60 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -3,7 +3,7 @@ import socketserver import pydoc from xmlrpc.client import Fault -from typing import Any, Callable, Dict, Iterable, List, Optional, Pattern, Protocol, Tuple, Type, Union +from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Pattern, Protocol, Tuple, Type, Union from datetime import datetime _Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime] @@ -75,6 +75,7 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): class ServerHTMLDoc(pydoc.HTMLDoc): # undocumented + def docroutine(self, object: object, name: str, mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ..., cl: Optional[type] = ..., *ignored) -> str: ... # type: ignore def docserver(self, server_name: str, package_documentation: str, methods: Dict[str, str]) -> str: ... class XMLRPCDocGenerator: # undocumented From 4cb35b70a2f9296a8b4beb67f4171afb5365016f Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 23:03:58 -0500 Subject: [PATCH 06/12] Whoops, ignored is also missing --- stdlib/3/xmlrpc/server.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index b32b19517b60..f8e835fafe50 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -75,7 +75,7 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): class ServerHTMLDoc(pydoc.HTMLDoc): # undocumented - def docroutine(self, object: object, name: str, mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ..., cl: Optional[type] = ..., *ignored) -> str: ... # type: ignore + def docroutine(self, object: object, name: str, mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ..., cl: Optional[type] = ...) -> str: ... # type: ignore def docserver(self, server_name: str, package_documentation: str, methods: Dict[str, str]) -> str: ... class XMLRPCDocGenerator: # undocumented From 5935e5d845f3d839620dc59750cd0af489cbd227 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 23:28:12 -0500 Subject: [PATCH 07/12] Remove unnecessary str/repr overrides --- stdlib/3/xmlrpc/client.pyi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index 43ea37d7463e..2d7e2507d150 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -47,7 +47,6 @@ class ProtocolError(Error): headers: Dict[str, str] def __init__(self, url: str, errcode: int, errmsg: str, headers: Dict[str, str]) -> None: ... - def __repr__(self) -> str: ... class ResponseError(Error): ... @@ -57,7 +56,6 @@ class Fault(Error): faultString: str def __init__(self, faultCode: str, faultString: str, **extra: Any) -> None: ... - def __repr__(self) -> str: ... boolean = bool @@ -76,8 +74,6 @@ class DateTime: def __gt__(self, other: _DateTimeComparable) -> bool: ... def __ge__(self, other: _DateTimeComparable) -> bool: ... def __eq__(self, other: _DateTimeComparable) -> bool: ... # type: ignore - def __str__(self) -> str: ... - def __repr__(self) -> str: ... def make_comparable(self, other: _DateTimeComparable) -> Tuple[str, str]: ... # undocumented def timetuple(self) -> time.struct_time: ... # undocumented def decode(self, data: Any) -> None: ... @@ -91,7 +87,6 @@ class Binary: data: bytes def __init__(self, data: Optional[bytes] = ...) -> None: ... - def __str__(self) -> str: ... def __eq__(self, other: Union[Binary, bytes]) -> bool: ... # type: ignore def decode(self, data: bytes) -> None: ... def encode(self, out: IO[str]) -> None: ... @@ -190,7 +185,6 @@ class MultiCall: __call_list: List[Tuple[str, Tuple[_Marshallable, ...]]] def __init__(self, server: ServerProxy) -> None: ... - def __repr__(self) -> str: ... def __getattr__(self, item: str) -> _MultiCallMethod: ... def __call__(self) -> MultiCallIterator: ... @@ -261,7 +255,6 @@ class ServerProxy: __allow_none: bool def __init__(self, uri, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... - def __repr__(self) -> str: ... def __getattr__(self, name: str) -> _Method: ... @overload def __call__(self, attr: Literal["close"]) -> Callable[[], None]: ... From fa08cabe6eab7862fa477795ae920c7be9c75283 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Mar 2020 23:49:30 -0500 Subject: [PATCH 08/12] Remove unnecessary __eq__ and quotes around Unmarshall. DateTime __eq__ left for now --- stdlib/3/xmlrpc/client.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index 2d7e2507d150..3bd978b80465 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -87,7 +87,6 @@ class Binary: data: bytes def __init__(self, data: Optional[bytes] = ...) -> None: ... - def __eq__(self, other: Union[Binary, bytes]) -> bool: ... # type: ignore def decode(self, data: bytes) -> None: ... def encode(self, out: IO[str]) -> None: ... @@ -127,7 +126,7 @@ class Marshaller: class Unmarshaller: - dispatch: Dict[str, Callable[['Unmarshaller', str], None]] = ... + dispatch: Dict[str, Callable[[Unmarshaller, str], None]] = ... _type: Optional[str] _stack: List[_Marshallable] From 3d722599367758c614705b3f46964ae98fdb6bd8 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 7 Mar 2020 13:21:43 -0500 Subject: [PATCH 09/12] Fix problems from review --- stdlib/3/xmlrpc/client.pyi | 40 ++++++++++++++++++++++---------------- stdlib/3/xmlrpc/server.pyi | 5 +++-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index 3bd978b80465..ef826420b121 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -4,7 +4,7 @@ import time import gzip import http.client -from typing import Any, Callable, Dict, IO, Iterable, List, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Iterable, List, Mapping, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload from types import TracebackType from datetime import datetime @@ -111,18 +111,18 @@ class Marshaller: def __init__(self, encoding: Optional[str] = ..., allow_none: bool = ...) -> None: ... def dumps(self, values: Union[Fault, Iterable[_Marshallable]]) -> str: ... - def __dump(self, value: Union[_Marshallable]) -> None: ... # undocumented - def dump_nil(self, value: None, write: IO[str]) -> None: ... - def dump_bool(self, value: bool, write: IO[str]) -> None: ... - def dump_long(self, value: int, write: IO[str]) -> None: ... - def dump_int(self, value: int, write: IO[str]) -> None: ... - def dump_double(self, value: float, write: IO[str]) -> None: ... - def dump_unicode(self, value: str, write: IO[str], escape: Callable[[str], str] = ...) -> None: ... - def dump_bytes(self, value: bytes, write: IO[str]) -> None: ... - def dump_array(self, value: Union[Iterable[_Marshallable]], write: IO[str]) -> None: ... - def dump_struct(self, value: Dict[str, _Marshallable], write: IO[str], escape: Callable[[str], str] = ...) -> None: ... - def dump_datetime(self, value: _XMLDate, write: IO[str]) -> None: ... - def dump_instance(self, value: Union[DateTime, Binary], write: IO[str]) -> None: ... + def __dump(self, value: Union[_Marshallable], write: Callable[[str], Any]) -> None: ... # undocumented + def dump_nil(self, value: None, write: Callable[[str], Any]) -> None: ... + def dump_bool(self, value: bool, write: Callable[[str], Any]) -> None: ... + def dump_long(self, value: int, write: Callable[[str], Any]) -> None: ... + def dump_int(self, value: int, write: Callable[[str], Any]) -> None: ... + def dump_double(self, value: float, write: Callable[[str], Any]) -> None: ... + def dump_unicode(self, value: str, write: Callable[[str], Any], escape: Callable[[str], str] = ...) -> None: ... + def dump_bytes(self, value: bytes, write: Callable[[str], Any]) -> None: ... + def dump_array(self, value: Iterable[_Marshallable], write: Callable[[str], Any]) -> None: ... + def dump_struct(self, value: Mapping[str, _Marshallable], write: Callable[[str], Any], escape: Callable[[str], str] = ...) -> None: ... + def dump_datetime(self, value: _XMLDate, write: Callable[[str], Any]) -> None: ... + def dump_instance(self, value: object, write: Callable[[str], Any]) -> None: ... class Unmarshaller: @@ -146,7 +146,7 @@ class Unmarshaller: def start(self, tag: str, attrs: Dict[str, str]) -> None: ... def data(self, text: str) -> None: ... def end(self, tag: str) -> None: ... - def end_dispatch(self, tag: str, data: str) -> Any: ... + def end_dispatch(self, tag: str, data: str) -> None: ... def end_nil(self, data: str) -> None: ... def end_boolean(self, data: str) -> None: ... def end_int(self, data: str) -> None: ... @@ -213,7 +213,7 @@ class _Method: # undocumented def __init__(self, send: Callable[[str, Tuple[_Marshallable, ...]], _Marshallable], name: str) -> None: ... def __getattr__(self, name: str) -> _Method: ... - def __call__(self, args: _Marshallable) -> None: ... + def __call__(self, *args: _Marshallable) -> _Marshallable: ... class Transport: @@ -227,7 +227,10 @@ class Transport: _headers: List[Tuple[str, str]] _extra_headers: List[Tuple[str, str]] - def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ...) -> None: ... + if sys.version_info >= (3, 8): + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ...) -> None: ... + else: + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ...) -> None: ... def request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... def single_request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... def getparser(self) -> Tuple[ExpatParser, Unmarshaller]: ... @@ -241,7 +244,10 @@ class Transport: class SafeTransport(Transport): - def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + if sys.version_info >= (3, 8): + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + else: + def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, context: Optional[Any] = ...) -> None: ... def make_connection(self, host: _HostType) -> http.client.HTTPSConnection: ... class ServerProxy: diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index f8e835fafe50..d987794cb7b3 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -28,7 +28,7 @@ class SimpleXMLRPCDispatcher: # undocumented def register_multicall_functions(self) -> None: ... def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... # undocumented def system_listMethods(self) -> List[str]: ... # undocumented - def system_methodSignature(self, method_name: str) -> List[Type[Any]]: ... # undocumented + def system_methodSignature(self, method_name: str) -> str: ... # undocumented def system_methodHelp(self, method_name: str) -> str: ... # undocumented def system_multicall(self, call_list: List[Dict[str, _Marshallable]]) -> List[_Marshallable]: ... # undocumented def _dispatch(self, method: str, params: Iterable[_Marshallable]) -> _Marshallable: ... # undocumented @@ -44,7 +44,7 @@ class SimpleXMLRPCRequestHandler(http.server.BaseHTTPRequestHandler): def accept_encodings(self) -> Dict[str, float]: ... def is_rpc_path_valid(self) -> bool: ... def do_POST(self) -> None: ... - def decode_request_content(self, data: bytes) -> bytes: ... + def decode_request_content(self, data: bytes) -> Optional[bytes]: ... def report_404(self) -> None: ... def log_request(self, code: Union[int, str] = ..., size: Union[int, str] = ...) -> None: ... @@ -86,6 +86,7 @@ class XMLRPCDocGenerator: # undocumented def __init__(self) -> None: ... def set_server_title(self, server_title: str) -> None: ... + def set_server_name(self, server_name: str) -> None: ... def set_server_documentation(self, server_documentation: str) -> None: ... def generate_html_documentation(self) -> str: ... From f88db8770dd19b20ea0c75913972800a8f1eb627 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 7 Mar 2020 20:11:48 -0500 Subject: [PATCH 10/12] Fix various version-specific differences, make request_type conservative (only bytes, guaranteed to have same len as number of bytes) --- stdlib/3/xmlrpc/client.pyi | 16 ++++++++++------ stdlib/3/xmlrpc/server.pyi | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index ef826420b121..b83856c972ee 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -151,7 +151,8 @@ class Unmarshaller: def end_boolean(self, data: str) -> None: ... def end_int(self, data: str) -> None: ... def end_double(self, data: str) -> None: ... - def end_bigdecimal(self, data: str) -> None: ... + if sys.version_info >= (3, 6): + def end_bigdecimal(self, data: str) -> None: ... def end_string(self, data: str) -> None: ... def end_array(self, data: str) -> None: ... def end_struct(self, data: str) -> None: ... @@ -231,15 +232,15 @@ class Transport: def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ...) -> None: ... else: def __init__(self, use_datetime: bool = ..., use_builtin_types: bool = ...) -> None: ... - def request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... - def single_request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... + def request(self, host: _HostType, handler: str, request_body: bytes, verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... + def single_request(self, host: _HostType, handler: str, request_body: bytes, verbose: bool = ...) -> Tuple[_Marshallable, ...]: ... def getparser(self) -> Tuple[ExpatParser, Unmarshaller]: ... def get_host_info(self, host: _HostType) -> Tuple[str, List[Tuple[str, str]], Dict[str, str]]: ... def make_connection(self, host: _HostType) -> http.client.HTTPConnection: ... def close(self) -> None: ... - def send_request(self, host: _HostType, handler: str, request_body: Union[bytes, Iterable[bytes], str], debug: bool) -> http.client.HTTPConnection: ... + def send_request(self, host: _HostType, handler: str, request_body: bytes, debug: bool) -> http.client.HTTPConnection: ... def send_headers(self, connection: http.client.HTTPConnection, headers: List[Tuple[str, str]]) -> None: ... - def send_content(self, connection: http.client.HTTPConnection, request_body: Union[bytes, Iterable[bytes], str]) -> None: ... + def send_content(self, connection: http.client.HTTPConnection, request_body: bytes) -> None: ... def parse_response(self, response: http.client.HTTPResponse) -> Tuple[_Marshallable, ...]: ... class SafeTransport(Transport): @@ -259,7 +260,10 @@ class ServerProxy: __verbose: bool __allow_none: bool - def __init__(self, uri, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + if sys.version_info >= (3, 8): + def __init__(self, uri, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., use_builtin_types: bool = ..., *, headers: Iterable[Tuple[str, str]] = ..., context: Optional[Any] = ...) -> None: ... + else: + def __init__(self, uri, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., use_builtin_types: bool = ..., *, context: Optional[Any] = ...) -> None: ... def __getattr__(self, name: str) -> _Method: ... @overload def __call__(self, attr: Literal["close"]) -> Callable[[], None]: ... diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index d987794cb7b3..e7b37708050e 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -1,6 +1,7 @@ import http.server import socketserver import pydoc +import sys from xmlrpc.client import Fault from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Pattern, Protocol, Tuple, Type, Union @@ -23,7 +24,10 @@ class SimpleXMLRPCDispatcher: # undocumented def __init__(self, allow_none: bool = ..., encoding: Optional[str] = ..., use_builtin_types: bool = ...) -> None: ... def register_instance(self, instance: Any, allow_dotted_names: bool = ...) -> None: ... - def register_function(self, function: Optional[_DispatchProtocol] = ..., name: Optional[str] = ...) -> Callable[..., Any]: ... + if sys.version_info >= (3, 7): + def register_function(self, function: Optional[_DispatchProtocol] = ..., name: Optional[str] = ...) -> Callable[..., Any]: ... + else: + def register_function(self, funciton: _DispatchProtocol, name: Optional[str] = ...) -> Callable[..., Any]: ... def register_introspection_functions(self) -> None: ... def register_multicall_functions(self) -> None: ... def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... # undocumented From ce47bfb0a5c23b0856ba9940ac7f82479362a22b Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 7 Mar 2020 20:16:16 -0500 Subject: [PATCH 11/12] Silly misspelling --- stdlib/3/xmlrpc/server.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/xmlrpc/server.pyi b/stdlib/3/xmlrpc/server.pyi index e7b37708050e..97f3a5ac483f 100644 --- a/stdlib/3/xmlrpc/server.pyi +++ b/stdlib/3/xmlrpc/server.pyi @@ -27,7 +27,7 @@ class SimpleXMLRPCDispatcher: # undocumented if sys.version_info >= (3, 7): def register_function(self, function: Optional[_DispatchProtocol] = ..., name: Optional[str] = ...) -> Callable[..., Any]: ... else: - def register_function(self, funciton: _DispatchProtocol, name: Optional[str] = ...) -> Callable[..., Any]: ... + def register_function(self, function: _DispatchProtocol, name: Optional[str] = ...) -> Callable[..., Any]: ... def register_introspection_functions(self) -> None: ... def register_multicall_functions(self) -> None: ... def _marshaled_dispatch(self, data: str, dispatch_method: Optional[Callable[[Optional[str], Tuple[_Marshallable, ...]], Union[Fault, Tuple[_Marshallable, ...]]]] = ..., path: Optional[Any] = ...) -> str: ... # undocumented From 7cd61ddc46899f84c2d16fbb0d330ffd00a0e9db Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 3 Apr 2020 21:00:27 -0400 Subject: [PATCH 12/12] Change from IO to ad-hoc minimal protocols --- stdlib/3/xmlrpc/client.pyi | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/3/xmlrpc/client.pyi b/stdlib/3/xmlrpc/client.pyi index b83856c972ee..e54c928b2659 100644 --- a/stdlib/3/xmlrpc/client.pyi +++ b/stdlib/3/xmlrpc/client.pyi @@ -16,6 +16,10 @@ else: _T = TypeVar("_T") class _HasTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... +class _HasWrite(Protocol): + def write(self, __o: str) -> None: ... +class _HasRead(Protocol): + def read(self) -> bytes: ... _DateTimeComparable = Union[DateTime, datetime, str, _HasTimeTuple] _Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime, DateTime, Binary] _XMLDate = Union[int, datetime, Tuple[int, ...], time.struct_time] @@ -77,7 +81,7 @@ class DateTime: def make_comparable(self, other: _DateTimeComparable) -> Tuple[str, str]: ... # undocumented def timetuple(self) -> time.struct_time: ... # undocumented def decode(self, data: Any) -> None: ... - def encode(self, out: IO[str]) -> None: ... + def encode(self, out: _HasWrite) -> None: ... def _datetime(data: Any) -> DateTime: ... # undocumented def _datetime_type(data: str) -> datetime: ... # undocumented @@ -88,7 +92,7 @@ class Binary: def __init__(self, data: Optional[bytes] = ...) -> None: ... def decode(self, data: bytes) -> None: ... - def encode(self, out: IO[str]) -> None: ... + def encode(self, out: _HasWrite) -> None: ... def _binary(data: bytes) -> Binary: ... # undocumented @@ -102,7 +106,7 @@ class ExpatParser: # undocumented class Marshaller: - dispatch: Dict[Type[Any], Callable[[Marshaller, Any, IO[str]], None]] = ... # TODO: Replace 'Any' with some kind of binding + dispatch: Dict[Type[Any], Callable[[Marshaller, Any, Callable[[str], Any]], None]] = ... # TODO: Replace 'Any' with some kind of binding memo: Dict[Any, None] data: None @@ -204,7 +208,7 @@ class GzipDecodedResponse(gzip.GzipFile): # undocumented io: io.BytesIO - def __init__(self, response: IO[bytes]) -> None: ... + def __init__(self, response: _HasRead) -> None: ... def close(self) -> None: ... class _Method: # undocumented