diff options
Diffstat (limited to 'de_uvok/activitypub_fuse')
| -rw-r--r-- | de_uvok/activitypub_fuse/fuse.py | 16 | ||||
| -rw-r--r-- | de_uvok/activitypub_fuse/providers.py | 52 | ||||
| -rw-r--r-- | de_uvok/activitypub_fuse/types.py | 12 | 
3 files changed, 80 insertions, 0 deletions
diff --git a/de_uvok/activitypub_fuse/fuse.py b/de_uvok/activitypub_fuse/fuse.py index 5a6052f..46eeb02 100644 --- a/de_uvok/activitypub_fuse/fuse.py +++ b/de_uvok/activitypub_fuse/fuse.py @@ -13,7 +13,14 @@ from .types import Status  class StatusFileSystem(Operations, LoggingMixIn): +    """ +    Implements a FUSE file system for mapping (ActivityPub, Mastodon, ...) statuses to text files. +    """ +      def __init__(self): +        """ +        Initialize a new instance of StatusFileSystem, to be used with FUSE. +        """          self.__queue: SimpleQueue[list[Status]] = SimpleQueue()          self.__statuses: list[Status] = []          self.__fd = 0 @@ -44,6 +51,9 @@ class StatusFileSystem(Operations, LoggingMixIn):          raise FuseOSError(errno.ENOENT)      def __update_status_field(self): +        """ +        Update the internal statuses list with new statuses from the queue. +        """          try:              while True:                  statuses = self.__queue.get_nowait() @@ -64,6 +74,12 @@ class StatusFileSystem(Operations, LoggingMixIn):          return dir_entries      def add_statuses(self, statuses: list[Status]): +        """ +        Add new statuses to the queue. + +        Args: +            statuses (list): A list of Status objects to be added. +        """          self.__queue.put(statuses)      def open(self, path, flags):  # type: ignore diff --git a/de_uvok/activitypub_fuse/providers.py b/de_uvok/activitypub_fuse/providers.py index 19cee62..74b08b4 100644 --- a/de_uvok/activitypub_fuse/providers.py +++ b/de_uvok/activitypub_fuse/providers.py @@ -14,18 +14,59 @@ _api_url_m_status_template = "https://{server}/api/v1/accounts/{uid}/statuses"  class StatusProvider: +    """ +    Base class for status providers. +    """ +      def load_statuses(self, max_id="") -> tuple[list[Status], Optional[str]]: +        """ +        Load statuses up to a given maximum ID. + +        Args: +            max_id (str): The maximum ID for loading statuses. +                Can be empty or None to load the first page. + +        Returns: +            tuple: A tuple containing a list of Status objects and, +                optionally, a max ID for the next call. +        """          raise NotImplementedError      def _fallback_not_found(self): +        """ +        Handle user not found error by returning a Status representing that error. + +        Returns: +            list: A list containing a single 'not-found' status. +        """          return [Status("not-found", "User not found", "1970-01-01T00:00:00Z")]      def _fallback_error(self, error_msg: str): +        """ +        Handle an error by returning a Status representing that error. + +        Args: +            error_msg (str): The error message to be included in the fallback status. + +        Returns: +            list: A list containing a single 'error' status. +        """          return [Status("error", error_msg, "1970-01-01T00:00:00Z")]  class ActivityPubStatusProvider(StatusProvider): +    """ +    Status provider for ActivityPub protocol. +    """ +      def __init__(self, server: str, user: str): +        """ +        Initialize the ActivityPub status provider. + +        Args: +            server (str): The server FQDN. +            user (str): The user name (just the name, not the full ID). +        """          self.server = server          self.user = user @@ -69,7 +110,18 @@ class ActivityPubStatusProvider(StatusProvider):  class MastodonStatusProvider(StatusProvider): +    """ +    Status provider for Mastodon API. +    """ +      def __init__(self, server: str, user: str): +        """ +        Initialize the Mastodon status provider. + +        Args: +            server (str): The server FQDN. +            user (str): The user name (just the name, not the full ID). +        """          self.server = server          self.user = user          self.userid = 0 diff --git a/de_uvok/activitypub_fuse/types.py b/de_uvok/activitypub_fuse/types.py index d354335..9b92728 100644 --- a/de_uvok/activitypub_fuse/types.py +++ b/de_uvok/activitypub_fuse/types.py @@ -1,5 +1,17 @@  class Status(object): +    """ +    Represents a status with an ID, content, and published date. +    """ +      def __init__(self, id: str, content: str, published: str): +        """ +        Initialize a new Status instance. + +        Args: +            id (str): The unique identifier of the status. +            content (str): The content of the status. +            published (str): The published date of the status in ISO format. +        """          self.id = id          self.content = content          self.published = published  | 
