METADATA 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. Metadata-Version: 2.4
  2. Name: pathvalidate
  3. Version: 3.3.1
  4. Summary: pathvalidate is a Python library to sanitize/validate a string such as filenames/file-paths/etc.
  5. Home-page: https://github.com/thombashi/pathvalidate
  6. Author: Tsuyoshi Hombashi
  7. Author-email: tsuyoshi.hombashi@gmail.com
  8. License: MIT License
  9. Project-URL: Changelog, https://github.com/thombashi/pathvalidate/blob/master/CHANGELOG.md
  10. Project-URL: Documentation, https://pathvalidate.rtfd.io/
  11. Project-URL: Source, https://github.com/thombashi/pathvalidate
  12. Project-URL: Tracker, https://github.com/thombashi/pathvalidate/issues
  13. Keywords: file,path,validation,validator,sanitization,sanitizer
  14. Classifier: Development Status :: 5 - Production/Stable
  15. Classifier: Intended Audience :: Developers
  16. Classifier: Intended Audience :: Information Technology
  17. Classifier: License :: OSI Approved :: MIT License
  18. Classifier: Operating System :: OS Independent
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Programming Language :: Python :: 3.9
  21. Classifier: Programming Language :: Python :: 3.10
  22. Classifier: Programming Language :: Python :: 3.11
  23. Classifier: Programming Language :: Python :: 3.12
  24. Classifier: Programming Language :: Python :: 3.13
  25. Classifier: Programming Language :: Python :: 3 :: Only
  26. Classifier: Programming Language :: Python :: Implementation :: CPython
  27. Classifier: Programming Language :: Python :: Implementation :: PyPy
  28. Classifier: Topic :: Software Development :: Libraries
  29. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  30. Classifier: Topic :: System :: Filesystems
  31. Classifier: Topic :: Text Processing
  32. Classifier: Typing :: Typed
  33. Requires-Python: >=3.9
  34. Description-Content-Type: text/x-rst
  35. License-File: LICENSE
  36. Provides-Extra: docs
  37. Requires-Dist: sphinx_rtd_theme>=1.2.2; extra == "docs"
  38. Requires-Dist: Sphinx>=2.4; extra == "docs"
  39. Requires-Dist: urllib3<2; extra == "docs"
  40. Provides-Extra: readme
  41. Requires-Dist: readmemaker>=1.2.0; extra == "readme"
  42. Requires-Dist: path<18,>=13; extra == "readme"
  43. Provides-Extra: test
  44. Requires-Dist: allpairspy>=2; extra == "test"
  45. Requires-Dist: click>=6.2; extra == "test"
  46. Requires-Dist: Faker>=1.0.8; extra == "test"
  47. Requires-Dist: pytest>=6.0.1; extra == "test"
  48. Requires-Dist: pytest-md-report>=0.6.2; extra == "test"
  49. Dynamic: author
  50. Dynamic: author-email
  51. Dynamic: classifier
  52. Dynamic: description
  53. Dynamic: description-content-type
  54. Dynamic: home-page
  55. Dynamic: keywords
  56. Dynamic: license
  57. Dynamic: license-file
  58. Dynamic: project-url
  59. Dynamic: provides-extra
  60. Dynamic: requires-python
  61. Dynamic: summary
  62. .. contents:: **pathvalidate**
  63. :backlinks: top
  64. :depth: 2
  65. Summary
  66. =========
  67. `pathvalidate <https://github.com/thombashi/pathvalidate>`__ is a Python library to sanitize/validate a string such as filenames/file-paths/etc.
  68. |PyPI pkg ver| |conda pkg ver| |Supported Python ver| |Supported Python impl| |CI status| |Test coverage| |CodeQL|
  69. .. |PyPI pkg ver| image:: https://badge.fury.io/py/pathvalidate.svg
  70. :target: https://badge.fury.io/py/pathvalidate
  71. :alt: PyPI package version
  72. .. |conda pkg ver| image:: https://anaconda.org/conda-forge/pathvalidate/badges/version.svg
  73. :target: https://anaconda.org/conda-forge/pathvalidate
  74. :alt: conda package version
  75. .. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/pathvalidate.svg
  76. :target: https://pypi.org/project/pathvalidate
  77. :alt: Supported Python versions
  78. .. |Supported Python impl| image:: https://img.shields.io/pypi/implementation/pathvalidate.svg
  79. :target: https://pypi.org/project/pathvalidate
  80. :alt: Supported Python implementations
  81. .. |CI status| image:: https://github.com/thombashi/pathvalidate/actions/workflows/ci.yml/badge.svg
  82. :target: https://github.com/thombashi/pathvalidate/actions/workflows/ci.yml
  83. :alt: CI status of Linux/macOS/Windows
  84. .. |Test coverage| image:: https://coveralls.io/repos/github/thombashi/pathvalidate/badge.svg?branch=master
  85. :target: https://coveralls.io/github/thombashi/pathvalidate?branch=master
  86. :alt: Test coverage: coveralls
  87. .. |CodeQL| image:: https://github.com/thombashi/pathvalidate/actions/workflows/github-code-scanning/codeql/badge.svg
  88. :target: https://github.com/thombashi/pathvalidate/actions/workflows/github-code-scanning/codeql
  89. :alt: CodeQL
  90. Features
  91. ---------
  92. - Sanitize/Validate a string as a:
  93. - file name
  94. - file path
  95. - Sanitize will do:
  96. - Remove invalid characters for a target platform
  97. - Replace reserved names for a target platform
  98. - Normalize
  99. - Remove unprintable characters
  100. - Argument validator/sanitizer for ``argparse`` and ``click``
  101. - Multi platform support:
  102. - ``Linux``
  103. - ``Windows``
  104. - ``macOS``
  105. - ``POSIX``: POSIX-compliant systems (Linux, macOS, etc.)
  106. - ``universal``: platform independent
  107. - Multibyte character support
  108. CLI tool
  109. ---------
  110. You can find this package's command line interface tool at the `pathvalidate-cli <https://github.com/thombashi/pathvalidate-cli>`__ repository.
  111. Examples
  112. ==========
  113. Sanitize a filename
  114. ---------------------
  115. :Sample Code:
  116. .. code-block:: python
  117. from pathvalidate import sanitize_filename
  118. fname = "fi:l*e/p\"a?t>h|.t<xt"
  119. print(f"{fname} -> {sanitize_filename(fname)}\n")
  120. fname = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
  121. print(f"{fname} -> {sanitize_filename(fname)}\n")
  122. :Output:
  123. .. code-block::
  124. fi:l*e/p"a?t>h|.t<xt -> filepath.txt
  125. _a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f(g)h+i_0.txt
  126. The default target ``platform`` is ``universal``.
  127. i.e. the sanitized file name is valid for any platform.
  128. Sanitize a filepath
  129. ---------------------
  130. :Sample Code:
  131. .. code-block:: python
  132. from pathvalidate import sanitize_filepath
  133. fpath = "fi:l*e/p\"a?t>h|.t<xt"
  134. print(f"{fpath} -> {sanitize_filepath(fpath)}\n")
  135. fpath = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
  136. print(f"{fpath} -> {sanitize_filepath(fpath)}\n")
  137. :Output:
  138. .. code-block::
  139. fi:l*e/p"a?t>h|.t<xt -> file/path.txt
  140. _a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f/(g)h+i_0.txt
  141. Validate a filename
  142. ---------------------
  143. :Sample Code:
  144. .. code-block:: python
  145. import sys
  146. from pathvalidate import ValidationError, validate_filename
  147. try:
  148. validate_filename("fi:l*e/p\"a?t>h|.t<xt")
  149. except ValidationError as e:
  150. print(f"{e}\n", file=sys.stderr)
  151. try:
  152. validate_filename("COM1")
  153. except ValidationError as e:
  154. print(f"{e}\n", file=sys.stderr)
  155. :Output:
  156. .. code-block::
  157. [PV1100] invalid characters found: platform=universal, description=invalids=('/'), value='fi:l*e/p"a?t>h|.t<xt'
  158. [PV1002] found a reserved name by a platform: 'COM1' is a reserved name, platform=universal, reusable_name=False
  159. Check a filename
  160. ------------------
  161. :Sample Code:
  162. .. code-block:: python
  163. from pathvalidate import is_valid_filename, sanitize_filename
  164. fname = "fi:l*e/p\"a?t>h|.t<xt"
  165. print(f"is_valid_filename('{fname}') return {is_valid_filename(fname)}\n")
  166. sanitized_fname = sanitize_filename(fname)
  167. print(f"is_valid_filename('{sanitized_fname}') return {is_valid_filename(sanitized_fname)}\n")
  168. :Output:
  169. .. code-block::
  170. is_valid_filename('fi:l*e/p"a?t>h|.t<xt') return False
  171. is_valid_filename('filepath.txt') return True
  172. filename/filepath validator for ``argparse``
  173. ----------------------------------------------
  174. :Sample Code:
  175. .. code-block:: python
  176. from argparse import ArgumentParser
  177. from pathvalidate.argparse import validate_filename_arg, validate_filepath_arg
  178. parser = ArgumentParser()
  179. parser.add_argument("--filename", type=validate_filename_arg)
  180. parser.add_argument("--filepath", type=validate_filepath_arg)
  181. options = parser.parse_args()
  182. if options.filename:
  183. print(f"filename: {options.filename}")
  184. if options.filepath:
  185. print(f"filepath: {options.filepath}")
  186. :Output:
  187. .. code-block::
  188. $ ./examples/argparse_validate.py --filename eg
  189. filename: eg
  190. $ ./examples/argparse_validate.py --filename e?g
  191. usage: argparse_validate.py [-h] [--filename FILENAME] [--filepath FILEPATH]
  192. argparse_validate.py: error: argument --filename: [PV1100] invalid characters found: invalids=(':'), value='e:g', platform=Windows
  193. .. note::
  194. ``validate_filepath_arg`` consider ``platform`` as of ``"auto"`` if the input is an absolute file path.
  195. filename/filepath sanitizer for ``argparse``
  196. ----------------------------------------------
  197. :Sample Code:
  198. .. code-block:: python
  199. from argparse import ArgumentParser
  200. from pathvalidate.argparse import sanitize_filename_arg, sanitize_filepath_arg
  201. parser = ArgumentParser()
  202. parser.add_argument("--filename", type=sanitize_filename_arg)
  203. parser.add_argument("--filepath", type=sanitize_filepath_arg)
  204. options = parser.parse_args()
  205. if options.filename:
  206. print("filename: {}".format(options.filename))
  207. if options.filepath:
  208. print("filepath: {}".format(options.filepath))
  209. :Output:
  210. .. code-block::
  211. $ ./examples/argparse_sanitize.py --filename e/g
  212. filename: eg
  213. .. note::
  214. ``sanitize_filepath_arg`` is set platform as ``"auto"``.
  215. filename/filepath validator for ``click``
  216. -------------------------------------------
  217. :Sample Code:
  218. .. code-block:: python
  219. import click
  220. from pathvalidate.click import validate_filename_arg, validate_filepath_arg
  221. @click.command()
  222. @click.option("--filename", callback=validate_filename_arg)
  223. @click.option("--filepath", callback=validate_filepath_arg)
  224. def cli(filename: str, filepath: str) -> None:
  225. if filename:
  226. click.echo(f"filename: {filename}")
  227. if filepath:
  228. click.echo(f"filepath: {filepath}")
  229. if __name__ == "__main__":
  230. cli()
  231. :Output:
  232. .. code-block::
  233. $ ./examples/click_validate.py --filename ab
  234. filename: ab
  235. $ ./examples/click_validate.py --filepath e?g
  236. Usage: click_validate.py [OPTIONS]
  237. Try 'click_validate.py --help' for help.
  238. Error: Invalid value for '--filename': [PV1100] invalid characters found: invalids=('?'), value='e?g', platform=Windows
  239. filename/filepath sanitizer for ``click``
  240. -------------------------------------------
  241. :Sample Code:
  242. .. code-block:: python
  243. import click
  244. from pathvalidate.click import sanitize_filename_arg, sanitize_filepath_arg
  245. @click.command()
  246. @click.option("--filename", callback=sanitize_filename_arg)
  247. @click.option("--filepath", callback=sanitize_filepath_arg)
  248. def cli(filename, filepath):
  249. if filename:
  250. click.echo(f"filename: {filename}")
  251. if filepath:
  252. click.echo(f"filepath: {filepath}")
  253. if __name__ == "__main__":
  254. cli()
  255. :Output:
  256. .. code-block::
  257. $ ./examples/click_sanitize.py --filename a/b
  258. filename: ab
  259. For more information
  260. ----------------------
  261. More examples can be found at
  262. https://pathvalidate.rtfd.io/en/latest/pages/examples/index.html
  263. Installation
  264. ============
  265. Installation: pip
  266. ------------------------------
  267. ::
  268. pip install pathvalidate
  269. Installation: conda
  270. ------------------------------
  271. ::
  272. conda install conda-forge::pathvalidate
  273. Installation: apt
  274. ------------------------------
  275. ::
  276. sudo add-apt-repository ppa:thombashi/ppa
  277. sudo apt update
  278. sudo apt install python3-pathvalidate
  279. Dependencies
  280. ============
  281. Python 3.9+
  282. no external dependencies.
  283. Documentation
  284. ===============
  285. https://pathvalidate.rtfd.io/
  286. Sponsors
  287. ====================================
  288. |chasbecker| |shiguredo| |b4tman| |Arturi0| |github|
  289. .. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48&u=6da7176e51ae2654bcfd22564772ef8a3bb22318&v=4
  290. :target: https://github.com/chasbecker
  291. :alt: ex-sponsor: Charles Becker (chasbecker)
  292. .. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48&v=4
  293. :target: https://github.com/shiguredo
  294. :alt: ex-sponsor: 時雨堂 (shiguredo)
  295. .. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4
  296. :target: https://github.com/b4tman
  297. :alt: onetime: Dmitry Belyaev (b4tman)
  298. .. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4
  299. :target: https://github.com/Arturi0
  300. :alt: onetime: Arturi0
  301. .. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48&v=4
  302. :target: https://github.com/github
  303. :alt: onetime: GitHub (github)
  304. `Become a sponsor <https://github.com/sponsors/thombashi>`__