[SCM] morituri/master: more filtering
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:10:05 UTC 2014
The following commit has been merged in the master branch:
commit 34d58e2b5ccfa4863551aa67fdd1af24a288444d
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Sat Jul 13 22:46:20 2013 +0200
more filtering
diff --git a/morituri/common/path.py b/morituri/common/path.py
index 65fc206..b7f39e8 100644
--- a/morituri/common/path.py
+++ b/morituri/common/path.py
@@ -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
diff --git a/morituri/common/program.py b/morituri/common/program.py
index c5db0b0..bd9b8f7 100644
--- a/morituri/common/program.py
+++ b/morituri/common/program.py
@@ -67,11 +67,14 @@ class Program(log.Loggable):
d = {}
- for key in ['fat', 'special']:
+ for key, default in {
+ 'fat': True,
+ 'special': False
+ }.items():
value = None
value = self._config.getboolean('main', 'path_filter_'+ key)
if value is None:
- value = True
+ value = default
d[key] = value
diff --git a/morituri/test/test_common_path.py b/morituri/test/test_common_path.py
index 45b160d..7cec838 100644
--- a/morituri/test/test_common_path.py
+++ b/morituri/test/test_common_path.py
@@ -9,8 +9,17 @@ from morituri.test import common
class FilterTestCase(common.TestCase):
def setUp(self):
- self._filter = path.PathFilter()
+ self._filter = path.PathFilter(special=True)
def testSlash(self):
part = u'A Charm/A Blade'
self.assertEquals(self._filter.filter(part), u'A Charm-A Blade')
+
+ def testFat(self):
+ part = u'A Word: F**k you?'
+ self.assertEquals(self._filter.filter(part), u'A Word- F__k you_')
+
+ def testSpecial(self):
+ part = u'<<< $&*!\' "()`{}[]spaceship>>>'
+ self.assertEquals(self._filter.filter(part),
+ u'___ _____ ________spaceship___')
diff --git a/morituri/test/test_program_cdparanoia.py b/morituri/test/test_program_cdparanoia.py
index 4d7b510..6c910b1 100644
--- a/morituri/test/test_program_cdparanoia.py
+++ b/morituri/test/test_program_cdparanoia.py
@@ -69,7 +69,7 @@ class VersionTestCase(common.TestCase):
self.failUnless(v)
# of the form III 10.2
# make sure it ends with a digit
- self.failUnless(int(v[-1]))
+ self.failUnless(int(v[-1]), v)
class AnalyzeFileTask(cdparanoia.AnalyzeTask):
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list