-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
======== | ||
Tutorial | ||
======== | ||
|
||
.. currentmodule:: senf | ||
|
||
There are various ways to create fsnative instances: | ||
|
||
:: | ||
|
||
# create from unicode text | ||
>>> senf.fsnative(u"foo") | ||
'foo' | ||
|
||
# create form some serialzed format | ||
>>> senf.bytes2fsn(b"foo", "utf-8") | ||
'foo' | ||
|
||
# create from an URI | ||
>>> senf.uri2fsn("file:///foo") | ||
'/foo' | ||
|
||
# create from some Python path like | ||
>>> senf.path2fsn(b"foo") | ||
'foo' | ||
|
||
Now that we have a `fsnative`, what can we do with it? | ||
|
||
:: | ||
|
||
>>> path = senf.fsnative(u"/foo") | ||
|
||
# We can print it | ||
>>> senf.print_(path) | ||
|
||
# We can convert it to text for our favorite GUI toolkit | ||
>>> senf.fsn2text(path) | ||
'/foo' | ||
|
||
# We can convert it to an URI | ||
>>> senf.fsn2uri(path) | ||
'file:///foo' | ||
|
||
# We can convert it to an ASCII only URI | ||
>>> senf.fsn2uri_ascii(path) | ||
'file:///foo' | ||
|
||
# We can serialize the path so we can save it somewhere | ||
>>> senf.fsn2bytes("/foo", "utf-8") | ||
b'/foo' | ||
|
||
The functions in the stdlib usually return the same type which was passed in. | ||
If we pass in a `fsnative`, we get one back as well. | ||
|
||
:: | ||
|
||
>>> files = os.listdir(senf.fsnative(u".")) | ||
>>> isinstance(files[0], senf.fsnative) | ||
True | ||
|
||
In some cases the stdlib functions don't take arguments and always return the | ||
same type. For those cases we provide alternative implementations. | ||
|
||
:: | ||
|
||
>>> isinstance(senf.getcwd(), senf.fsnative) | ||
True | ||
|
||
A similar problem arises with stdlib collections. We provides alternatives for | ||
`sys.argv` and `os.environ`. | ||
|
||
:: | ||
|
||
>>> isinstance(senf.argv[0], senf.fsnative) | ||
True | ||
>>> isinstance(senf.environ["PATH"], senf.fsnative) | ||
True | ||
|
||
|
||
If you work with files a lot your unit tests will probably need temporary | ||
files. We provide wrappers for `tempfile` functions which always return a | ||
`fsnative`. | ||
|
||
:: | ||
|
||
>>> senf.mkdtemp() | ||
'/tmp/tmp26Daqo' | ||
>>> isinstance(_, senf.fsnative) | ||
True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,6 @@ | |
|
||
defpath = defpath | ||
"""`fsnative`: Like `os.defpath` but a `fsnative`""" | ||
|
||
|
||
__all__ = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters