from functools import wraps
# Type hint for python <= 3.8
from typing import Any, Dict, List, Tuple
-from typing import Optional, Union
+from typing import Iterator, Optional, Union
HELLO_PREFIX = "OK MPD "
ERROR_PREFIX = "ACK "
self._wfile.write(f"{line!s}\n")
self._wfile.flush()
- def _write_command(self, command, args=None):
+ def _write_command(self, command, args: Optional[list[str]] = None):
if args is None:
args = []
parts = [command]
raise CommandError('new line found in the command!')
self._write_line(" ".join(parts))
- def _read_binary(self, amount):
+ def _read_binary(self, amount: int):
chunk = bytearray()
while amount > 0:
result = self._rbfile.read(amount)
raise ProtocolError(f"Could not parse pair: '{line}'")
return pair
- def _read_pairs(self, separator=": ", binary: bool =False):
+ def _read_pairs(self, separator: str =": ", binary: bool =False):
pair = self._read_pair(separator, binary=binary)
while pair:
yield pair
for _, value in self._read_pairs(":"):
yield value
- def _read_objects(self, delimiters: Optional[List[str]] = None):
+ def _read_objects(self, delimiters: Optional[List[str]] = None) -> Iterator[Dict]:
obj: Dict[str,Any] = {}
if delimiters is None:
delimiters = []
def _fetch_playlist(self):
return self._read_playlist()
- def _fetch_object(self):
+ def _fetch_object(self) -> Dict:
objs = list(self._read_objects())
if not objs:
return {}
return objs[0]
@iterator_wrapper
- def _fetch_objects(self, delimiters):
+ def _fetch_objects(self, delimiters: List[str]):
return self._read_objects(delimiters)
def _fetch_changes(self):