Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jan 6, 2019
1 parent 9e52a87 commit 7af2e83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
55 changes: 24 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pathvalidate
==============
**pathvalidate**

.. contents:: Table of Contents
:depth: 2

.. image:: https://badge.fury.io/py/pathvalidate.svg
:target: https://badge.fury.io/py/pathvalidate

Expand All @@ -22,17 +25,14 @@ pathvalidate

Summary
---------
A Python library to sanitize/validate a string such as filenames/file-paths/variable-names/etc.
A Python library to sanitize/validate a string such as filenames/file-paths/etc.

Features
---------
- Sanitize/Validate a string as a:
- file name
- file path
- variable name: ``Python``/``JavaScript``
- `Labeled Tab-separated Values (LTSV) <http://ltsv.org/>`__ label
- Elastic search index name
- Excel sheet name
- Multibyte character support

Examples
==========
Expand All @@ -41,10 +41,10 @@ Validate a filename
:Sample Code:
.. code-block:: python
import pathvalidate
from pathvalidate import validate_filename
try:
pathvalidate.validate_filename("\0_a*b:c<d>e%f/(g)h+i_0.txt")
validate_filename("\0_a*b:c<d>e%f/(g)h+i_0.txt")
except ValueError:
print("invalid filename!")
Expand All @@ -58,45 +58,38 @@ Sanitize a filename
:Sample Code:
.. code-block:: python
import pathvalidate as pv
from pathvalidate import sanitize_filename
fname = "fi:l*e/p\"a?t>h|.t<xt"
print("{} -> {}".format(fname, sanitize_filename(fname)))
print(pv.sanitize_filename("f\\i:l*e?n\"a<m>e|.txt"))
print(pv.sanitize_filename("_a*b:c<d>e%f/(g)h+i_0.txt"))
fname = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
print("{} -> {}".format(fname, sanitize_filename(fname)))
:Output:
.. code-block::
_abcde%f(g)h+i_0.txt
fi:l*e/p"a?t>h|.t<xt -> filepath.txt
_a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f(g)h+i_0.txt
Sanitize a filepath
---------------------
:Sample Code:
.. code-block:: python
import pathvalidate as pv
print(pv.sanitize_filepath("fi:l*e/p\"a?t>h|.t<xt"))
print(pv.sanitize_filepath("_a*b:c<d>e%f/(g)h+i_0.txt"))
:Output:
.. code-block::
file/path.txt
_abcde%f/(g)h+i_0.txt
Sanitize a variable name
--------------------------
:Sample Code:
.. code-block:: python
from pathvalidate import sanitize_filepath
import pathvalidate as pv
fpath = "fi:l*e/p\"a?t>h|.t<xt"
print("{} -> {}".format(fpath, sanitize_filepath(fpath)))
print(pv.sanitize_python_var_name("_a*b:c<d>e%f/(g)h+i_0.txt"))
fpath = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
print("{} -> {}".format(fpath, sanitize_filepath(fpath)))
:Output:
.. code-block::
abcdefghi_0txt
fi:l*e/p"a?t>h|.t<xt -> file/path.txt
_a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f/(g)h+i_0.txt
For more information
----------------------
Expand Down
5 changes: 1 addition & 4 deletions docs/make_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def write_examples(maker):
maker.write_chapter("Sanitize a filepath")
maker.write_file(example_root.joinpath("sanitize_filepath_code.txt"))

maker.write_chapter("Sanitize a variable name")
maker.write_file(example_root.joinpath("sanitize_var_name_code.txt"))

maker.write_chapter("For more information")
maker.write_line_list(
[
Expand All @@ -45,7 +42,7 @@ def write_examples(maker):


def main():
maker = readmemaker.ReadmeMaker("pathvalidate", OUTPUT_DIR)
maker = readmemaker.ReadmeMaker("pathvalidate", OUTPUT_DIR, is_make_toc=True)

maker.write_introduction_file("badges.txt")

Expand Down

0 comments on commit 7af2e83

Please sign in to comment.