diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-11-24 17:40:11 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-11-24 17:40:11 +0000 |
commit | 414513daf0f0a816b0316e33e96abee6e1d08486 (patch) | |
tree | 406d61345d883820f432118a810ac3da82f29b44 /fs/osfs/__init__.py | |
parent | 17c48538ae56ddda5869613c33edee524b834658 (diff) | |
download | pyfilesystem-414513daf0f0a816b0316e33e96abee6e1d08486.tar.gz |
InvalidCharsInPathError
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@830 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/osfs/__init__.py')
-rw-r--r-- | fs/osfs/__init__.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/fs/osfs/__init__.py b/fs/osfs/__init__.py index 35e4652..a6f0a3a 100644 --- a/fs/osfs/__init__.py +++ b/fs/osfs/__init__.py @@ -22,8 +22,8 @@ import datetime import platform from fs.base import * -from fs.errors import * from fs.path import * +from fs.errors import * from fs import _thread_synchronize_default from fs.osfs.xattrs import OSFSXAttrMixin @@ -87,6 +87,12 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): 'atomic.setcontents' : False, } + if sys.platform == 'win32': + _invalid_path_chars = '\\:*?"<>|' + else: + _invalid_path_chars = '\0' + _re_invalid_path_chars = re.compile('|'.join(re.escape(c) for c in _invalid_path_chars), re.UNICODE) + def __init__(self, root_path, thread_synchronize=_thread_synchronize_default, encoding=None, create=False, dir_mode=0700, use_long_paths=True): """ Creates an FS object that represents the OS Filesystem under a given root path @@ -147,12 +153,18 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): return p return p.decode(self.encoding, 'replace') + def _validate_path(self, path): + """Raise an error if there are any invalid characters in the path""" + if self._re_invalid_path_chars.search(path): + raise InvalidCharsInPathError(path) + def getsyspath(self, path, allow_none=False): path = relpath(normpath(path)).replace("/", os.sep) path = os.path.join(self.root_path, path) if not path.startswith(self.root_path): raise PathError(path, msg="OSFS given path outside root: %(path)s") path = self._decode_path(path) + self._validate_path(path) return path def unsyspath(self, path): |