How to use the tinyrpc.public function in tinyrpc

To help you get started, we’ve selected a few tinyrpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rokups / Launchpad / src / client / modules / fs.py View on Github external
    @tinyrpc.public
    def get_file_content(self, file_path):
        return open(file_path, 'rb').read()
github rokups / Launchpad / src / client / modules / fs.py View on Github external
    @tinyrpc.public
    def enumerate_directory(self, dir_path):
        # Default path is always /, handle it for different systems
        if os.name == 'nt' and dir_path == '/':
            dir_path = 'C:/'

        result = {}
        for filename in itertools.chain(['..'], os.listdir(dir_path)):
            full_path = os.path.join(dir_path, filename)
            file_info = {
                'stat': None,
                'is_dir': os.path.isdir(full_path),
                'is_link': os.path.islink(full_path),
                'is_mount': os.path.ismount(full_path),
                'is_file': os.path.isfile(full_path),
            }
            with suppress(OSError, KeyError):
github rokups / Launchpad / src / client / modules / fs.py View on Github external
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
import os
from contextlib import suppress

import itertools
import tinyrpc


@tinyrpc.public
class FilesystemClientModule(object):
    @classmethod
    def setup(cls):
        pass

    @tinyrpc.public
    def enumerate_directory(self, dir_path):
        # Default path is always /, handle it for different systems
        if os.name == 'nt' and dir_path == '/':
            dir_path = 'C:/'

        result = {}
        for filename in itertools.chain(['..'], os.listdir(dir_path)):
            full_path = os.path.join(dir_path, filename)
            file_info = {
                'stat': None,
github rokups / Launchpad / src / dashboard / server_session.py View on Github external
    @tinyrpc.public
    def import_module(self, module_name):
        try:
            spec = importlib.util.find_spec(module_name)
            if not spec:
                return None
            with open(spec.origin, 'rb') as fp:
                return marshal.dumps(compile(fp.read(), '', 'exec'))
        except FileNotFoundError:
            return None
github rokups / Launchpad / src / client / client_session.py View on Github external
#
import sys
import time
import asyncio
from contextlib import suppress

import tinyrpc

from client.importer import RemoteImporter
from client.modules.fs import FilesystemClientModule
from client.modules.shell import ShellClientModule
from common.session import LaunchpadSession
from common import transport


@tinyrpc.public
class LaunchpadClientSession(LaunchpadSession):
    def __init__(self):
        super().__init__()
        self._remote_importer = RemoteImporter(self)
        # Register self as rpc server
        self._dispatcher.register_object('client', self)
        # Retrieve client to rpc server on the other end
        self.server = self._dispatcher.get_object('server')
        # Initialize plugins
        self.fs = FilesystemClientModule()
        self.shell = ShellClientModule()

    def on_connect(self, connection):
        super().on_connect(connection)
        sys.meta_path.insert(0, self._remote_importer)