Files
NCBM 9009a7c5bc Add type stubs for mido MIDI library
- Created type stubs for various modules in the mido library including messages, midifiles, parser, ports, sockets, syx, tokenizer, and version.
- Implemented type hints for functions and classes to improve type checking and code clarity.
- Added support for MIDI over TCP/IP in sockets module.
- Included methods for reading and writing SYX files in syx module.
- Enhanced the parser functionality with a dedicated Parser class for MIDI byte streams.
- Established a structure for MIDI file handling with MidiFile and MidiTrack classes.
2026-04-26 00:51:40 +08:00

44 lines
1.3 KiB
Python

"""
MIDI over TCP/IP.
"""
import socket
from typing import Literal, overload
from .ports import BaseIOPort, MultiPort
class PortServer(MultiPort):
def __init__(self, host: str, portno: int, backlog: int = 1) -> None: ...
@overload
def accept(self, block: Literal[True] = True) -> SocketPort:
"""
Accept a connection from a client.
Will block until there is a new connection, and then return a
`SocketPort` object.
If `block=False`, `None` will be returned if there is no
new connection waiting.
"""
@overload
def accept(self, block: bool) -> SocketPort | None: ...
class SocketPort(BaseIOPort):
def __init__(self, host: str, portno: int, conn: socket.socket | None = ...) -> None: ...
def connect(host: str, portno: int) -> SocketPort:
"""Connect to a socket port server.
The return value is a `SocketPort` object connected to another
`SocketPort` object at the server end. Messages can be sent either way.
"""
def parse_address(address: str) -> tuple[str, int]:
"""Parse and address on the format host:port.
Returns a tuple (host, port). Raises ValueError if format is
invalid or port is not an integer or out of range.
"""
def format_address(host: str, portno: int) -> str: ...