Commit 803816d3 by willmcgugan

Added getpathurl method

parent 80c9bf05
......@@ -55,4 +55,5 @@
any watchers when a new one was added.
* MountFS: added support for mounting at the root directory, and for
mounting over an existing mount.
* Added 'getpathurl' and 'haspathurl' methods
......@@ -139,7 +139,7 @@ class FS(object):
:param thread_synconize: If True, a lock object will be created for the object, otherwise a dummy lock will be used.
:type thread_synchronize: bool
"""
super(FS,self).__init__()
super(FS, self).__init__()
self.closed = False
if thread_synchronize:
self._lock = threading.RLock()
......@@ -199,6 +199,7 @@ class FS(object):
:type allow_none: bool
:raises NoSysPathError: If the path does not map on to a system path, and allow_none is set to False (default)
:rtype: unicode
"""
if not allow_none:
raise NoSysPathError(path=path)
......@@ -207,12 +208,42 @@ class FS(object):
def hassyspath(self, path):
"""Check if the path maps to a system path (a path recognised by the OS).
:param path: -- path to check
:param path: path to check
:returns: True if `path` maps to a system path
:rtype: bool
"""
return self.getsyspath(path, allow_none=True) is not None
def getpathurl(self, path, allow_none=False):
"""Returns a url that corresponds to the given path, if one exists.
If the path does not have an equivalent URL form (and allow_none is False)
then a NoPathURLError exception is thrown. Otherwise the URL will be
returns as an unicode string.
:param path: a path within the filesystem
:param allow_none: if true, this method can return None if there is no
URL form of the given path
:type allow_none: bool
:raises NoPathURLError: If no URL form exists, and allow_none is False (the default)
:rtype: unicode
"""
if not allow_none:
raise NoPathURLError(path=path)
return None
def haspathurl(self, path):
"""Check if the path has an equivalent URL form
:param path: path to check
:returns: True if `path` has a URL form
:rtype: bool
"""
return self.getpathurl(path, allow_none=True) is not None
def open(self, path, mode="r", **kwargs):
"""Open a the given path as a file-like object.
......
"""
Defines the Exception classes thrown by PyFilesystem objects. Exceptions relating to the underling filesystem are translated in to one of the following Exceptions. Exceptions that relate to a path store that path in `self.path`.
Defines the Exception classes thrown by PyFilesystem objects. Exceptions relating
to the underling filesystem are translated in to one of the following Exceptions.
Exceptions that relate to a path store that path in `self.path`.
All Exception classes are derived from `FSError` which can be used as a catch-all exception.
All Exception classes are derived from `FSError` which can be used as a
catch-all exception.
"""
......@@ -17,6 +20,7 @@ __all__ = ['FSError',
'OperationTimeoutError',
'ResourceError',
'NoSysPathError',
'NoPathURLError',
'ResourceNotFoundError',
'ResourceInvalidError',
'DestinationExistsError',
......@@ -127,6 +131,11 @@ class NoSysPathError(ResourceError):
default_message = "No mapping to OS filesystem: %(path)s"
class NoPathURLError(ResourceError):
"""Exception raised when there is no URL form for a given path."""
default_message = "No URL form: %(path)s"
class ResourceNotFoundError(ResourceError):
"""Exception raised when a required resource is not found."""
default_message = "Resource not found: %(path)s"
......
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