Python Virtual File System: A spike test

Duncan Booth duncan at NOSPAMrcp.co.uk
Wed Jun 12 12:09:38 CEST 2002


"Mike C. Fletcher" <mcfletch at rogers.com> wrote in
news:mailman.1023872902.2540.python-list at python.org: 

> An initial implementation (spike test) exploring the viability of the 
> approach.  Implementation provides:
> 
>      equality testing
>      parent/child/ancestor/descendent retrieval/testing
>      filesystem-role testing (file/dir/root)
>      root retrieval and root comparisons
>      "walking" (callback-based recursive iteration)
>      listing (returning Paths which include their parent directory)
>      fragment determination (i.e. c:\\temp\\test -> "c:\\", "temp",
>      "test" recursive directory-tree removal (including files)
>      open( ) method for path specifiers
> 
> The current implementation is a sub-class of str which provides a
> number of new methods (and overrides some built-in methods) to provide
> the above functionality.
> 

My initial thoughts:
What is your use-case for equality testing? Especially given that it is 
virtually impossible to implement this reliably.
For example the normcase implementation in the standard library lowercases 
all pathnames under windows. While this is useful most of the time, not all 
filesystems are case insensitive, even on windows.

Your class should support iterators: probably three flavours, one for 
contained files, one for contained directories and one for everything. The 
list, walk, and remove methods would probably then benefit from reusing the 
iterators.

The FileSystemPath seems a bit windows oriented with drive() and unc() 
methods.

The root method returns a drive such as 'c:'. This means that:
 >>> temp = filepath.path('c:\\temp')
 >>> temp
 FileSystemPath('c:\\temp')
 >>> temp.root()
 FileSystemPath('c:')
 >>> temp.root()+'fred'
 FileSystemPath('c:fred')

I would have expected temp.root()+'fred' to give a reference to 'fred' in 
the root directory, not a relative reference.

There seems to be a problem with the implementation of canonical() when 
working with some UNC pathnames (watch w2):
 >>> from filepath import path
 >>> w = path(r'\\osprey\work')
 >>> w1 = path(r'd:\work')
 >>> w2 = path('\\.\d:\work')
 >>> w==w1
 0
 >>> w1==w2
 0
 >>> w.root()
 FileSystemPath('\\\\osprey\\work')
 >>> w1.root()
 FileSystemPath('d:')
 >>> w2.root()
 FileSystemPath('d:')
 >>> w2.canonical()
 'd:\\d:\\work'
 >>> w.canonical()
 '\\\\osprey\\work'

I suspect however, this is a problem with the underlying os.path functions.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list