Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 4, 2024
1 parent 1ba9d2a commit 568444e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/pushsource/_impl/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
optional,
optional_str,
)
from..reader.base import ContentReader
from ..reader.base import ContentReader


LOG = logging.getLogger("pushsource")
Expand Down Expand Up @@ -260,7 +260,7 @@ def content(self):
A non-seekable read-only file-like object for reading the content
from the :meth:`src`
"""
return ContentReader.get("file:"+self.src)
return ContentReader.get("file:" + self.src)

def exist(self):
"""Return whether item exists at the :meth"`src`"""
Expand Down
12 changes: 7 additions & 5 deletions src/pushsource/_impl/reader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ContentReader(BufferedIOBase):
"""
The base class defines the interface for all the content readers that read
from various sources like a mounted fs, S3 bucket etc. The readers are
buffered and non-seekable.
buffered and non-seekable.
Instances for a specific reader could be obtained from the method
:meth:`~pushsource.ContentReader.get`
Expand Down Expand Up @@ -41,7 +41,7 @@ def __exit__(self, exc_type, exc_value, traceback):
def read(self, size=-1):
"""Read and return up to `size` bytes. If `size` is negative, read until EOF."""
raise NotImplementedError()

def read1(self, size=-1):
"""Read and return up to `size` bytes. If `size` is negative, read until EOF."""
return self.read(size)
Expand All @@ -57,7 +57,7 @@ def writable(self):
def seekable(self):
"""Return False to indicate the stream is not seekable."""
return False

def exist(self):
"""Return whether the object exist to be read"""
raise NotImplementedError()
Expand Down Expand Up @@ -122,6 +122,8 @@ def get(cls, path, *args, **kwargs):
raise ValueError("Not a valid path for content reader: %s", path)

if content_type not in cls._READERS:
raise ValueError(f"Requested {content_type} reader but there's no such registerd reader")

raise ValueError(
f"Requested {content_type} reader but there's no such registerd reader"
)

return cls._READERS[content_type](parsed.path, *args, **kwargs)
5 changes: 3 additions & 2 deletions src/pushsource/_impl/reader/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .base import ContentReader


class FileContentReader(ContentReader):
"""
A file content reader that provides read-only, non-seekable access to a file at the given src.
Expand All @@ -13,7 +14,7 @@ def __init__(self, filepath):
Parameters:
filepath (str): Path to the file to be read.
"""
"""
self._filepath = filepath
self._file_obj = None

Expand All @@ -35,7 +36,7 @@ def read(self, size=-1):
if self._file_obj is None:
self._file_obj = open(self._filepath, "rb")
return self._file_obj.read(size)

def exist(self):
"""Returns True if the file exists at the given file path"""
return os.path.exists(self._filepath)
Expand Down

0 comments on commit 568444e

Please sign in to comment.