mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
config/linux.py: Removed List and Optional usage
Missed these in the initial PR -- using the python 3.10 versions
This commit is contained in:
parent
a930f5b902
commit
4527177f9b
@ -3,7 +3,6 @@ import os
|
||||
import pathlib
|
||||
import sys
|
||||
from configparser import ConfigParser
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
from config import AbstractConfig, appname, logger
|
||||
|
||||
@ -18,7 +17,7 @@ class LinuxConfig(AbstractConfig):
|
||||
__unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'}
|
||||
__escape_lut = {'\\': '\\', '\n': 'n', ';': ';', '\r': 'r'}
|
||||
|
||||
def __init__(self, filename: Optional[str] = None) -> None:
|
||||
def __init__(self, filename: str | None = None) -> None:
|
||||
super().__init__()
|
||||
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
|
||||
xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser()
|
||||
@ -42,7 +41,7 @@ class LinuxConfig(AbstractConfig):
|
||||
|
||||
self.filename.parent.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
self.config: Optional[ConfigParser] = ConfigParser(comment_prefixes=('#',), interpolation=None)
|
||||
self.config: ConfigParser | None = ConfigParser(comment_prefixes=('#',), interpolation=None)
|
||||
self.config.read(self.filename) # read() ignores files that dont exist
|
||||
|
||||
# Ensure that our section exists. This is here because configparser will happily create files for us, but it
|
||||
@ -85,7 +84,7 @@ class LinuxConfig(AbstractConfig):
|
||||
:param s: str - The string to unescape.
|
||||
:return: str - The unescaped string.
|
||||
"""
|
||||
out: List[str] = []
|
||||
out: list[str] = []
|
||||
i = 0
|
||||
while i < len(s):
|
||||
c = s[i]
|
||||
@ -107,7 +106,7 @@ class LinuxConfig(AbstractConfig):
|
||||
|
||||
return "".join(out)
|
||||
|
||||
def __raw_get(self, key: str) -> Optional[str]:
|
||||
def __raw_get(self, key: str) -> str | None:
|
||||
"""
|
||||
Get a raw data value from the config file.
|
||||
|
||||
@ -183,7 +182,7 @@ class LinuxConfig(AbstractConfig):
|
||||
|
||||
return bool(int(data))
|
||||
|
||||
def set(self, key: str, val: Union[int, str, List[str]]) -> None:
|
||||
def set(self, key: str, val: int | str | list[str]) -> None:
|
||||
"""
|
||||
Set the given key's data to the given value.
|
||||
|
||||
@ -192,7 +191,7 @@ class LinuxConfig(AbstractConfig):
|
||||
if self.config is None:
|
||||
raise ValueError('attempt to use a closed config')
|
||||
|
||||
to_set: Optional[str] = None
|
||||
to_set: str | None = None
|
||||
if isinstance(val, bool):
|
||||
to_set = str(int(val))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user