Skip to content

Commit

Permalink
🐛 修复漏洞
Browse files Browse the repository at this point in the history
  • Loading branch information
SilianZ committed Mar 9, 2024
1 parent e9c6a3f commit 21c7682
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions container/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import yaml
from typing import Union

class CFG:
def __init__(self, path: str) -> None:
Expand All @@ -9,18 +10,18 @@ def __init__(self, path: str) -> None:
self.load()

def load(self):
with open(self.file, 'r', encoding="utf-8") as f:
with open(self.file, "r", encoding="utf-8") as f:
self.cfg = yaml.load(f.read(), Loader=yaml.FullLoader)

def get(self, key, default):
value = self.cfg.get(key, None)
def get(self, key, default_):
value = self.cfg.get(key, default_)
if value is None:
self.write(key, default)
self.write(key, default_)
return value

def write(self, key, value):
self.cfg[key] = value
with open(self.file, 'w', encoding="utf-8") as f:
with open(self.file, "w", encoding="utf-8") as f:
yaml.dump(data=self.cfg, stream=f, allow_unicode=True)

Config: CFG = CFG("./config/config.yaml")
Expand Down

0 comments on commit 21c7682

Please sign in to comment.