Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.4.12] - (Unreleased)

### Added

- Added options for readbytes and readtext

### Changed

- Start testing on PyPy. Due to [#342](https://github.com/PyFilesystem/pyfilesystem2/issues/342)
Expand Down
20 changes: 13 additions & 7 deletions fs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def openbin(
path, # type: Text
mode="r", # type: Text
buffering=-1, # type: int
**options # type: Any
**options, # type: Any
):
# type: (...) -> BinaryIO
"""Open a binary file-like object.
Expand Down Expand Up @@ -586,8 +586,8 @@ def exclude_file(patterns, info):
iter_info = itertools.islice(iter_info, start, end)
return iter_info

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
"""Get the contents of a file as bytes.

Arguments:
Expand Down Expand Up @@ -644,6 +644,7 @@ def readtext(
encoding=None, # type: Optional[Text]
errors=None, # type: Optional[Text]
newline="", # type: Text
**options, # type: Any
):
# type: (...) -> Text
"""Get the contents of a file as a string.
Expand All @@ -664,7 +665,12 @@ def readtext(
"""
with closing(
self.open(
path, mode="rt", encoding=encoding, errors=errors, newline=newline
path,
mode="rt",
encoding=encoding,
errors=errors,
newline=newline,
**options,
)
) as read_file:
contents = read_file.read()
Expand Down Expand Up @@ -1130,7 +1136,7 @@ def open(
encoding=None, # type: Optional[Text]
errors=None, # type: Optional[Text]
newline="", # type: Text
**options # type: Any
**options, # type: Any
):
# type: (...) -> IO
"""Open a file.
Expand Down Expand Up @@ -1163,7 +1169,7 @@ def open(
"""
validate_open_mode(mode)
bin_mode = mode.replace("t", "")
bin_file = self.openbin(path, mode=bin_mode, buffering=buffering)
bin_file = self.openbin(path, mode=bin_mode, buffering=buffering, **options)
io_stream = iotools.make_stream(
path,
bin_file,
Expand All @@ -1172,7 +1178,7 @@ def open(
encoding=encoding or "utf-8",
errors=errors,
newline=newline,
**options
line_buffering=options.get("line_buffering", False),
)
return io_stream

Expand Down
4 changes: 2 additions & 2 deletions fs/ftpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ def setinfo(self, path, info):
if not self.exists(path):
raise errors.ResourceNotFound(path)

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
_path = self.validatepath(path)
data = io.BytesIO()
with ftp_errors(self, path):
Expand Down
9 changes: 5 additions & 4 deletions fs/mountfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def removedir(self, path):
fs, _path = self._delegate(path)
return fs.removedir(_path)

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
self.check()
fs, _path = self._delegate(path)
return fs.readbytes(_path)
Expand All @@ -203,6 +203,7 @@ def readtext(
encoding=None, # type: Optional[Text]
errors=None, # type: Optional[Text]
newline="", # type: Text
**options, # type: Any
):
# type: (...) -> Text
self.check()
Expand Down Expand Up @@ -284,7 +285,7 @@ def open(
encoding=None, # type: Optional[Text]
errors=None, # type: Optional[Text]
newline="", # type: Text
**options # type: Any
**options, # type: Any
):
# type: (...) -> IO
validate_open_mode(mode)
Expand All @@ -297,7 +298,7 @@ def open(
encoding=encoding,
errors=errors,
newline=newline,
**options
**options,
)

def upload(self, path, file, chunk_size=None, **options):
Expand Down
8 changes: 4 additions & 4 deletions fs/multifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def scandir(
if not exists:
raise errors.ResourceNotFound(path)

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
self.check()
fs = self._delegate(path)
if fs is None:
Expand All @@ -293,8 +293,8 @@ def download(self, path, file, chunk_size=None, **options):
fs = self._delegate_required(path)
return fs.download(path, file, chunk_size=chunk_size, **options)

def readtext(self, path, encoding=None, errors=None, newline=""):
# type: (Text, Optional[Text], Optional[Text], Text) -> Text
def readtext(self, path, encoding=None, errors=None, newline="", **options):
# type: (Text, Optional[Text], Optional[Text], Text, Any) -> Text
self.check()
fs = self._delegate_required(path)
return fs.readtext(path, encoding=encoding, errors=errors, newline=newline)
Expand Down
9 changes: 5 additions & 4 deletions fs/wrapfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ def filterdir(
for info in iter_files:
yield info

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
self.check()
_fs, _path = self.delegate_path(path)
with unwrap_errors(path):
Expand All @@ -348,6 +348,7 @@ def readtext(
encoding=None, # type: Optional[Text]
errors=None, # type: Optional[Text]
newline="", # type: Text
**options, # type: Any
):
# type: (...) -> Text
self.check()
Expand Down Expand Up @@ -456,7 +457,7 @@ def open(
errors=None, # type: Optional[Text]
newline="", # type: Text
line_buffering=False, # type: bool
**options # type: Any
**options, # type: Any
):
# type: (...) -> IO[AnyStr]
self.check()
Expand All @@ -470,7 +471,7 @@ def open(
errors=errors,
newline=newline,
line_buffering=line_buffering,
**options
**options,
)
return open_file

Expand Down
4 changes: 2 additions & 2 deletions fs/zipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ def close(self):
if hasattr(self, "_zip"):
self._zip.close()

def readbytes(self, path):
# type: (Text) -> bytes
def readbytes(self, path, **options):
# type: (Text, Any) -> bytes
self.check()
if not self._directory.isfile(path):
raise errors.ResourceNotFound(path)
Expand Down