2013-10-07 07:15:47 +00:00
|
|
|
""" Helper methods for various modules. """
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2013-12-07 20:54:19 +00:00
|
|
|
RE_SANITIZE_FILENAME = re.compile(r"(~|(\.\.)|/|\+)")
|
|
|
|
RE_SLUGIFY = re.compile(r'[^A-Za-z0-9_]+')
|
|
|
|
|
2013-11-11 00:46:48 +00:00
|
|
|
|
2013-10-07 07:15:47 +00:00
|
|
|
def sanitize_filename(filename):
|
|
|
|
""" Sanitizes a filename by removing .. / and \\. """
|
2013-12-07 20:54:19 +00:00
|
|
|
return RE_SANITIZE_FILENAME.sub("", filename)
|
|
|
|
|
|
|
|
|
|
|
|
def slugify(text):
|
|
|
|
""" Slugifies a given text. """
|
|
|
|
text = text.strip().replace(" ", "_")
|
|
|
|
|
|
|
|
return RE_SLUGIFY.sub("", text)
|