web/ldt/utils/path.py
author ymh <ymh.work@gmail.com>
Wed, 29 Sep 2010 10:10:07 +0200
changeset 81 97b12f5f2c7a
permissions -rw-r--r--
first version of embed and auth. plan to implement rbac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
Some small file related utilities
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
"""
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import unicodedata
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import string
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
def sanitize_filename(filename):
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').lower()
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    return ''.join(c for c in cleanedFilename if c in validFilenameChars).replace(' ','_')
97b12f5f2c7a first version of embed and auth. plan to implement rbac
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14