summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-23 02:20:16 +0000
committerwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-23 02:20:16 +0000
commit52a338f9a00e873974a4816c0ea0f6b59734f968 (patch)
tree24f5a9a3533a67ec6049c9a3c501d024787235b5 /fs
parent0464dfd0040905c48dddcf79681c1f138066730f (diff)
downloadpyfilesystem-52a338f9a00e873974a4816c0ea0f6b59734f968.tar.gz
Small optimization
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@572 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs')
-rw-r--r--fs/path.py30
-rw-r--r--fs/tempfs.py8
-rw-r--r--fs/tests/__init__.py15
-rw-r--r--fs/tests/test_path.py1
4 files changed, 34 insertions, 20 deletions
diff --git a/fs/path.py b/fs/path.py
index dcedd61..87a8691 100644
--- a/fs/path.py
+++ b/fs/path.py
@@ -77,20 +77,24 @@ def recursepath(path, reverse=False):
>>> recursepath('a/b/c')
['/', u'/a', u'/a/b', u'/a/b/c']
- """
+ """
+ paths = [u'/']
+ append = paths.append
+ path = u'/' + normpath(path.lstrip('/'))
+ find = path.find
+ pos = 1
+ if len(path) > 1:
+ while 1:
+ pos = find('/', pos + 1)
+ if pos == -1:
+ append(path)
+ break
+ append(path[:pos])
+
if reverse:
- paths = []
- append = paths.append
- path = abspath(normpath(path)).rstrip("/")
- while path:
- append(path)
- path = dirname(path).rstrip("/")
- paths.append(u"/")
- return paths
- else:
- paths = [u""] + list(iteratepath(path))
- return [u"/"] + [u'/'.join(paths[:i+1]) for i in xrange(1,len(paths))]
-
+ return paths[::-1]
+ return paths
+
def abspath(path):
"""Convert the given path to an absolute path.
diff --git a/fs/tempfs.py b/fs/tempfs.py
index 793a29c..380b76f 100644
--- a/fs/tempfs.py
+++ b/fs/tempfs.py
@@ -7,6 +7,7 @@ Make a temporary file system that exists in a folder provided by the OS. All fil
"""
import os
+import os.path
import time
import tempfile
@@ -23,7 +24,8 @@ class TempFS(OSFS):
_meta = { 'virtual' : False,
'read_only' : False,
'unicode_paths' : os.path.supports_unicode_filenames,
- 'case_insensitive_paths' : os.path.normcase('Aa') == 'aa',
+ 'case_insensitive_paths' : os.path.normcase('Aa') == 'aa',
+ 'pickle_contents': False,
'network' : False,
'atomic.move' : True,
'atomic.copy' : True,
@@ -55,7 +57,9 @@ class TempFS(OSFS):
return u'<TempFS: %s>' % self._temp_dir
def __setstate__(self, state):
- state = super(TempFS, self).__setstate__(state)
+ """Pickle the TempFS. TempFS delted their contents when closed, so pickling
+ is not garanteed to preserve the directory contents"""
+ state = super(TempFS, self).__setstate__(state)
self._temp_dir = tempfile.mkdtemp(self.identifier or "TempFS", dir=self.temp_dir)
super(TempFS, self).__init__(self._temp_dir,
dir_mode=self.dir_mode,
diff --git a/fs/tests/__init__.py b/fs/tests/__init__.py
index 7e1c865..59f7291 100644
--- a/fs/tests/__init__.py
+++ b/fs/tests/__init__.py
@@ -685,11 +685,16 @@ class FSTestCases(object):
self.assertEquals(self.fs.getcontents('f.txt'),contents)
def test_pickling(self):
- self.fs.setcontents("test1","hello world")
- fs2 = pickle.loads(pickle.dumps(self.fs))
- self.assert_(fs2.isfile("test1"))
- fs3 = pickle.loads(pickle.dumps(self.fs,-1))
- self.assert_(fs3.isfile("test1"))
+ if self.fs.getmeta('pickle_contents', True):
+ self.fs.setcontents("test1","hello world")
+ fs2 = pickle.loads(pickle.dumps(self.fs))
+ self.assert_(fs2.isfile("test1"))
+ fs3 = pickle.loads(pickle.dumps(self.fs,-1))
+ self.assert_(fs3.isfile("test1"))
+ else:
+ # Just make sure it doesn't throw an exception
+ fs2 = pickle.loads(pickle.dumps(self.fs))
+
def test_big_file(self):
chunk_size = 1024 * 256
diff --git a/fs/tests/test_path.py b/fs/tests/test_path.py
index 8c8a635..8356b4c 100644
--- a/fs/tests/test_path.py
+++ b/fs/tests/test_path.py
@@ -103,6 +103,7 @@ class TestPathFunctions(unittest.TestCase):
self.assertEquals(recursepath("hello",reverse=True),["/hello","/"])
self.assertEquals(recursepath("",reverse=True),["/"])
+
def test_isdotfile(self):
for path in ['.foo',
'.svn',