I am done

This commit is contained in:
2024-10-30 22:14:35 +01:00
parent 720dc28c09
commit 40e2a747cf
36901 changed files with 5011519 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
from .control import (
start_file_log,
start_socket_log,
stop_file_log,
stop_logging,
stop_socket_log,
)
from .log import log
__all__ = [
"start_file_log",
"start_socket_log",
"stop_file_log",
"stop_logging",
"stop_socket_log",
"log",
]

View File

@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
import os
from logging import FileHandler, Formatter, StreamHandler
from logging.handlers import DEFAULT_TCP_LOGGING_PORT
from typing import Optional
from .logger import LOGGER
from .socket_stream import SocketStream
_default_formatter_str = os.environ.get("PYREADLINE_FORMATTER", "%(message)s")
SOCKET_HANDLER: Optional["StreamHandler[SocketStream]"] = None
FILE_HANDLER: Optional[FileHandler] = None
def start_socket_log(
host: str = "localhost",
port: int = DEFAULT_TCP_LOGGING_PORT,
formatter_str: str = _default_formatter_str,
) -> None:
global SOCKET_HANDLER
if SOCKET_HANDLER is not None:
return
SOCKET_HANDLER = StreamHandler(SocketStream(host, port))
SOCKET_HANDLER.setFormatter(Formatter(formatter_str))
LOGGER.addHandler(SOCKET_HANDLER)
def stop_socket_log() -> None:
global SOCKET_HANDLER
if SOCKET_HANDLER is None:
return
LOGGER.removeHandler(SOCKET_HANDLER)
SOCKET_HANDLER = None
def start_file_log(filename: str) -> None:
global FILE_HANDLER
if FILE_HANDLER is not None:
return
FILE_HANDLER = FileHandler(filename, "w")
LOGGER.addHandler(FILE_HANDLER)
def stop_file_log() -> None:
global FILE_HANDLER
if FILE_HANDLER is None:
return
LOGGER.removeHandler(FILE_HANDLER)
FILE_HANDLER.close()
FILE_HANDLER = None
def stop_logging() -> None:
stop_file_log()
stop_socket_log()

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
from pyreadline3.unicode_helper import ensure_str
from .logger import LOGGER
def log(record: str) -> None:
s = ensure_str(record)
LOGGER.debug(s)

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
import logging
import os
from .null_handler import NULLHandler
_default_log_level = os.environ.get("PYREADLINE_LOG", "DEBUG")
LOGGER = logging.getLogger("PYREADLINE")
LOGGER.setLevel(_default_log_level)
LOGGER.propagate = False
LOGGER.addHandler(NULLHandler())

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
from logging import Handler, LogRecord
class NULLHandler(Handler):
def emit(self, record: LogRecord) -> None:
pass

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
# Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# *****************************************************************************
from socket import AF_INET, SOCK_DGRAM, socket
from pyreadline3.unicode_helper import ensure_str
class SocketStream:
def __init__(
self,
host: str,
port: int,
) -> None:
self.__host = host
self.__port = port
self.__socket = socket(AF_INET, SOCK_DGRAM)
def write(self, record: str) -> None:
self.__socket.sendto(
ensure_str(record),
(self.__host, self.__port),
)
def flush(self) -> None:
pass
def close(self) -> None:
pass