Skip to main content

A Python 2.7/3.2+ package to sanitize filenames in a (hopefully) cross-platform, cross-filesystem manner.

Project description

filename-sanitizer
==================

A Python 2.7/3.2+ module that aims to sanitize filenames in a cross-platform, cross-filesystem manner.

Dedicated to Nadia Mahmood, my good friend Jawaad's newborn daughter. Maybe this module will be useful to her if she ever decides to follow her father's footsteps in becoming a hacker. ;-)

This is only a beginning; much work needs to be done to deal with the various filesystems' under-documented aspects.

Unlike most of the extremely naïve, whitelist-based solutions found on the Internet, this solution deals much better with Unicode filenames.

How to use
----------

```py3
>>> from filename_sanitizer import sanitize_path_fragment
>>> crazy_filename = u'"foo/bar<bla>yada*meow?.'
>>> sanitized_filename = sanitize_path_fragment(
... crazy_filename,
... target_file_systems = {'ntfs_win32'},
... replacement = u'-'
... )
...
>>> print(sanitized_filename)
-foo-bar-bla-yada-meow--
>>>
```

Read the file [`filename_sanitizer/__init__.py`](filename_sanitizer/__init__.py) for details of how the function deals with various file systems.

License
-------

BSD 2-Clause License. See the file [LICENSE](LICENSE).


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filename-sanitizer-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

filename_sanitizer-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file filename-sanitizer-0.1.0.tar.gz.

File metadata

  • Download URL: filename-sanitizer-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for filename-sanitizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b79ef7b46ffc60bf51cd1dd623e6ff39af7f88e6a583b0d02653aea17994dc4
MD5 5062be25106435e31934a5c90988aa91
BLAKE2b-256 667311ce0d3978aaac29daeb2cd84d9c7788747f7951b65b9029afa7e45c0c71

See more details on using hashes here.

File details

Details for the file filename_sanitizer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: filename_sanitizer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for filename_sanitizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc70ebef9167deed735a73ea2033066707331c504400aa0de2f221b75d2cd84
MD5 ab9262194437312286ba2f83a7ec2019
BLAKE2b-256 49c65972f7810b3ccf8e6809d8c01ba872678f816ed23e41619487c454496569

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page