def _post(self, value, song, keep_extension=True): if value: assert isinstance(value, unicode) value = fsnative(value) if keep_extension: fn = song.get("~filename", ".") ext = fn[fn.rfind("."):].lower() val_ext = value[-len(ext):].lower() if not ext == val_ext: value += ext.lower() if os.name == "nt": assert isinstance(value, unicode) value = strip_win32_incompat_from_path(value) value = expanduser(value) value = limit_path(value) if sep in value and not os.path.isabs(value): raise ValueError("Pattern is not rooted") return value
def _post(self, value, song, keep_extension=True): if value: assert isinstance(value, unicode) value = fsnative(value) if keep_extension: fn = song.get("~filename", ".") ext = fn[fn.rfind(".") :].lower() val_ext = value[-len(ext) :].lower() if not ext == val_ext: value += ext.lower() if os.name == "nt": assert isinstance(value, unicode) value = strip_win32_incompat_from_path(value) value = expanduser(value) value = limit_path(value) if sep in value and not os.path.isabs(value): raise ValueError("Pattern is not rooted") return value
def test_main(self): if os.name == "nt": path = u'C:\\foobar\\ä%s\\%s' % ("x" * 300, "x" * 300) path = limit_path(path) self.failUnlessEqual(len(path), 3 + 6 + 1 + 255 + 1 + 255) else: path = '/foobar/ä%s/%s' % ("x" * 300, "x" * 300) path = limit_path(path) self.failUnlessEqual(len(path), 1 + 6 + 1 + 255 + 1 + 255) path = fsnative(u"foo%s.ext" % (u"x" * 300)) new = limit_path(path, ellipsis=False) self.assertTrue(isinstance(new, fsnative)) self.assertEqual(len(new), 255) self.assertTrue(new.endswith(fsnative(u"xx.ext"))) new = limit_path(path) self.assertTrue(isinstance(new, fsnative)) self.assertEqual(len(new), 255) self.assertTrue(new.endswith(fsnative(u"...ext"))) self.assertTrue(isinstance(limit_path(fsnative()), fsnative)) self.assertEqual(limit_path(fsnative()), fsnative())
def test_main(self): if os.name == "nt": path = u'C:\\foobar\\ä%s\\%s' % ("x" * 300, "x" * 300) path = limit_path(path) self.failUnlessEqual(len(path), 3 + 6 + 1 + 255 + 1 + 255) else: path = '/foobar/ä%s/%s' % ("x" * 300, "x" * 300) path = limit_path(path) self.failUnlessEqual(len(path), 1 + 6 + 1 + 255 + 1 + 255) path = fsnative(u"foo%s.ext" % (u"x" * 300)) new = limit_path(path, ellipsis=False) self.assertTrue(is_fsnative(new)) self.assertEqual(len(new), 255) self.assertTrue(new.endswith(fsnative(u"xx.ext"))) new = limit_path(path) self.assertTrue(is_fsnative(new)) self.assertEqual(len(new), 255) self.assertTrue(new.endswith(fsnative(u"...ext"))) self.assertTrue(is_fsnative(limit_path(fsnative()))) self.assertEqual(limit_path(fsnative()), fsnative())
def filename_for(cls, name: str): # Manually do *minimal* escaping, to allow near-readable filenames for bad, good in cls._SAFER.items(): name = name.replace(bad, good) return path2fsn("%s.%s" % (limit_path(name), cls.EXT))