Change the way TempFS's _meta dict gets built so that it 'inherits' default…

Change the way TempFS's _meta dict gets built so that it 'inherits' default values from OSFS's _meta (eliminates duplicate code)
parent bdf95abf
......@@ -22,24 +22,11 @@ class TempFS(OSFS):
"""Create a Filesystem in a temporary directory (with tempfile.mkdtemp),
and removes it when the TempFS object is cleaned up."""
_meta = { 'thread_safe' : True,
'virtual' : False,
'read_only' : False,
'unicode_paths' : os.path.supports_unicode_filenames,
'case_insensitive_paths' : os.path.normcase('Aa') == 'aa',
'pickle_contents': False,
'network' : False,
'atomic.move' : True,
'atomic.copy' : True,
'atomic.makedir' : True,
'atomic.rename' : True,
'atomic.setcontents' : False
}
if platform.system() == 'Windows':
_meta["invalid_path_chars"] = ''.join(chr(n) for n in xrange(31)) + '\\:*?"<>|'
else:
_meta["invalid_path_chars"] = '\0'
_meta = dict(OSFS._meta)
_meta['pickle_contents'] = False
_meta['network'] = False
_meta['atomic.move'] = True
_meta['atomic.copy'] = True
def __init__(self, identifier=None, temp_dir=None, dir_mode=0700, thread_synchronize=_thread_synchronize_default):
"""Creates a temporary Filesystem
......
......@@ -124,3 +124,10 @@ class TestTempFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
td = self.fs._temp_dir
return os.path.exists(os.path.join(td, relpath(p)))
def test_invalid_chars(self):
super(TestTempFS, self).test_invalid_chars()
self.assertRaises(errors.InvalidCharsInPathError, self.fs.open, 'invalid\0file', 'wb')
self.assertFalse(self.fs.isvalidpath('invalid\0file'))
self.assert_(self.fs.isvalidpath('validfile'))
self.assert_(self.fs.isvalidpath('completely_valid/path/foo.bar'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment