MCPcopy
hub / github.com/caronc/apprise / open

Method open

apprise/persistent_store.py:748–812  ·  view source on GitHub ↗

Returns an iterator to our our file within our namespace identified by the key provided. If no key is provided, then the default is used

(
        self,
        key: Optional[str] = None,
        mode: str = "r",
        buffering: int = -1,
        encoding: Optional[str] = None,
        errors: Optional[str] = None,
        newline: Optional[str] = None,
        closefd: bool = True,
        opener: Optional[Any] = None,
        compress: bool = False,
        compresslevel: int = 9,
    )

Source from the content-addressed store, hash-verified

746 return True
747
748 def open(
749 self,
750 key: Optional[str] = None,
751 mode: str = "r",
752 buffering: int = -1,
753 encoding: Optional[str] = None,
754 errors: Optional[str] = None,
755 newline: Optional[str] = None,
756 closefd: bool = True,
757 opener: Optional[Any] = None,
758 compress: bool = False,
759 compresslevel: int = 9,
760 ) -> Any:
761 """Returns an iterator to our our file within our namespace identified
762 by the key provided.
763
764 If no key is provided, then the default is used
765 """
766
767 if key is None:
768 key = self.base_key
769
770 elif not isinstance(key, str) or not self.__valid_key.match(key):
771 raise AttributeError(
772 f"Persistent Storage key ({key} provided is invalid"
773 )
774
775 if self.__mode == PersistentStoreMode.MEMORY:
776 # Nothing further can be done
777 raise FileNotFoundError()
778
779 io_file = os.path.join(self.__data_path, f"{key}{self.__extension}")
780 try:
781 return (
782 open(
783 io_file,
784 mode=mode,
785 buffering=buffering,
786 encoding=encoding,
787 errors=errors,
788 newline=newline,
789 closefd=closefd,
790 opener=opener,
791 )
792 if not compress
793 else gzip.open(
794 io_file,
795 compresslevel=compresslevel,
796 encoding=encoding,
797 errors=errors,
798 newline=newline,
799 )
800 )
801
802 except FileNotFoundError:
803 # pass along (but wrap with Apprise exception)
804 raise exception.AppriseFileNotFound(
805 f"No such file or directory: '{io_file}'"

Callers 4

readMethod · 0.95
__load_cacheMethod · 0.45
flushMethod · 0.45

Calls 1

joinMethod · 0.45

Tested by 1