コード例 #1
0
ファイル: sequence_queue.py プロジェクト: BloggerBust/bbpyp
 def push(self, sequential_transfer_object):
     if not isinstance(sequential_transfer_object,
                       SequentialTransferObject):
         raise BbpypValueError(
             "sequential_transfer_object", sequential_transfer_object,
             f"Expected an instance of SequentialTransferObject, but received an instance of {type(sequential_transfer_object)}"
         )
     heapq.heappush(self._queue, sequential_transfer_object)
コード例 #2
0
ファイル: collection_util.py プロジェクト: BloggerBust/bbpyp
 def reversed_index(collection, item, from_position=None):
     from_position = from_position if from_position is not None else len(
         collection) - 1
     for index in reversed(range(0, from_position + 1)):
         if collection[index] == item:
             return index
     raise BbpypValueError(
         "item", item,
         "is not in collection" if from_position == len(collection) -
         1 else f"is not in collection before position {from_position}")
コード例 #3
0
ファイル: topic_channel.py プロジェクト: BloggerBust/bbpyp
    def __init__(self, topic, logger, channel_topic_config,
                 channel_topic_config_default, channel_max_buffer_size,
                 async_service, context_service):

        if not isinstance(channel_topic_config,
                          dict) and channel_topic_config is not None:
            raise BbpypValueError(
                "channel_topic_config", channel_topic_config,
                "channel_topic_config must be of type dict or None")

        if not isinstance(channel_topic_config_default, dict):
            raise BbpypValueError(
                "channel_topic_config_default", channel_topic_config_default,
                "channel_topic_config_default must be of type dict")

        self._started = False
        self._topic = topic
        self._logger = logger
        self._channel_topic_config = deepcopy(
            channel_topic_config) if channel_topic_config else {}
        self._channel_topic_config_default = deepcopy(
            channel_topic_config_default)
        self._async_service = async_service
        self._context_service = context_service
        self._publisher_connection_source = None
        self._subscriber_connection_source = None
        self._publisher_connection_clones = []
        self._subscriber_connection_clones = []
        self._publishers = []
        self._subscribers = []

        _channel_topic_config = self._get_channel_topic_config(topic)

        self._number_of_publisher_clones = _channel_topic_config[
            "publish_concurrency"] + 1
        self._number_of_subscriber_clones = _channel_topic_config[
            "subscribe_concurrency"] + 1
        self._channel_max_buffer_size = channel_max_buffer_size

        self._publisher_connect_event = self._async_service.create_event()
        self._subscriber_connect_event = self._async_service.create_event()
        self._publisher_disconnect_event = self._async_service.create_event()
        self._subscriber_disconnect_event = self._async_service.create_event()
コード例 #4
0
ファイル: queue_factory.py プロジェクト: BloggerBust/bbpyp
    def __call__(self, queue_type):
        queue = None
        if queue_type == QueueType.FIFO:
            queue = self._fifo_queue_factory()
        elif queue_type == QueueType.SEQUENCE:
            queue = self._sequence_queue_factory()
        else:
            raise BbpypValueError("queue_type", queue_type,
                                  "unsupported queue type")

        return queue
コード例 #5
0
ファイル: single_link_node.py プロジェクト: BloggerBust/bbpyp
    def __init__(self,
                 value=None,
                 next_link=None,
                 link_node_iter_factory=None,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        if next_link is not None and not isinstance(next_link, SingleLinkNode):
            raise BbpypValueError(
                "next_link", next_link,
                f"Must be either None or of type {SingleLinkNode}")

        self._link_node_iter_factory = link_node_iter_factory
        self._value = value
        self._next_link = next_link
コード例 #6
0
    def __deepcopy__(self, memo):
        new_inst = type(self).__new__(self.__class__)
        types_to_assign = self.__types_to_assign()

        def copy_list(source, memo):

            new_list = list()
            for item in source:
                if isinstance(item, (list, tuple)):
                    new_list.append(copy_list(item, memo))
                elif isinstance(item, types_to_assign):
                    new_list.append(item)
                else:
                    new_list.append(deepcopy(item, memo))
            return new_list

        for prop in self.__dict__:
            if isinstance(self.__dict__[prop], types_to_assign):
                new_inst.__dict__[prop] = self.__dict__[prop]
            elif isinstance(self.__dict__[prop], (list, tuple)):
                new_inst.__dict__[prop] = copy_list(self.__dict__[prop], memo)
            else:
                try:
                    new_inst.__dict__[prop] = deepcopy(self.__dict__[prop],
                                                       memo)
                except:
                    is_deeply_copyable = isinstance(self.__dict__[prop],
                                                    DeeplyCopyable)
                    if is_deeply_copyable:
                        error_message = "Failed to deeply copy property. A type referenced by type(self.__dict__[prop]) is not deepcopyable. Identify this type and add it to DeeplyCopyable._DEEPLY_COPYABLE_ASSIGN_TYPES"
                    else:
                        error_message = "Failed to deeply copy property. Consider adding type(self.__dict__[prop]) to DeeplyCopyable._DEEPLY_COPYABLE_ASSIGN_TYPES"

                    raise BbpypValueError(prop, self.__dict__[prop],
                                          error_message)

        return new_inst
コード例 #7
0
    async def run_in_context(self, func, *args, **kwargs):
        if not callable(func):
            raise BbpypValueError("func", func, f"must be callable")

        copied_context = copy_context()
        await copied_context.run(func, *args, **kwargs)