From 7af2e83bf1aa138303a84339b0080598ba66b56a Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Sun, 6 Jan 2019 11:00:18 +0900 Subject: [PATCH] Update README --- README.rst | 55 ++++++++++++++++++++------------------------- docs/make_readme.py | 5 +---- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/README.rst b/README.rst index 7504eb3..d7a8637 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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) `__ label - - Elastic search index name - - Excel sheet name +- Multibyte character support Examples ========== @@ -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:ce%f/(g)h+i_0.txt") + validate_filename("\0_a*b:ce%f/(g)h+i_0.txt") except ValueError: print("invalid filename!") @@ -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 {}".format(fname, sanitize_filename(fname))) - print(pv.sanitize_filename("f\\i:l*e?n\"ae|.txt")) - print(pv.sanitize_filename("_a*b:ce%f/(g)h+i_0.txt")) + fname = "\0_a*b:ce%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 filepath.txt + _a*b:ce%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|.te%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 {}".format(fpath, sanitize_filepath(fpath))) - print(pv.sanitize_python_var_name("_a*b:ce%f/(g)h+i_0.txt")) + fpath = "\0_a*b:ce%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 file/path.txt + _a*b:ce%f/(g)h+i_0.txt -> _abcde%f/(g)h+i_0.txt For more information ---------------------- diff --git a/docs/make_readme.py b/docs/make_readme.py index b3d6e9b..d63f6ee 100644 --- a/docs/make_readme.py +++ b/docs/make_readme.py @@ -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( [ @@ -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")