Improve documentation, cleanup duplicated code

This commit is contained in:
2021-03-28 15:03:42 +02:00
parent 07b018d2ab
commit cd053bc74e
5 changed files with 96 additions and 39 deletions

View File

@@ -3,8 +3,11 @@ import os
import pathlib
import re
import urllib
from datetime import datetime
from time import mktime
from typing import Dict
from urllib.parse import urlparse, urlsplit
from wsgiref.handlers import format_date_time
from httplib.exceptions import InvalidStatusLine, InvalidResponse, BadRequest, InvalidRequestLine
from httplib.httpsocket import FORMAT
@@ -58,7 +61,7 @@ def parse_status_line(line: str):
def parse_request_line(line: str):
"""
Parses the specified line as and HTTP request-line.
Parses the specified line as an HTTP request-line.
Returns the method, target as ParseResult and HTTP version from the request-line.
@param line: the request-line to be parsed
@@ -89,6 +92,7 @@ def parse_request_line(line: str):
def parse_headers(lines):
"""
Parses the lines from the `lines` iterator as headers.
@param lines: iterator to retrieve the lines from.
@return: A dictionary with header as key and value as value.
"""
@@ -218,3 +222,12 @@ def get_relative_save_path(path: str):
root = pathlib.PurePath(os.getcwd())
rel = path_obj.relative_to(root)
return str(rel)
def get_date():
"""
Returns a string representation of the current date according to RFC 1123.
"""
now = datetime.now()
stamp = mktime(now.timetuple())
return format_date_time(stamp)