From f5ceb8927f2e7f2a9e29d62c8e4cef876f917249 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sat, 6 Feb 2021 00:32:26 +0800 Subject: =?UTF-8?q?=F0=9F=8F=97=20=F0=9F=92=A9=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=95=A5b=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/service/switch.py | 79 -------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 ATRI/service/switch.py (limited to 'ATRI/service/switch.py') diff --git a/ATRI/service/switch.py b/ATRI/service/switch.py deleted file mode 100644 index b97a0ec..0000000 --- a/ATRI/service/switch.py +++ /dev/null @@ -1,79 +0,0 @@ -import json -import aiofiles -from typing import Optional - -from ATRI.exceptions import InvalidWriteText - -from . import SERVICE_PATH - - -class Switch: - filename = 'switch.service.json' - path = SERVICE_PATH / filename - path.parent.mkdir(exist_ok=True, parents=True) - try: - data = json.loads(path.read_bytes()) - except: - data = {} - - @classmethod - def get_service(cls) -> dict: - return cls.data - - @classmethod - async def auth_service( - cls, service: str, group: Optional[int] = None) -> bool: - cls.data.setdefault('global', {}) - cls.data.setdefault(group, {}) - if service not in cls.data['global']: - cls.data['global'][service] = True - if service not in cls.data[group]: - cls.data[group][service] = True - try: - async with aiofiles.open( - cls.path, 'w', encoding='utf-8') as target: - await target.write( - json.dumps( - cls.data, indent=4 - ) - ) - except InvalidWriteText: - raise InvalidWriteText('Writing file failed!') - else: - pass - - if cls.data['global'][service]: - return True if cls.data[group][service] else False - else: - return False - - @classmethod - async def control_service(cls, service: str, _type: bool, - group: Optional[str]) -> None: - if service not in cls.data: - cls.data['global'][service] = True - cls.data[group][service] = True - try: - async with aiofiles.open( - cls.path, 'w', encoding='utf-8') as target: - await target.write( - json.dumps( - cls.data, indent=4 - ) - ) - except InvalidWriteText: - raise InvalidWriteText('Writing file failed!') - if group: - cls.data[group][service] = _type - else: - cls.data['global'][service] = _type - try: - async with aiofiles.open( - cls.path, 'w', encoding='utf-8') as target: - await target.write( - json.dumps( - cls.data, indent=4 - ) - ) - except InvalidWriteText: - raise InvalidWriteText('Writing file failed!') -- cgit v1.2.3