<commit_before>from __future__ import absolute_import

import ast
import json
import os
import logging
import time
import abc

import zmp
# python protocol should be usable without ROS.
from ..pyros_prtcl import MsgBuild, Topic, Service, Param, ServiceList, ServiceInfo, TopicList, TopicInfo, ParamList, ParamInfo, Interaction, Interactions, InteractionInfo, Namespaces, NamespaceInfo, Rocon
from .baseinterface import BaseInterface


# TODO : service interface for mock to be able to dynamically trigger services / topics / params appearing & disappearing
class PyrosBase(zmp.Node):
    """
    Mock Interface in pure python ( No ROS needed ).
    """
    __metaclass__ = abc.ABCMeta

    def __init__(self, name=None):
        super(PyrosBase, self).__init__(name or 'pyros')

        self.last_update = 0
        self.update_interval = 1  # seconds to wait between each update

        self.provides(self.msg_build)
        self.provides(self.topic)
        self.provides(self.topics)
        self.provides(self.service)
        self.provides(self.services)
        self.provides(self.param)
        self.provides(self.params)
        self.provides(self.reinit)
        pass

    # These should match the design of PyrosClient and Protocol so we are consistent between pipe and python API
    @abc.abstractmethod
    def msg_build(self, name):
        return

    @abc.abstractmethod
    def topic(self, name, msg_content=None):
        return

    @abc.abstractmethod
    def topics(self):
        return

    # a simple string echo service
    @abc.abstractmethod
    def service(self, name, rqst_content=None):
        return

    @abc.abstractmethod
    def services(self):
        return

    @abc.abstractmethod
    def param(self, name, value=None):
        return

    @abc.abstractmethod
    def params(self):
        return

    @abc.abstractmethod
    def reinit(self):
        return

    def run(self):
        """
        Running in a zmp.Node process, providing zmp.services
        """

        logging.debug("pyros node running, zmp[{name}] pid[{pid}]".format(name=self.name, pid=os.getpid()))

        super(PyrosBase, self).run()

        logging.debug("pyros node shutdown, zmp[{name}] pid[{pid}]".format(name=self.name, pid=os.getpid()))

    def update(self, timedelta):<commit_msg>adding custom manager argument in basenode, and making shutdown possible override more obvious.<commit_after>from __future__ import absolute_import

import ast
import json
import os
import logging
import time
import abc

import zmp
# python protocol should be usable without ROS.
from ..pyros_prtcl import MsgBuild, Topic, Service, Param, ServiceList, ServiceInfo, TopicList, TopicInfo, ParamList, ParamInfo, Interaction, Interactions, InteractionInfo, Namespaces, NamespaceInfo, Rocon
from .baseinterface import BaseInterface


# TODO : service interface for mock to be able to dynamically trigger services / topics / params appearing & disappearing
class PyrosBase(zmp.Node):
    """
    Mock Interface in pure python ( No ROS needed ).
    """
    __metaclass__ = abc.ABCMeta

    def __init__(self, name=None, context_manager=None):
        """
        :param name: name of the node
        :param context_manager: a context manager to enter when starting, and exit when the node stops
        :return:
        """
        super(PyrosBase, self).__init__(name or 'pyros', context_manager=context_manager)

        self.last_update = 0
        self.update_interval = 1  # seconds to wait between each update

        self.provides(self.msg_build)
        self.provides(self.topic)
        self.provides(self.topics)
        self.provides(self.service)
        self.provides(self.services)
        self.provides(self.param)
        self.provides(self.params)
        self.provides(self.reinit)
        pass

    # These should match the design of PyrosClient and Protocol so we are consistent between pipe and python API
    @abc.abstractmethod
    def msg_build(self, name):
        return

    @abc.abstractmethod
    def topic(self, name, msg_content=None):
        return

    @abc.abstractmethod
    def topics(self):
        return

    # a simple string echo service
    @abc.abstractmethod
    def service(self, name, rqst_content=None):
        return

    @abc.abstractmethod
    def services(self):
        return

    @abc.abstractmethod
    def param(self, name, value=None):
        return

    @abc.abstractmethod
    def params(self):
        return

    @abc.abstractmethod
    def reinit(self):
        return

    def run(self):
        """
        Running in a zmp.Node process, providing zmp.services
        """

        logging.debug("pyros node running, zmp[{name}] pid[{pid}]".format(name=self.name, pid=os.getpid()))

        super(PyrosBase, self).run()

        logging.debug("pyros node shutdown, zmp[{name}] pid[{pid}]".format(name=self.name, pid=os.getpid()))

    def shutdown(self, join=True):
        """
        Clean shutdown of the node.
        :param join: optionally wait for the process to end (default : True)
        :return: None
        """

        super(PyrosBase, self).shutdown(join)

    def update(self, timedelta):
{'fraction_non_alphanumeric': 0.09159420289855072, 'fraction_numerical': 0.0007729468599033816, 'mean_word_length': 2.897590361445783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3205771', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1450, 'n_words': 438}