mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +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 pathlib
|
||||||
import sys
|
import sys
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from typing import Any, List, Optional, Union
|
|
||||||
|
|
||||||
from config import AbstractConfig, appname, logger
|
from config import AbstractConfig, appname, logger
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ class LinuxConfig(AbstractConfig):
|
|||||||
__unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'}
|
__unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'}
|
||||||
__escape_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__()
|
super().__init__()
|
||||||
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
|
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
|
||||||
xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser()
|
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.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
|
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
|
# 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.
|
:param s: str - The string to unescape.
|
||||||
:return: str - The unescaped string.
|
:return: str - The unescaped string.
|
||||||
"""
|
"""
|
||||||
out: List[str] = []
|
out: list[str] = []
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(s):
|
while i < len(s):
|
||||||
c = s[i]
|
c = s[i]
|
||||||
@ -107,7 +106,7 @@ class LinuxConfig(AbstractConfig):
|
|||||||
|
|
||||||
return "".join(out)
|
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.
|
Get a raw data value from the config file.
|
||||||
|
|
||||||
@ -183,7 +182,7 @@ class LinuxConfig(AbstractConfig):
|
|||||||
|
|
||||||
return bool(int(data))
|
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.
|
Set the given key's data to the given value.
|
||||||
|
|
||||||
@ -192,7 +191,7 @@ class LinuxConfig(AbstractConfig):
|
|||||||
if self.config is None:
|
if self.config is None:
|
||||||
raise ValueError('attempt to use a closed config')
|
raise ValueError('attempt to use a closed config')
|
||||||
|
|
||||||
to_set: Optional[str] = None
|
to_set: str | None = None
|
||||||
if isinstance(val, bool):
|
if isinstance(val, bool):
|
||||||
to_set = str(int(val))
|
to_set = str(int(val))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user