socket_stream.py 1013 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # *****************************************************************************
  3. # Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
  4. # Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
  5. #
  6. # Distributed under the terms of the BSD License. The full license is in
  7. # the file COPYING, distributed as part of this software.
  8. # *****************************************************************************
  9. from socket import AF_INET, SOCK_DGRAM, socket
  10. from pyreadline3.unicode_helper import ensure_str
  11. class SocketStream:
  12. def __init__(
  13. self,
  14. host: str,
  15. port: int,
  16. ) -> None:
  17. self.__host = host
  18. self.__port = port
  19. self.__socket = socket(AF_INET, SOCK_DGRAM)
  20. def write(self, record: str) -> None:
  21. self.__socket.sendto(
  22. ensure_str(record),
  23. (self.__host, self.__port),
  24. )
  25. def flush(self) -> None:
  26. pass
  27. def close(self) -> None:
  28. pass