Skip to content

Commit 4cc7dad

Browse files
author
Jakub Stasiak
committed
Add BaseRequestHandler instance attributes
From the BaseRequestHandler documentation: handle() This function must do all the work required to service a request. The default implementation does nothing. Several instance attributes are available to it; the request is available as self.request; the client address as self.client_address; and the server instance as self.server, in case it needs access to per-server information. The type of self.request is different for datagram or stream services. For stream services, self.request is a socket object; for datagram services, self.request is a pair of string and socket.
1 parent c1b1297 commit 4cc7dad

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

stdlib/3/socketserver.pyi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stubs for socketserver
22

3-
from typing import BinaryIO, Optional, Tuple
3+
from typing import BinaryIO, Generic, Optional, Tuple, TypeVar, Union
44
from socket import SocketType
55
import sys
66
import types
@@ -68,15 +68,23 @@ class ForkingUDPServer(ForkingMixIn, UDPServer): ...
6868
class ThreadingTCPServer(ThreadingMixIn, TCPServer): ...
6969
class ThreadingUDPServer(ThreadingMixIn, UDPServer): ...
7070

71-
class BaseRequestHandler:
71+
72+
_RequestT = TypeVar('_RequestT', Union[SocketType, Tuple[bytes, SocketType]])
73+
# str in case of Unix domain socket
74+
_AddressT = TypeVar('_AddressT', Tuple[str, int], str)
75+
76+
class BaseRequestHandler(Generic[_RequestT, _AddressT]):
77+
request = ... # type: _RequestT
78+
client_address = ... # type: _AddressT
79+
server = ... # type: BaseServer
7280
def setup(self) -> None: ...
7381
def handle(self) -> None: ...
7482
def finish(self) -> None: ...
7583

76-
class StreamRequestHandler(BaseRequestHandler):
84+
class StreamRequestHandler(BaseRequestHandler[SocketType, _AddressT], Generic[_AddressT]):
7785
rfile = ... # type: BinaryIO
7886
wfile = ... # type: BinaryIO
7987

80-
class DatagramRequestHandler(BaseRequestHandler):
88+
class DatagramRequestHandler(BaseRequestHandler[Tuple[bytes, SocketType], _AddressT], Generic[_AddressT]):
8189
rfile = ... # type: BinaryIO
8290
wfile = ... # type: BinaryIO

0 commit comments

Comments
 (0)