more filtering
This commit is contained in:
@@ -28,17 +28,31 @@ class PathFilter(object):
|
||||
I filter path components for safe storage on file systems.
|
||||
"""
|
||||
|
||||
def __init__(self, slashes=True, fat=True, special=True):
|
||||
def __init__(self, slashes=True, quotes=True, fat=True, special=False):
|
||||
"""
|
||||
@param slashes: whether to convert slashes to dashes
|
||||
@parm fat: whether to strip characters illegal on FAT filesystems
|
||||
@param quotes: whether to normalize quotes
|
||||
@param fat: whether to strip characters illegal on FAT filesystems
|
||||
@param special: whether to strip special characters
|
||||
"""
|
||||
self._slashes = slashes
|
||||
self._quotes = quotes
|
||||
self._fat = fat
|
||||
self._special = special
|
||||
|
||||
def filter(self, path):
|
||||
if self._slashes:
|
||||
path = re.sub(r'[/]', '-', path, re.UNICODE)
|
||||
path = re.sub(r'[/\\]', '-', path, re.UNICODE)
|
||||
|
||||
if self._quotes:
|
||||
path = re.sub(ur'[\u2019]', "'", path, re.UNICODE)
|
||||
|
||||
if self._special:
|
||||
# replace separators with a hyphen
|
||||
path = re.sub(r'[:\|]', '-', path, re.UNICODE)
|
||||
path = re.sub(r'[\*\?&!\'\"\$\(\)`{}\[\]<>]', '_', path, re.UNICODE)
|
||||
|
||||
if self._fat:
|
||||
path = re.sub(r'[:\*\?"<>|"]', '_', path, re.UNICODE)
|
||||
|
||||
return path
|
||||
|
||||
Reference in New Issue
Block a user