Commit 623515d4 by willmcgugan

Fixed unicode encoding for directory listings

parent 3af4d595
...@@ -47,12 +47,12 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS): ...@@ -47,12 +47,12 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS):
:param dir_mode: srt :param dir_mode: srt
:param thread_synchronize: If True, this object will be thread-safe by use of a threading.Lock object :param thread_synchronize: If True, this object will be thread-safe by use of a threading.Lock object
:param encoding: The encoding method for path strings :param encoding: The encoding method for path strings
:param create: Of True, then root_path will be created (if neccesary) :param create: Of True, then root_path will be created (if necessary)
""" """
super(OSFS, self).__init__(thread_synchronize=thread_synchronize) super(OSFS, self).__init__(thread_synchronize=thread_synchronize)
self.encoding = encoding self.encoding = encoding or sys.getfilesystemencoding()
root_path = os.path.expanduser(os.path.expandvars(root_path)) root_path = os.path.expanduser(os.path.expandvars(root_path))
root_path = os.path.normpath(os.path.abspath(root_path)) root_path = os.path.normpath(os.path.abspath(root_path))
# Enable long pathnames on win32 # Enable long pathnames on win32
...@@ -79,14 +79,15 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS): ...@@ -79,14 +79,15 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS):
def __unicode__(self): def __unicode__(self):
return u"<OSFS: %s>" % self.root_path return u"<OSFS: %s>" % self.root_path
def _decode_path(self, p):
if isinstance(p, unicode):
return p
return p.decode(self.encoding, 'replace')
def getsyspath(self, path, allow_none=False): def getsyspath(self, path, allow_none=False):
path = relpath(normpath(path)).replace("/",os.sep) path = relpath(normpath(path)).replace("/",os.sep)
path = os.path.join(self.root_path, path) path = os.path.join(self.root_path, path)
if not isinstance(path,unicode): path = self._decode_path(path)
if self.encoding is None:
path = path.decode(sys.getfilesystemencoding())
else:
path = path.decode(self.encoding)
return path return path
def unsyspath(self,path): def unsyspath(self,path):
...@@ -122,7 +123,7 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS): ...@@ -122,7 +123,7 @@ class OSFS(OSFSXAttrMixin,OSFSWatchMixin,FS):
@convert_os_errors @convert_os_errors
def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False): def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
paths = os.listdir(self.getsyspath(path)) paths = [self._decode_path(p) for p in os.listdir(self.getsyspath(path))]
return self._listdir_helper(path, paths, wildcard, full, absolute, dirs_only, files_only) return self._listdir_helper(path, paths, wildcard, full, absolute, dirs_only, files_only)
@convert_os_errors @convert_os_errors
......
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