Improved HTTP responses + code cleanup

parent 447d85e0
......@@ -2,6 +2,10 @@ import os
import yaml
from colorlog import warning as warn, info
CONFIG_GLOBAL = {
"TIMEZONE": "GMT"
}
CONFIG_HTTP = {
"DOC_ROOT": "doc-root",
"DOC_DEFAULT_NAME": "index.html",
......@@ -20,6 +24,7 @@ CONFIG_NACM = {
}
CONFIG = {
"GLOBAL": CONFIG_GLOBAL,
"HTTP_SERVER": CONFIG_HTTP,
"NACM": CONFIG_NACM
}
......
GLOBAL:
TIMEZONE: "Europe/Prague"
HTTP_SERVER:
DOC_ROOT: "jetconf/doc-root"
DOC_DEFAULT_NAME: "index.html"
......
from typing import Dict, Any
from datetime import datetime
from pytz import timezone
from yangson.instance import InstanceIdentifier, MemberName, EntryKeys
......@@ -25,3 +27,15 @@ class DataHelpers:
new_node.append(n)
n = new_node
return n
class DateTimeHelpers:
@staticmethod
def to_httpdate_str(dt: datetime, local_tz: str=None) -> str:
if local_tz is not None:
dtl = timezone(local_tz).localize(dt)
dt_gmt = dtl.astimezone(timezone("GMT"))
else:
dt_gmt = dt
return dt_gmt.strftime("%a, %d %b %Y %H:%M:%S GMT")
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment