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)
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
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)