Teach should_ignore_file to require unicode
authorDavid Stainton <dstainton415@gmail.com>
Mon, 14 Sep 2015 10:41:12 +0000 (12:41 +0200)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 15 Sep 2015 17:43:00 +0000 (18:43 +0100)
src/allmydata/magicpath.py
src/allmydata/test/test_magicpath.py

index b072b463298722ed8c4f445ac0a0d75c2c83b5ef..ba15ed581bdd455af7ea0e87edf9f68dfbbf1ed7 100644 (file)
@@ -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
index 2362bc3f3abfac88ff3769898bc27e6ec425ec92..1227a2c4d90209170ec6d42d330206857ffac1cc 100644 (file)
@@ -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)