Add path filter
This commit is contained in:
@@ -17,6 +17,7 @@ morituri_PYTHON = \
|
||||
log.py \
|
||||
logcommand.py \
|
||||
mbngs.py \
|
||||
path.py \
|
||||
program.py \
|
||||
renamer.py \
|
||||
task.py
|
||||
|
||||
44
morituri/common/path.py
Normal file
44
morituri/common/path.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# -*- Mode: Python; test-case-name: morituri.test.test_common_path -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
# Morituri - for those about to RIP
|
||||
|
||||
# Copyright (C) 2009 Thomas Vander Stichele
|
||||
|
||||
# This file is part of morituri.
|
||||
#
|
||||
# morituri is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# morituri is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class PathFilter(object):
|
||||
"""
|
||||
I filter path components for safe storage on file systems.
|
||||
"""
|
||||
|
||||
def __init__(self, slashes=True, fat=True, special=True):
|
||||
"""
|
||||
@param slashes: whether to convert slashes to dashes
|
||||
@parm fat: whether to strip characters illegal on FAT filesystems
|
||||
"""
|
||||
self._slashes = slashes
|
||||
self._fat = fat
|
||||
self._special = special
|
||||
|
||||
def filter(self, path):
|
||||
if self._slashes:
|
||||
path = re.sub(r'[/]', '-', path, re.UNICODE)
|
||||
|
||||
return path
|
||||
@@ -12,6 +12,7 @@ EXTRA_DIST = \
|
||||
test_common_encode.py \
|
||||
test_common_gstreamer.py \
|
||||
test_common_mbngs.py \
|
||||
test_common_path.py \
|
||||
test_common_program.py \
|
||||
test_common_renamer.py \
|
||||
test_image_cue.py \
|
||||
|
||||
16
morituri/test/test_common_path.py
Normal file
16
morituri/test/test_common_path.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- Mode: Python; test-case-name: morituri.test.test_common_path -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
from morituri.common import path
|
||||
|
||||
from morituri.test import common
|
||||
|
||||
|
||||
class FilterTestCase(common.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._filter = path.PathFilter()
|
||||
|
||||
def testSlash(self):
|
||||
part = u'A Charm/A Blade'
|
||||
self.assertEquals(self._filter.filter(part), u'A Charm-A Blade')
|
||||
Reference in New Issue
Block a user