"""This is a vfs class for the normal filesystem."""
__docformat__ = "restructuredtext"
import os
class Standard:
"""This is a vfs class for the normal filesystem.
It's mostly a wrapper for os.path.
The following attributes are used:
root
This is the root of the filesystem.
"""
def __init__(self, root):
"""Set the root of the filesystem.
If this isn't a directory, raise a ValueError.
"""
if not self.isdir(root):
raise ValueError("root must be a directory")
self.root = root
def __repr__(self):
return '<%s root="%s">' % (self.__class__.__name__, self.root)
def __getattr__(self, attr):
"""Delegate methods.
The following methods are delegated:
isdir, exists, join, splitext, isfile, splitdrive, split, open, stat,
curdir, pardir
"""
if attr in ("isdir", "exists", "join", "splitext", "isfile",
"splitdrive", "split"):
return getattr(os.path, attr)
if attr in ("stat", "curdir", "pardir"):
return getattr(os, attr)
if attr == "open":
return open
raise AttributeError("class %s has no attribute '%s'" %
(self.__class__.__name__, attr))
def translate_path(self, path):
"""Translate ``path`` to the local filename syntax.
Actually, ``path`` is already in the local filename syntax, but this is
your last chance to do anything else, such as making it an absolute
path, etc.
"""
return self.join(self.root, path)
|