mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-20 02:47:39 +03:00
Added more utility methods
This commit is contained in:
parent
8c0457bf47
commit
36d786ef8c
@ -3,8 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Dict, List, Mapping, MutableMapping, MutableSequence, NamedTuple, Optional, Sequence, Tuple, TypedDict,
|
TYPE_CHECKING, Any, Dict, List, Mapping, MutableMapping, MutableSequence, NamedTuple, Optional, Sequence, Tuple,
|
||||||
TypeVar, Union, cast
|
TypedDict, Union, cast
|
||||||
)
|
)
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -172,6 +172,16 @@ class DisabledResult(NamedTuple):
|
|||||||
"""Reason provided for why this killswitch exists."""
|
"""Reason provided for why this killswitch exists."""
|
||||||
return self.kill.reason if self.kill is not None else ""
|
return self.kill.reason if self.kill is not None else ""
|
||||||
|
|
||||||
|
def has_kill(self) -> bool:
|
||||||
|
"""Return whether or not this DisabledResult has a Kill associated with it."""
|
||||||
|
return self.kill is not None
|
||||||
|
|
||||||
|
def has_rules(self) -> bool:
|
||||||
|
"""Return whether or not the kill on this Result contains rules."""
|
||||||
|
# HACK: 2021-07-09 # Python/mypy/pyright does not support type guards like this yet. self.kill will always
|
||||||
|
# be non-None at the point it is evaluated
|
||||||
|
return self.has_kill() and self.kill.has_rules # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class KillSwitchSet:
|
class KillSwitchSet:
|
||||||
"""Queryable set of kill switches."""
|
"""Queryable set of kill switches."""
|
||||||
@ -226,10 +236,13 @@ class KillSwitchSet:
|
|||||||
return False, data
|
return False, data
|
||||||
|
|
||||||
log.info(f'Killswitch {name} is enabled. Checking if rules exist to make use safe')
|
log.info(f'Killswitch {name} is enabled. Checking if rules exist to make use safe')
|
||||||
if res.kill is None or not res.kill.has_rules:
|
if not res.has_rules():
|
||||||
logger.info('No rules exist. Stopping processing')
|
logger.info('No rules exist. Stopping processing')
|
||||||
return True, data
|
return True, data
|
||||||
|
|
||||||
|
if TYPE_CHECKING: # pyright, mypy, please -_-
|
||||||
|
assert res.kill is not None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_data = res.kill.apply_rules(deepcopy(data))
|
new_data = res.kill.apply_rules(deepcopy(data))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user