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/uri//%22%22?a=commitdiff_plain;h=1516c698e1803185b3bc9cf1515615c6102262aa;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)