From: David Stainton Date: Mon, 14 Sep 2015 10:41:12 +0000 (+0200) Subject: Teach should_ignore_file to require unicode X-Git-Url: https://git.rkrishnan.org/%5B/frontends/%22file:/flags/statistics?a=commitdiff_plain;h=3ce212fd9e7592921ff3e97e178b8af8f389e115;p=tahoe-lafs%2Ftahoe-lafs.git Teach should_ignore_file to require unicode --- diff --git a/src/allmydata/magicpath.py b/src/allmydata/magicpath.py index b072b463..ba15ed58 100644 --- a/src/allmydata/magicpath.py +++ b/src/allmydata/magicpath.py @@ -2,6 +2,8 @@ import re import os.path +from allmydata.util.assertutil import precondition + def path2magic(path): return re.sub(ur'[/@]', lambda m: {u'/': u'@_', u'@': u'@@'}[m.group(0)], path) @@ -13,6 +15,8 @@ IGNORE_SUFFIXES = [u'.backup', u'.tmp', u'.conflicted'] IGNORE_PREFIXES = [u'.'] def should_ignore_file(path_u): + precondition(isinstance(path_u, unicode), path_u=path_u) + for suffix in IGNORE_SUFFIXES: if path_u.endswith(suffix): return True diff --git a/src/allmydata/test/test_magicpath.py b/src/allmydata/test/test_magicpath.py index 2362bc3f..1227a2c4 100644 --- a/src/allmydata/test/test_magicpath.py +++ b/src/allmydata/test/test_magicpath.py @@ -20,9 +20,9 @@ class MagicPath(unittest.TestCase): self.failUnlessEqual(magicpath.magic2path(test), expected) def test_should_ignore(self): - self.failUnlessEqual(magicpath.should_ignore_file(".bashrc"), True) - self.failUnlessEqual(magicpath.should_ignore_file("bashrc."), False) - self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/branch/.bashrc"), True) - self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/.branch/bashrc"), True) - self.failUnlessEqual(magicpath.should_ignore_file("forest/.tree/branch/bashrc"), True) - self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/branch/bashrc"), False) + self.failUnlessEqual(magicpath.should_ignore_file(u".bashrc"), True) + self.failUnlessEqual(magicpath.should_ignore_file(u"bashrc."), False) + self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/.bashrc"), True) + self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/.branch/bashrc"), True) + self.failUnlessEqual(magicpath.should_ignore_file(u"forest/.tree/branch/bashrc"), True) + self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/bashrc"), False)