From 1f66f2c761043953048d77e22c6862f4b27430cf Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 00:58:09 +0800 Subject: [PATCH 01/11] add `options` to `readbytes` --- fs/base.py | 4 ++-- fs/ftpfs.py | 4 ++-- fs/mountfs.py | 4 ++-- fs/multifs.py | 4 ++-- fs/wrapfs.py | 4 ++-- fs/zipfs.py | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/base.py b/fs/base.py index a4b7aefb..7fbae25e 100644 --- a/fs/base.py +++ b/fs/base.py @@ -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: diff --git a/fs/ftpfs.py b/fs/ftpfs.py index 11d2c4cc..87fda025 100644 --- a/fs/ftpfs.py +++ b/fs/ftpfs.py @@ -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): diff --git a/fs/mountfs.py b/fs/mountfs.py index d51d7d9d..8b5f2e53 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -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) diff --git a/fs/multifs.py b/fs/multifs.py index e68d2c00..d452d2c7 100644 --- a/fs/multifs.py +++ b/fs/multifs.py @@ -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: diff --git a/fs/wrapfs.py b/fs/wrapfs.py index c09e9cf3..6f60a9a7 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -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): diff --git a/fs/zipfs.py b/fs/zipfs.py index 8feb9e56..2e8444dc 100644 --- a/fs/zipfs.py +++ b/fs/zipfs.py @@ -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) From 415865f57653ac685732c02a114d0d1801f982ae Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 01:04:22 +0800 Subject: [PATCH 02/11] add `options` to `readtext` --- fs/base.py | 12 +++++++++--- fs/mountfs.py | 5 +++-- fs/multifs.py | 4 ++-- fs/wrapfs.py | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/base.py b/fs/base.py index 7fbae25e..c5a90a97 100644 --- a/fs/base.py +++ b/fs/base.py @@ -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. @@ -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. @@ -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() @@ -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. diff --git a/fs/mountfs.py b/fs/mountfs.py index 8b5f2e53..40e7258b 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -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() @@ -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) @@ -297,7 +298,7 @@ def open( encoding=encoding, errors=errors, newline=newline, - **options + **options, ) def upload(self, path, file, chunk_size=None, **options): diff --git a/fs/multifs.py b/fs/multifs.py index d452d2c7..a65f9b88 100644 --- a/fs/multifs.py +++ b/fs/multifs.py @@ -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) diff --git a/fs/wrapfs.py b/fs/wrapfs.py index 6f60a9a7..11540654 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -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() @@ -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() @@ -470,7 +471,7 @@ def open( errors=errors, newline=newline, line_buffering=line_buffering, - **options + **options, ) return open_file From 4df25ded6016e56cf5e2cafc58825ba5da943a6d Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 01:05:11 +0800 Subject: [PATCH 03/11] move options from `make_stream` to `openbin` it seems no extra parameters are required for `iotools.make_stream`, and the description for `options` is 'arguments for the filesystem'. so I guess it was misplaced. --- fs/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/base.py b/fs/base.py index c5a90a97..033e345c 100644 --- a/fs/base.py +++ b/fs/base.py @@ -1169,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, @@ -1178,7 +1178,6 @@ def open( encoding=encoding or "utf-8", errors=errors, newline=newline, - **options ) return io_stream From 7c041d06c248404057fe58cd5cdc937c5f0345ed Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 01:11:39 +0800 Subject: [PATCH 04/11] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7126b0a9..00ea5f2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 937a2b6e689f340217f69f508d98323b8f25d740 Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 01:20:13 +0800 Subject: [PATCH 05/11] add back line buffering --- fs/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/base.py b/fs/base.py index 033e345c..b857b6c6 100644 --- a/fs/base.py +++ b/fs/base.py @@ -1178,6 +1178,7 @@ def open( encoding=encoding or "utf-8", errors=errors, newline=newline, + line_buffering=options.get("line_buffering", False), ) return io_stream From 607bd2b3311b7bace3ef8f101018bb6d79f5d5db Mon Sep 17 00:00:00 2001 From: tzing Date: Sat, 7 Dec 2019 11:13:46 +0800 Subject: [PATCH 06/11] fix syntaxerror the syntax error is cause by the trailing comma in func def, which is added by black. pyproject.toml is added for black to announce the target python version related: https://github.com/psf/black/issues/419 --- fs/base.py | 6 +++--- fs/mountfs.py | 4 ++-- fs/wrapfs.py | 4 ++-- pyproject.toml | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 pyproject.toml diff --git a/fs/base.py b/fs/base.py index b857b6c6..66fe0c6d 100644 --- a/fs/base.py +++ b/fs/base.py @@ -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. @@ -644,7 +644,7 @@ def readtext( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text - **options, # type: Any + **options # type: Any ): # type: (...) -> Text """Get the contents of a file as a string. @@ -1136,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. diff --git a/fs/mountfs.py b/fs/mountfs.py index 40e7258b..69b9efef 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -203,7 +203,7 @@ def readtext( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text - **options, # type: Any + **options # type: Any ): # type: (...) -> Text self.check() @@ -285,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) diff --git a/fs/wrapfs.py b/fs/wrapfs.py index 11540654..5b1fdb0c 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -348,7 +348,7 @@ def readtext( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text - **options, # type: Any + **options # type: Any ): # type: (...) -> Text self.check() @@ -457,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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..2c32aebf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +py36 = false From bda6a2220940dcad7adf9a5f1cefea646efd5b26 Mon Sep 17 00:00:00 2001 From: tzing Date: Sun, 8 Dec 2019 15:39:00 +0800 Subject: [PATCH 07/11] add docstring --- fs/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/base.py b/fs/base.py index 66fe0c6d..208bf1cc 100644 --- a/fs/base.py +++ b/fs/base.py @@ -592,6 +592,8 @@ def readbytes(self, path, **options): Arguments: path (str): A path to a readable file on the filesystem. + **options: keyword arguments for any additional information + required by the filesystem (if any). Returns: bytes: the file contents. @@ -655,6 +657,8 @@ def readtext( in text mode (defaults to `None`, reading in binary mode). errors (str, optional): Unicode errors parameter. newline (str): Newlines parameter. + **options: keyword arguments for any additional information + required by the filesystem (if any). Returns: str: file contents. From 2f1de1b09701825dc1398a21bd9071466b5c2f74 Mon Sep 17 00:00:00 2001 From: tzing Date: Sun, 8 Dec 2019 16:05:48 +0800 Subject: [PATCH 08/11] pass options kwargs to sub filesystem --- fs/base.py | 2 +- fs/mountfs.py | 6 ++++-- fs/multifs.py | 6 ++++-- fs/wrapfs.py | 4 ++-- fs/zipfs.py | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/base.py b/fs/base.py index 208bf1cc..eed425b4 100644 --- a/fs/base.py +++ b/fs/base.py @@ -602,7 +602,7 @@ def readbytes(self, path, **options): fs.errors.ResourceNotFound: if ``path`` does not exist. """ - with closing(self.open(path, mode="rb")) as read_file: + with closing(self.open(path, mode="rb", **options)) as read_file: contents = read_file.read() return contents diff --git a/fs/mountfs.py b/fs/mountfs.py index 69b9efef..98d65cc2 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -190,7 +190,7 @@ def readbytes(self, path, **options): # type: (Text, Any) -> bytes self.check() fs, _path = self._delegate(path) - return fs.readbytes(_path) + return fs.readbytes(_path, **options) def download(self, path, file, chunk_size=None, **options): # type: (Text, BinaryIO, Optional[int], **Any) -> None @@ -208,7 +208,9 @@ def readtext( # type: (...) -> Text self.check() fs, _path = self._delegate(path) - return fs.readtext(_path, encoding=encoding, errors=errors, newline=newline) + return fs.readtext( + _path, encoding=encoding, errors=errors, newline=newline, **options + ) def getsize(self, path): # type: (Text) -> int diff --git a/fs/multifs.py b/fs/multifs.py index a65f9b88..0d1eca96 100644 --- a/fs/multifs.py +++ b/fs/multifs.py @@ -286,7 +286,7 @@ def readbytes(self, path, **options): fs = self._delegate(path) if fs is None: raise errors.ResourceNotFound(path) - return fs.readbytes(path) + return fs.readbytes(path, **options) def download(self, path, file, chunk_size=None, **options): # type: (Text, BinaryIO, Optional[int], **Any) -> None @@ -297,7 +297,9 @@ 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) + return fs.readtext( + path, encoding=encoding, errors=errors, newline=newline, **options + ) def getsize(self, path): # type: (Text) -> int diff --git a/fs/wrapfs.py b/fs/wrapfs.py index 5b1fdb0c..566f58ef 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -339,7 +339,7 @@ def readbytes(self, path, **options): self.check() _fs, _path = self.delegate_path(path) with unwrap_errors(path): - _bytes = _fs.readbytes(_path) + _bytes = _fs.readbytes(_path, **options) return _bytes def readtext( @@ -355,7 +355,7 @@ def readtext( _fs, _path = self.delegate_path(path) with unwrap_errors(path): _text = _fs.readtext( - _path, encoding=encoding, errors=errors, newline=newline + _path, encoding=encoding, errors=errors, newline=newline, **options ) return _text diff --git a/fs/zipfs.py b/fs/zipfs.py index 2e8444dc..fbfd3245 100644 --- a/fs/zipfs.py +++ b/fs/zipfs.py @@ -445,7 +445,7 @@ def readbytes(self, path, **options): if not self._directory.isfile(path): raise errors.ResourceNotFound(path) zip_name = self._path_to_zip_name(path) - zip_bytes = self._zip.read(zip_name) + zip_bytes = self._zip.read(zip_name, **options) return zip_bytes def geturl(self, path, purpose="download"): From a493207f0b6d5dd7f9a354db9aba8146d725e567 Mon Sep 17 00:00:00 2001 From: tzing Date: Sun, 8 Dec 2019 16:06:38 +0800 Subject: [PATCH 09/11] add options kwargs to `writebytes`, `writetext` and `writefile` --- fs/base.py | 28 +++++++++++++++++++++++----- fs/ftpfs.py | 6 +++--- fs/mountfs.py | 14 ++++++++++---- fs/multifs.py | 9 +++++---- fs/wrap.py | 6 ++++-- fs/wrapfs.py | 14 ++++++++++---- 6 files changed, 55 insertions(+), 22 deletions(-) diff --git a/fs/base.py b/fs/base.py index eed425b4..94a77a49 100644 --- a/fs/base.py +++ b/fs/base.py @@ -1281,14 +1281,16 @@ def scandir( iter_info = itertools.islice(iter_info, start, end) return iter_info - def writebytes(self, path, contents): - # type: (Text, bytes) -> None + def writebytes(self, path, contents, **options): + # type: (Text, bytes, Any) -> None # FIXME(@althonos): accept bytearray and memoryview as well ? """Copy binary data to a file. Arguments: path (str): Destination path on the filesystem. contents (bytes): Data to be written. + **options: keyword arguments for any additional information + required by the filesystem (if any). Raises: TypeError: if contents is not bytes. @@ -1296,7 +1298,7 @@ def writebytes(self, path, contents): """ if not isinstance(contents, bytes): raise TypeError("contents must be bytes") - with closing(self.open(path, mode="wb")) as write_file: + with closing(self.open(path, mode="wb", **options)) as write_file: write_file.write(contents) setbytes = _new_name(writebytes, "setbytes") @@ -1341,6 +1343,7 @@ def writefile( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None """Set a file to the contents of a file object. @@ -1353,6 +1356,8 @@ def writefile( errors (str, optional): How encoding errors should be treated (same as `io.open`). newline (str): Newline parameter (same as `io.open`). + **options: Implementation specific options required to open + the source file. This method is similar to `~FS.upload`, in that it copies data from a file-like object to a resource on the filesystem, but unlike ``upload``, @@ -1372,7 +1377,12 @@ def writefile( with self._lock: with self.open( - path, mode=mode, encoding=encoding, errors=errors, newline=newline + path, + mode=mode, + encoding=encoding, + errors=errors, + newline=newline, + **options, ) as dst_file: tools.copy_file_data(file, dst_file) @@ -1411,6 +1421,7 @@ def writetext( encoding="utf-8", # type: Text errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None """Create or replace a file with text. @@ -1423,6 +1434,8 @@ def writetext( errors (str, optional): How encoding errors should be treated (same as `io.open`). newline (str): Newline parameter (same as `io.open`). + **options: keyword arguments for any additional information + required by the filesystem (if any). Raises: TypeError: if ``contents`` is not a unicode string. @@ -1432,7 +1445,12 @@ def writetext( raise TypeError("contents must be unicode") with closing( self.open( - path, mode="wt", encoding=encoding, errors=errors, newline=newline + path, + mode="wt", + encoding=encoding, + errors=errors, + newline=newline, + **options, ) ) as write_file: write_file.write(contents) diff --git a/fs/ftpfs.py b/fs/ftpfs.py index 87fda025..5329c13c 100644 --- a/fs/ftpfs.py +++ b/fs/ftpfs.py @@ -761,11 +761,11 @@ def upload(self, path, file, chunk_size=None, **options): str("STOR ") + _encode(_path, self.ftp.encoding), file ) - def writebytes(self, path, contents): - # type: (Text, ByteString) -> None + def writebytes(self, path, contents, **options): + # type: (Text, ByteString, Any) -> None if not isinstance(contents, bytes): raise TypeError("contents must be bytes") - self.upload(path, io.BytesIO(contents)) + self.upload(path, io.BytesIO(contents), **options) def setinfo(self, path, info): # type: (Text, RawInfo) -> None diff --git a/fs/mountfs.py b/fs/mountfs.py index 98d65cc2..0baba149 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -309,11 +309,11 @@ def upload(self, path, file, chunk_size=None, **options): fs, _path = self._delegate(path) return fs.upload(_path, file, chunk_size=chunk_size, **options) - def writebytes(self, path, contents): - # type: (Text, bytes) -> None + def writebytes(self, path, contents, **options): + # type: (Text, bytes, Any) -> None self.check() fs, _path = self._delegate(path) - return fs.writebytes(_path, contents) + return fs.writebytes(_path, contents, **options) def writetext( self, @@ -322,9 +322,15 @@ def writetext( encoding="utf-8", # type: Text errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None fs, _path = self._delegate(path) return fs.writetext( - _path, contents, encoding=encoding, errors=errors, newline=newline + _path, + contents, + encoding=encoding, + errors=errors, + newline=newline, + **options, ) diff --git a/fs/multifs.py b/fs/multifs.py index 0d1eca96..f38cfd95 100644 --- a/fs/multifs.py +++ b/fs/multifs.py @@ -408,9 +408,9 @@ def upload(self, path, file, chunk_size=None, **options): path, file, chunk_size=chunk_size, **options ) - def writebytes(self, path, contents): - # type: (Text, bytes) -> None - self._writable_required(path).writebytes(path, contents) + def writebytes(self, path, contents, **options): + # type: (Text, bytes, Any) -> None + self._writable_required(path).writebytes(path, contents, **options) def writetext( self, @@ -419,9 +419,10 @@ def writetext( encoding="utf-8", # type: Text errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None write_fs = self._writable_required(path) return write_fs.writetext( - path, contents, encoding=encoding, errors=errors, newline=newline + path, contents, encoding=encoding, errors=errors, newline=newline, **options ) diff --git a/fs/wrap.py b/fs/wrap.py index 7026bcbc..2e4b59ca 100644 --- a/fs/wrap.py +++ b/fs/wrap.py @@ -215,6 +215,7 @@ def writetext( encoding="utf-8", # type: Text errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None self.check() @@ -271,8 +272,8 @@ def open( **options ) - def writebytes(self, path, contents): - # type: (Text, bytes) -> None + def writebytes(self, path, contents, **options): + # type: (Text, bytes, Any) -> None self.check() raise ResourceReadOnly(path) @@ -288,6 +289,7 @@ def writefile( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None self.check() diff --git a/fs/wrapfs.py b/fs/wrapfs.py index 566f58ef..5c6e7b74 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -489,12 +489,12 @@ def opendir( with unwrap_errors(path): return factory(self, path) - def writebytes(self, path, contents): - # type: (Text, bytes) -> None + def writebytes(self, path, contents, **options): + # type: (Text, bytes, Any) -> None self.check() _fs, _path = self.delegate_path(path) with unwrap_errors(path): - _fs.writebytes(_path, contents) + _fs.writebytes(_path, contents, **options) def upload(self, path, file, chunk_size=None, **options): # type: (Text, BinaryIO, Optional[int], **Any) -> None @@ -510,13 +510,19 @@ def writefile( encoding=None, # type: Optional[Text] errors=None, # type: Optional[Text] newline="", # type: Text + **options # type: Any ): # type: (...) -> None self.check() _fs, _path = self.delegate_path(path) with unwrap_errors(path): _fs.writefile( - _path, file, encoding=encoding, errors=errors, newline=newline + _path, + file, + encoding=encoding, + errors=errors, + newline=newline, + **options, ) def validatepath(self, path): From a45f9058e1132a9a8d3c5b3a9a207bbd597a74f6 Mon Sep 17 00:00:00 2001 From: tzing Date: Sun, 8 Dec 2019 16:12:36 +0800 Subject: [PATCH 10/11] update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ea5f2a..a2a3075a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,13 +9,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added -- Added options for readbytes and readtext +- Added `options` kwargs to several I/O operations, including: `readbytes`, + `writebytes`, `readtext`, `writetext` and `writefile`. ### Changed - Start testing on PyPy. Due to [#342](https://github.com/PyFilesystem/pyfilesystem2/issues/342) we have to treat PyPy builds specially and allow them to fail, but at least we'll be able to see if we break something aside from known issues with FTP tests. +- Set `py36 = false` for black to prevent adding trailing comma in function + definition and cause `SyntaxError` in older python version. ## [2.4.11] - 2019-09-07 From f022c32187ed9f7c07961ef66e83b00137456631 Mon Sep 17 00:00:00 2001 From: tzing Date: Sun, 8 Dec 2019 16:20:15 +0800 Subject: [PATCH 11/11] forget to remove existing trailing comma in def --- fs/base.py | 6 +++--- fs/mountfs.py | 4 ++-- fs/wrapfs.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/base.py b/fs/base.py index 94a77a49..f73e73db 100644 --- a/fs/base.py +++ b/fs/base.py @@ -674,7 +674,7 @@ def readtext( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) ) as read_file: contents = read_file.read() @@ -1382,7 +1382,7 @@ def writefile( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) as dst_file: tools.copy_file_data(file, dst_file) @@ -1450,7 +1450,7 @@ def writetext( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) ) as write_file: write_file.write(contents) diff --git a/fs/mountfs.py b/fs/mountfs.py index 0baba149..2e45a858 100644 --- a/fs/mountfs.py +++ b/fs/mountfs.py @@ -300,7 +300,7 @@ def open( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) def upload(self, path, file, chunk_size=None, **options): @@ -332,5 +332,5 @@ def writetext( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) diff --git a/fs/wrapfs.py b/fs/wrapfs.py index 5c6e7b74..0abb2a5e 100644 --- a/fs/wrapfs.py +++ b/fs/wrapfs.py @@ -471,7 +471,7 @@ def open( errors=errors, newline=newline, line_buffering=line_buffering, - **options, + **options ) return open_file @@ -522,7 +522,7 @@ def writefile( encoding=encoding, errors=errors, newline=newline, - **options, + **options ) def validatepath(self, path):