diff --git a/platformio/home/rpc/handlers/account.py b/platformio/home/rpc/handlers/account.py index 2987329e..f7e5dade 100644 --- a/platformio/home/rpc/handlers/account.py +++ b/platformio/home/rpc/handlers/account.py @@ -15,9 +15,10 @@ from ajsonrpc.core import JSONRPC20DispatchException from platformio.account.client import AccountClient +from platformio.home.rpc.handlers.base import BaseRPCHandler -class AccountRPC: +class AccountRPC(BaseRPCHandler): @staticmethod def call_client(method, *args, **kwargs): try: diff --git a/platformio/home/rpc/handlers/app.py b/platformio/home/rpc/handlers/app.py index dbeafbdb..9c79e314 100644 --- a/platformio/home/rpc/handlers/app.py +++ b/platformio/home/rpc/handlers/app.py @@ -16,11 +16,12 @@ import os from pathlib import Path from platformio import __version__, app, fs, util +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.project.config import ProjectConfig from platformio.project.helpers import is_platformio_project -class AppRPC: +class AppRPC(BaseRPCHandler): IGNORE_STORAGE_KEYS = [ "cid", "coreVersion", diff --git a/platformio/home/rpc/handlers/base.py b/platformio/home/rpc/handlers/base.py new file mode 100644 index 00000000..7b3f5d8f --- /dev/null +++ b/platformio/home/rpc/handlers/base.py @@ -0,0 +1,17 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class BaseRPCHandler: + factory = None diff --git a/platformio/home/rpc/handlers/ide.py b/platformio/home/rpc/handlers/ide.py index c2eb5e06..643ee0c5 100644 --- a/platformio/home/rpc/handlers/ide.py +++ b/platformio/home/rpc/handlers/ide.py @@ -18,9 +18,10 @@ from pathlib import Path from ajsonrpc.core import JSONRPC20DispatchException from platformio.compat import aio_get_running_loop +from platformio.home.rpc.handlers.base import BaseRPCHandler -class IDERPC: +class IDERPC(BaseRPCHandler): COMMAND_TIMEOUT = 1.5 # in seconds def __init__(self): diff --git a/platformio/home/rpc/handlers/misc.py b/platformio/home/rpc/handlers/misc.py index c384fea9..ab2508a4 100644 --- a/platformio/home/rpc/handlers/misc.py +++ b/platformio/home/rpc/handlers/misc.py @@ -17,10 +17,11 @@ import time from platformio.cache import ContentCache from platformio.compat import aio_create_task +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.home.rpc.handlers.os import OSRPC -class MiscRPC: +class MiscRPC(BaseRPCHandler): async def load_latest_tweets(self, data_url): cache_key = ContentCache.key_from_args(data_url, "tweets") cache_valid = "180d" diff --git a/platformio/home/rpc/handlers/os.py b/platformio/home/rpc/handlers/os.py index 51b50ee3..0d6b9f48 100644 --- a/platformio/home/rpc/handlers/os.py +++ b/platformio/home/rpc/handlers/os.py @@ -24,6 +24,7 @@ from starlette.concurrency import run_in_threadpool from platformio import fs from platformio.cache import ContentCache from platformio.device.list.util import list_logical_devices +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.http import HTTPSession, ensure_internet_on @@ -35,7 +36,7 @@ class HTTPAsyncSession(HTTPSession): return await run_in_threadpool(func, *args, **kwargs) -class OSRPC: +class OSRPC(BaseRPCHandler): @staticmethod async def fetch_content(url, data=None, headers=None, cache_valid=None): if not headers: diff --git a/platformio/home/rpc/handlers/platform.py b/platformio/home/rpc/handlers/platform.py index 14383cd3..2cc959df 100644 --- a/platformio/home/rpc/handlers/platform.py +++ b/platformio/home/rpc/handlers/platform.py @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.package.manager.platform import PlatformPackageManager from platformio.platform.factory import PlatformFactory -class PlatformRPC: +class PlatformRPC(BaseRPCHandler): @staticmethod def list_installed(options=None): result = [] diff --git a/platformio/home/rpc/handlers/project.py b/platformio/home/rpc/handlers/project.py index 6c12bcae..aa5ef83d 100644 --- a/platformio/home/rpc/handlers/project.py +++ b/platformio/home/rpc/handlers/project.py @@ -20,6 +20,7 @@ from ajsonrpc.core import JSONRPC20DispatchException from platformio import exception, fs from platformio.home.rpc.handlers.app import AppRPC +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.home.rpc.handlers.piocore import PIOCoreRPC from platformio.package.manager.platform import PlatformPackageManager from platformio.project.config import ProjectConfig @@ -29,7 +30,7 @@ from platformio.project.integration.generator import ProjectGenerator from platformio.project.options import get_config_options_schema -class ProjectRPC: +class ProjectRPC(BaseRPCHandler): @staticmethod def config_call(init_kwargs, method, *args): assert isinstance(init_kwargs, dict) diff --git a/platformio/home/rpc/handlers/registry.py b/platformio/home/rpc/handlers/registry.py index 34d0974b..1370f328 100644 --- a/platformio/home/rpc/handlers/registry.py +++ b/platformio/home/rpc/handlers/registry.py @@ -15,10 +15,11 @@ from ajsonrpc.core import JSONRPC20DispatchException from starlette.concurrency import run_in_threadpool +from platformio.home.rpc.handlers.base import BaseRPCHandler from platformio.registry.client import RegistryClient -class RegistryRPC: +class RegistryRPC(BaseRPCHandler): @staticmethod async def call_client(method, *args, **kwargs): try: diff --git a/platformio/home/rpc/server.py b/platformio/home/rpc/server.py index 88f06704..94296164 100644 --- a/platformio/home/rpc/server.py +++ b/platformio/home/rpc/server.py @@ -37,6 +37,7 @@ class JSONRPCServerFactoryBase: raise NotImplementedError def add_object_handler(self, handler, namespace): + handler.factory = self self.manager.dispatcher.add_object(handler, prefix="%s." % namespace) def on_client_connect(self):