Created
May 22, 2020 16:28
-
-
Save agalea91/bfbb2036547c64923330055b6c7f8cb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_valid_filename(s): | |
""" | |
Return the given string converted to a string that can be used for a clean | |
filename. Remove leading and trailing spaces; convert other spaces to | |
underscores; and remove anything that is not an alphanumeric, dash, | |
underscore, or dot. | |
# https://github.com/django/django/blob/master/django/utils/text.py | |
""" | |
s = str(s).strip().replace(' ', '_') | |
s = re.sub(r'(?u)[^-\w.]', '', s) | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment