Commit 7f9532d0 by rfkelly0

allow listdir/ilistdir to take non-keyword args

parent cb43070a
...@@ -15,7 +15,7 @@ implementations of this interface such as: ...@@ -15,7 +15,7 @@ implementations of this interface such as:
""" """
__version__ = "0.4.0a7" __version__ = "0.4.0a8"
__author__ = "Will McGugan (will@willmcgugan.com)" __author__ = "Will McGugan (will@willmcgugan.com)"
# 'base' imports * from 'path' and 'errors', so their # 'base' imports * from 'path' and 'errors', so their
......
...@@ -491,7 +491,12 @@ class FS(object): ...@@ -491,7 +491,12 @@ class FS(object):
instead of a list. Depending on the filesystem this may be more instead of a list. Depending on the filesystem this may be more
efficient than calling listdir() and iterating over the resulting list. efficient than calling listdir() and iterating over the resulting list.
""" """
return iter(self.listdir(path,wildcard,full,absolute,dirs_only,files_only)) return iter(self.listdir(path,
wildcard=wildcard,
full=full,
absolute=absolute,
dirs_only=dirs_only,
files_only=files_only))
def ilistdirinfo(self, path="./", def ilistdirinfo(self, path="./",
wildcard=None, wildcard=None,
......
...@@ -65,4 +65,4 @@ class HTTPFS(FS): ...@@ -65,4 +65,4 @@ class HTTPFS(FS):
absolute=False, absolute=False,
dirs_only=False, dirs_only=False,
files_only=False): files_only=False):
return [] return []
\ No newline at end of file
...@@ -493,12 +493,12 @@ class CacheFS(WrapFS): ...@@ -493,12 +493,12 @@ class CacheFS(WrapFS):
return super(CacheFS,self).isfile(path) return super(CacheFS,self).isfile(path)
@_cached_method @_cached_method
def listdir(self,path="",**kwds): def listdir(self,path="",*args,**kwds):
return super(CacheFS,self).listdir(path,**kwds) return super(CacheFS,self).listdir(path,*args,**kwds)
@_cached_method @_cached_method
def listdirinfo(self,path="",**kwds): def listdirinfo(self,path="",*args,**kwds):
return super(CacheFS,self).listdirinfo(path,**kwds) return super(CacheFS,self).listdirinfo(path,*args,**kwds)
@_cached_method @_cached_method
def getinfo(self,path): def getinfo(self,path):
......
...@@ -93,11 +93,14 @@ class TestHideDotFilesFS(unittest.TestCase): ...@@ -93,11 +93,14 @@ class TestHideDotFilesFS(unittest.TestCase):
def test_hidden(self): def test_hidden(self):
self.assertEquals(len(self.fs.listdir(hidden=False)), 2) self.assertEquals(len(self.fs.listdir(hidden=False)), 2)
self.assertEquals(len(list(self.fs.ilistdir(hidden=False))), 2)
def test_nonhidden(self): def test_nonhidden(self):
self.assertEquals(len(self.fs.listdir(hidden=True)), 4) self.assertEquals(len(self.fs.listdir(hidden=True)), 4)
self.assertEquals(len(list(self.fs.ilistdir(hidden=True))), 4)
def test_default(self): def test_default(self):
self.assertEquals(len(self.fs.listdir()), 2) self.assertEquals(len(self.fs.listdir()), 2)
self.assertEquals(len(list(self.fs.ilistdir())), 2)
...@@ -224,7 +224,12 @@ class WrapFS(FS): ...@@ -224,7 +224,12 @@ class WrapFS(FS):
yield e yield e
@rewrite_errors @rewrite_errors
def listdirinfo(self, path="", **kwds): def listdirinfo(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
dirs_only=dirs_only,
files_only=files_only)
full = kwds.pop("full",False) full = kwds.pop("full",False)
absolute = kwds.pop("absolute",False) absolute = kwds.pop("absolute",False)
wildcard = kwds.pop("wildcard",None) wildcard = kwds.pop("wildcard",None)
...@@ -247,7 +252,12 @@ class WrapFS(FS): ...@@ -247,7 +252,12 @@ class WrapFS(FS):
return entries return entries
@rewrite_errors @rewrite_errors
def ilistdirinfo(self, path="", **kwds): def ilistdirinfo(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
dirs_only=dirs_only,
files_only=files_only)
full = kwds.pop("full",False) full = kwds.pop("full",False)
absolute = kwds.pop("absolute",False) absolute = kwds.pop("absolute",False)
wildcard = kwds.pop("wildcard",None) wildcard = kwds.pop("wildcard",None)
......
...@@ -28,13 +28,27 @@ class HideDotFilesFS(WrapFS): ...@@ -28,13 +28,27 @@ class HideDotFilesFS(WrapFS):
def _decode(self, path): def _decode(self, path):
return path return path
def listdir(self, path="", **kwds): def listdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False, hidden=False):
hidden = kwds.pop("hidden",False) kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
dirs_only=dirs_only,
files_only=files_only)
entries = self.wrapped_fs.listdir(path,**kwds) entries = self.wrapped_fs.listdir(path,**kwds)
if not hidden: if not hidden:
entries = [e for e in entries if not self.is_hidden(e)] entries = [e for e in entries if not self.is_hidden(e)]
return entries return entries
def ilistdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False, hidden=False):
kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
dirs_only=dirs_only,
files_only=files_only)
for e in self.wrapped_fs.ilistdir(path,**kwds):
if hidden or not self.is_hidden(e):
yield e
def walk(self, path="/", wildcard=None, dir_wildcard=None, search="breadth",hidden=False): def walk(self, path="/", wildcard=None, dir_wildcard=None, search="breadth",hidden=False):
if search == "breadth": if search == "breadth":
dirs = [path] dirs = [path]
......
...@@ -144,14 +144,14 @@ class SimulateXAttr(WrapFS): ...@@ -144,14 +144,14 @@ class SimulateXAttr(WrapFS):
def _decode(self,path): def _decode(self,path):
return path return path
def listdir(self,path="",**kwds): def listdir(self,path="",*args,**kwds):
"""Prevent .xattr from appearing in listings.""" """Prevent .xattr from appearing in listings."""
entries = self.wrapped_fs.listdir(path,**kwds) entries = self.wrapped_fs.listdir(path,*args,**kwds)
return [e for e in entries if not self._is_attr_path(e)] return [e for e in entries if not self._is_attr_path(e)]
def ilistdir(self,path="",**kwds): def ilistdir(self,path="",*args,**kwds):
"""Prevent .xattr from appearing in listings.""" """Prevent .xattr from appearing in listings."""
for e in self.wrapped_fs.ilistdir(path,**kwds): for e in self.wrapped_fs.ilistdir(path,*args,**kwds):
if not self._is_attr_path(e): if not self._is_attr_path(e):
yield e yield e
......
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