mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 09:40:30 +08:00
refactoring
This commit is contained in:
parent
13a51f2f46
commit
234aa8bda4
@ -53,11 +53,11 @@ class AtxIsBusyError(AtxOperationError, aioregion.RegionIsBusyError):
|
|||||||
|
|
||||||
|
|
||||||
def _atx_working(method: Callable) -> Callable:
|
def _atx_working(method: Callable) -> Callable:
|
||||||
async def wrap(self: "Atx", *args: Any, **kwargs: Any) -> Any:
|
async def wrapper(self: "Atx", *args: Any, **kwargs: Any) -> Any:
|
||||||
if not self._enabled: # pylint: disable=protected-access
|
if not self._enabled: # pylint: disable=protected-access
|
||||||
raise AtxDisabledError()
|
raise AtxDisabledError()
|
||||||
return (await method(self, *args, **kwargs))
|
return (await method(self, *args, **kwargs))
|
||||||
return wrap
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class Atx: # pylint: disable=too-many-instance-attributes
|
class Atx: # pylint: disable=too-many-instance-attributes
|
||||||
|
|||||||
@ -190,13 +190,13 @@ def _explore_device(device_path: str) -> Optional[_MassStorageDeviceInfo]:
|
|||||||
|
|
||||||
|
|
||||||
def _msd_working(method: Callable) -> Callable:
|
def _msd_working(method: Callable) -> Callable:
|
||||||
async def wrap(self: "MassStorageDevice", *args: Any, **kwargs: Any) -> Any:
|
async def wrapper(self: "MassStorageDevice", *args: Any, **kwargs: Any) -> Any:
|
||||||
if not self._enabled: # pylint: disable=protected-access
|
if not self._enabled: # pylint: disable=protected-access
|
||||||
raise MsdDisabledError()
|
raise MsdDisabledError()
|
||||||
if not self._device_path: # pylint: disable=protected-access
|
if not self._device_path: # pylint: disable=protected-access
|
||||||
raise MsdOfflineError()
|
raise MsdOfflineError()
|
||||||
return (await method(self, *args, **kwargs))
|
return (await method(self, *args, **kwargs))
|
||||||
return wrap
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@ -156,14 +156,14 @@ _COOKIE_AUTH_TOKEN = "auth_token"
|
|||||||
|
|
||||||
|
|
||||||
def _atomic(handler: Callable) -> Callable:
|
def _atomic(handler: Callable) -> Callable:
|
||||||
async def wrap(self: "Server", request: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def wrapper(self: "Server", request: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
return (await asyncio.shield(handler(self, request)))
|
return (await asyncio.shield(handler(self, request)))
|
||||||
return wrap
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _exposed(http_method: str, path: str, atomic: bool=False, auth_required: bool=True) -> Callable:
|
def _exposed(http_method: str, path: str, atomic: bool=False, auth_required: bool=True) -> Callable:
|
||||||
def make_wrapper(handler: Callable) -> Callable:
|
def make_wrapper(handler: Callable) -> Callable:
|
||||||
async def wrap(self: "Server", request: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def wrapper(self: "Server", request: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
try:
|
try:
|
||||||
if auth_required:
|
if auth_required:
|
||||||
user = request.headers.get(_HEADER_AUTH_USER, "")
|
user = request.headers.get(_HEADER_AUTH_USER, "")
|
||||||
@ -198,17 +198,17 @@ def _exposed(http_method: str, path: str, atomic: bool=False, auth_required: boo
|
|||||||
return _json_exception(err, 403)
|
return _json_exception(err, 403)
|
||||||
|
|
||||||
if atomic:
|
if atomic:
|
||||||
wrap = _atomic(wrap)
|
wrapper = _atomic(wrapper)
|
||||||
|
|
||||||
setattr(wrap, _ATTR_EXPOSED, True)
|
setattr(wrapper, _ATTR_EXPOSED, True)
|
||||||
setattr(wrap, _ATTR_EXPOSED_METHOD, http_method)
|
setattr(wrapper, _ATTR_EXPOSED_METHOD, http_method)
|
||||||
setattr(wrap, _ATTR_EXPOSED_PATH, path)
|
setattr(wrapper, _ATTR_EXPOSED_PATH, path)
|
||||||
return wrap
|
return wrapper
|
||||||
return make_wrapper
|
return make_wrapper
|
||||||
|
|
||||||
|
|
||||||
def _system_task(method: Callable) -> Callable:
|
def _system_task(method: Callable) -> Callable:
|
||||||
async def wrap(self: "Server") -> None:
|
async def wrapper(self: "Server") -> None:
|
||||||
try:
|
try:
|
||||||
await method(self)
|
await method(self)
|
||||||
raise RuntimeError("Dead system task: %s" % (method))
|
raise RuntimeError("Dead system task: %s" % (method))
|
||||||
@ -218,8 +218,8 @@ def _system_task(method: Callable) -> Callable:
|
|||||||
get_logger().exception("Unhandled exception, killing myself ...")
|
get_logger().exception("Unhandled exception, killing myself ...")
|
||||||
os.kill(os.getpid(), signal.SIGTERM)
|
os.kill(os.getpid(), signal.SIGTERM)
|
||||||
|
|
||||||
setattr(wrap, _ATTR_SYSTEM_TASK, True)
|
setattr(wrapper, _ATTR_SYSTEM_TASK, True)
|
||||||
return wrap
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class _Events(Enum):
|
class _Events(Enum):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user