ue_pe_web/scripts/03_server/src_students_0/myserver/log.py
2024-03-08 00:47:19 +01:00

98 lines
2.4 KiB
Python

######################################################################
# Copyright (c) Adrien Luxey-Bitri, Boris Baldassari
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
######################################################################
"""
A package for learning network programming in Python.
This module (file) manages the HTTP logging messages.
"""
from myserver.date import now_rfc2616
def log(msg: str):
"""
Logs a message to stdout, with a timestamp.
Output is: `timestamp - message`.
Parameters
----------
- msg : str
The message string to print.
"""
pass
def log_address(addr: tuple[str, int], msg: str):
"""
Logs a message to stdout, with a timestamp and an address (host:port).
Output is: `timestamp - host:port - message`.
Parameters
----------
- addr: tuple[str, int]
The address to print, as a tuple (host, port)
- msg: str
The message string to print.
"""
pass
def log_request(addr: tuple[str, int], req: dict[str, dict]):
"""
Logs a request message to stdout, with a timestamp and an address (host:port).
If the User-Agent header is passed, its value is appended at the end.
Output is: `timestamp - host:port - verb resource`.
Output with User-Agent is: `timestamp - host:port - verb resource - user_agent`.
Parameters
----------
- addr: tuple[str, int]
The address to print, as a tuple (host, port)
- req: dict[str, dict]
The request to print.
"""
msg = None
log_address(addr, msg)
def log_reply(addr: tuple[str, int], req: dict[str, dict], code: int):
"""
Logs an HTTP reply to stdout, with timestamp, address (host:port), code.
If the User-Agent header is passed, its value is appended at the end.
Output is: `timestamp - host:port - HTTP-verb HTTP-resource - code`.
Output with User-Agent is: `timestamp - host:port - HTTP-verb HTTP-resource - code - user_agent`.
Parameters
----------
- addr: tuple[str, int]
The address to print, as a tuple (host, port)
- req: dict[str, dict]
The request to print.
- code: int
The replied code to print.
"""
msg = None
log_address(addr, msg)