Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Feb 12, 2019
1 parent 9748b12 commit c81844a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
32 changes: 26 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,41 @@ Validate a filename
:Sample Code:
.. code-block:: python
from pathvalidate import validate_filename
import sys
from pathvalidate import ValidationError, validate_filename
try:
validate_filename("\0_a*b:c<d>e%f/(g)h+i_0.txt")
except ValueError:
print("invalid filename!")
validate_filename("fi:l*e/p\"a?t>h|.t<xt")
except ValidationError as e:
print(e, file=sys.stderr)
:Output:
.. code-block::
invalid filename!
invalid char found: invalid-char=':, \*, /, ", \?, >, \|, <', value='fi:l*e/p"a?t>h|.t<xt', reason=ErrorReason.INVALID_CHARACTER
Check a filename
------------------
:Sample Code:
.. code-block:: python
from pathvalidate import is_valid_filename, sanitize_filename
fname = "fi:l*e/p\"a?t>h|.t<xt"
print("is_valid_filename('{}') return {}".format(fname, is_valid_filename(fname)))
sanitized_fname = sanitize_filename(fname)
print("is_valid_filename('{}') return {}".format(sanitized_fname, is_valid_filename(sanitized_fname)))
:Output:
.. code-block::
is_valid_filename('fi:l*e/p"a?t>h|.t<xt') return False
is_valid_filename('filepath.txt') return True
For more information
----------------------
More More examples can be found at
More examples can be found at
https://pathvalidate.rtfd.io/en/latest/pages/examples/index.html

Installation
Expand Down
5 changes: 4 additions & 1 deletion docs/make_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ def write_examples(maker):
maker.write_chapter("Validate a filename")
maker.write_file(example_root.joinpath("validate_filename_code.txt"))

maker.write_chapter("Check a filename")
maker.write_file(example_root.joinpath("is_valid_filename_code.txt"))

maker.write_chapter("For more information")
maker.write_lines(
[
"More More examples can be found at ",
"More examples can be found at ",
"https://{}.rtfd.io/en/latest/pages/examples/index.html".format(PROJECT_NAME),
]
)
Expand Down

0 comments on commit c81844a

Please sign in to comment.