core/homeassistant/util.py

19 lines
432 B
Python
Raw Normal View History

2013-10-07 07:15:47 +00:00
""" Helper methods for various modules. """
import re
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 \\. """
return RE_SANITIZE_FILENAME.sub("", filename)
def slugify(text):
""" Slugifies a given text. """
text = text.strip().replace(" ", "_")
return RE_SLUGIFY.sub("", text)