Skip to content

Commit 2827cb0

Browse files
authored
Merge pull request #467 from PyFilesystem/update-docs
Update docs and add doctest loading mechanism
2 parents e6f0c8f + 41bbe3c commit 2827cb0

22 files changed

+603
-152
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
[#449](https://github.com/PyFilesystem/pyfilesystem2/pull/449).
1616
- `PathError` now supports wrapping an exception using the `exc` argument.
1717
Closes [#453](https://github.com/PyFilesystem/pyfilesystem2/issues/453).
18+
- Better documentation of the `writable` parameter of `fs.open_fs`, and
19+
hint about using `fs.wrap.read_only` when a read-only filesystem is
20+
required. Closes [#441](https://github.com/PyFilesystem/pyfilesystem2/issues/441).
1821

1922
### Changed
2023

@@ -28,7 +31,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2831
- `FSTestCases` now builds the large data required for `upload` and `download` tests only
2932
once in order to reduce the total testing time.
3033
- `MemoryFS.move` and `MemoryFS.movedir` will now avoid copying data.
31-
Closes [#452](https://github.com/PyFilesystem/pyfilesystem2/issues/452).
34+
Closes [#452](https://github.com/PyFilesystem/pyfilesystem2/issues/452).
35+
- `FS.removetree("/")` behaviour has been standardized in all filesystems, and
36+
is expected to clear the contents of the root folder without deleting it.
37+
Closes [#471](https://github.com/PyFilesystem/pyfilesystem2/issues/471).
38+
- `FS.getbasic` is now deprecated, as it is redundant with `FS.getinfo`,
39+
and `FS.getinfo` is now explicitly expected to return the *basic* info
40+
namespace unconditionally. Closes [#469](https://github.com/PyFilesystem/pyfilesystem2/issues/469).
3241

3342
### Fixed
3443

@@ -40,8 +49,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4049
- `WrapCachedDir.isdir` and `WrapCachedDir.isfile` raising a `ResourceNotFound` error on non-existing path ([#470](https://github.com/PyFilesystem/pyfilesystem2/pull/470)).
4150
- `FTPFS` not listing certain entries with sticky/SUID/SGID permissions set by Linux server ([#473](https://github.com/PyFilesystem/pyfilesystem2/pull/473)).
4251
Closes [#451](https://github.com/PyFilesystem/pyfilesystem2/issues/451).
43-
- `scandir` iterator not being closed explicitly in `OSFS.scandir`, occasionally causing a `ResourceWarning`
52+
- `scandir` iterator not being closed explicitly in `OSFS.scandir`, occasionally causing a `ResourceWarning`
4453
to be thrown. Closes [#311](https://github.com/PyFilesystem/pyfilesystem2/issues/311).
54+
- Incomplete type annotations for the `temp_fs` parameter of `WriteTarFS` and `WriteZipFS`.
55+
Closes [#410](https://github.com/PyFilesystem/pyfilesystem2/issues/410).
4556

4657

4758
## [2.4.12] - 2021-01-14

fs/_ftp_parse.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656

5757

5858
def get_decoders():
59-
"""
60-
Returns all available FTP LIST line decoders with their matching regexes.
61-
"""
59+
"""Return all available FTP LIST line decoders with their matching regexes."""
6260
decoders = [
6361
(RE_LINUX, decode_linux),
6462
(RE_WINDOWSNT, decode_windowsnt),
@@ -149,13 +147,34 @@ def _decode_windowsnt_time(mtime):
149147

150148

151149
def decode_windowsnt(line, match):
152-
"""
153-
Decodes a Windows NT FTP LIST line like one of these:
150+
"""Decode a Windows NT FTP LIST line.
151+
152+
Examples:
153+
Decode a directory line::
154+
155+
>>> line = "11-02-18 02:12PM <DIR> images"
156+
>>> match = RE_WINDOWSNT.match(line)
157+
>>> pprint(decode_windowsnt(line, match))
158+
{'basic': {'is_dir': True, 'name': 'images'},
159+
'details': {'modified': 1518358320.0, 'type': 1},
160+
'ftp': {'ls': '11-02-18 02:12PM <DIR> images'}}
161+
162+
Decode a file line::
163+
164+
>>> line = "11-02-18 03:33PM 9276 logo.gif"
165+
>>> match = RE_WINDOWSNT.match(line)
166+
>>> pprint(decode_windowsnt(line, match))
167+
{'basic': {'is_dir': False, 'name': 'logo.gif'},
168+
'details': {'modified': 1518363180.0, 'size': 9276, 'type': 2},
169+
'ftp': {'ls': '11-02-18 03:33PM 9276 logo.gif'}}
170+
171+
Alternatively, the time might also be present in 24-hour format::
154172
155-
`11-02-18 02:12PM <DIR> images`
156-
`11-02-18 03:33PM 9276 logo.gif`
173+
>>> line = "11-02-18 15:33 9276 logo.gif"
174+
>>> match = RE_WINDOWSNT.match(line)
175+
>>> decode_windowsnt(line, match)["details"]["modified"]
176+
1518363180.0
157177
158-
Alternatively, the time (02:12PM) might also be present in 24-hour format (14:12).
159178
"""
160179
is_dir = match.group("size") == "<DIR>"
161180

fs/_repr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def make_repr(class_name, *args, **kwargs):
2727
>>> MyClass('Will')
2828
MyClass('foo', name='Will')
2929
>>> MyClass(None)
30-
MyClass()
30+
MyClass('foo')
3131
3232
"""
3333
arguments = [repr(arg) for arg in args]

fs/_url_tools.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
def url_quote(path_snippet):
1313
# type: (Text) -> Text
14-
"""
15-
On Windows, it will separate drive letter and quote windows
16-
path alone. No magic on Unix-alie path, just pythonic
17-
`pathname2url`
14+
"""Quote a URL without quoting the Windows drive letter, if any.
15+
16+
On Windows, it will separate drive letter and quote Windows
17+
path alone. No magic on Unix-like path, just pythonic
18+
`~urllib.request.pathname2url`.
1819
1920
Arguments:
20-
path_snippet: a file path, relative or absolute.
21+
path_snippet (str): a file path, relative or absolute.
22+
2123
"""
2224
if _WINDOWS_PLATFORM and _has_drive_letter(path_snippet):
2325
drive_letter, path = path_snippet.split(":", 1)
@@ -34,17 +36,19 @@ def url_quote(path_snippet):
3436

3537
def _has_drive_letter(path_snippet):
3638
# type: (Text) -> bool
37-
"""
38-
The following path will get True
39-
D:/Data
40-
C:\\My Dcouments\\ test
39+
"""Check whether a path contains a drive letter.
4140
42-
And will get False
41+
Arguments:
42+
path_snippet (str): a file path, relative or absolute.
4343
44-
/tmp/abc:test
44+
Example:
45+
>>> _has_drive_letter("D:/Data")
46+
True
47+
>>> _has_drive_letter(r"C:\\System32\\ test")
48+
True
49+
>>> _has_drive_letter("/tmp/abc:test")
50+
False
4551
46-
Arguments:
47-
path_snippet: a file path, relative or absolute.
4852
"""
4953
windows_drive_pattern = ".:[/\\\\].*$"
5054
return re.match(windows_drive_pattern, path_snippet) is not None

0 commit comments

Comments
 (0)