Module nari.io.reader

Collection of reading-related classes and utilities

Expand source code
"""Collection of reading-related classes and utilities"""

from abc import ABCMeta, abstractmethod
from typing import Iterator, Optional

from nari.types.event import Event


class Reader(metaclass=ABCMeta):
    """Represents an abstract base for reader objects"""
    def __iter__(self) -> Iterator[Event]:
        return self

    def __next__(self) -> Event:
        event: Optional[Event] = self.read_next()
        if event:
            return event
        raise StopIteration

    @abstractmethod
    def read_next(self) -> Optional[Event]:
        """Implementing classes must implement this method to return the next parsed event"""

    def read_all(self) -> list[Event]:
        """Iterates through all events and returns them as a list"""
        return list(self)

Sub-modules

nari.io.reader.actlog

Classes and functions for handling network logs from ACT

nari.io.reader.actlogutils

Just a bunch of helper methods to spit out events from the ACT log

nari.io.reader.pickle

Reads pickle'd event files

Classes

class Reader

Represents an abstract base for reader objects

Expand source code
class Reader(metaclass=ABCMeta):
    """Represents an abstract base for reader objects"""
    def __iter__(self) -> Iterator[Event]:
        return self

    def __next__(self) -> Event:
        event: Optional[Event] = self.read_next()
        if event:
            return event
        raise StopIteration

    @abstractmethod
    def read_next(self) -> Optional[Event]:
        """Implementing classes must implement this method to return the next parsed event"""

    def read_all(self) -> list[Event]:
        """Iterates through all events and returns them as a list"""
        return list(self)

Subclasses

Methods

def read_all(self) ‑> list[Event]

Iterates through all events and returns them as a list

Expand source code
def read_all(self) -> list[Event]:
    """Iterates through all events and returns them as a list"""
    return list(self)
def read_next(self) ‑> Optional[Event]

Implementing classes must implement this method to return the next parsed event

Expand source code
@abstractmethod
def read_next(self) -> Optional[Event]:
    """Implementing classes must implement this method to return the next parsed event"""