PyFilesystem / pyfilesystem

Python filesystem abstraction layer
http://pyfilesystem.org/
BSD 3-Clause "New" or "Revised" License
288 stars 63 forks source link

u'/' must not be unicode - both because os.sep is a byte string #212

Closed zopyx closed 9 years ago

zopyx commented 9 years ago

and not a unicode string and it causes UnicodeErrors with code using pyfilsystem for transparent access to arbitrary filesystems using the same code as www.xml-director.info.

willmcgugan commented 9 years ago

Do you have a traceback for the unicode errors? Which platform / Python version?

The fix might not be so simple, os.sep is unicode on Python3.

zopyx commented 9 years ago

I am getting this error with OSFS on Mac with Python 2.7.X. The same code (including tests) is passing on Linux and Mac with DAVFS. The goal of my project is support all common FS types (WebDAV, LocalFS, FTPSH, SFTPSH)

Traceback (most recent call last): File "/Users/ajung/.buildout/eggs/unittest2-0.5.1-py2.7.egg/unittest2/case.py", line 333, in run self.setUp() File "/Users/ajung/sandboxes/xmldirector.plonecore/xmldirector/plonecore/tests/test_connector.py", line 43, in setUp with handle.open(PREFIX + u'/üöä/üöä.xml', 'wb') as fp: File "/Users/ajung/.buildout/eggs/fs-0.5.2-py2.7.egg/fs/iotools.py", line 126, in wrapper *kwargs) File "/Users/ajung/sandboxes/xmldirector.plonecore/xmldirector/plonecore/davfs.py", line 94, in open self._checklock(path, op='open{}'.format(mode[0])) File "/Users/ajung/sandboxes/xmldirector.plonecore/xmldirector/plonecore/davfs.py", line 75, in _check_lock log_info = lm.get_lock(path) File "/Users/ajung/sandboxes/xmldirector.plonecore/xmldirector/plonecore/locking.py", line 88, in get_lock with handle.open(lock_filename, 'rb', lock_check=False) as fp: File "/Users/ajung/.buildout/eggs/fs-0.5.2-py2.7.egg/fs/iotools.py", line 126, in wrapper _kwargs) File "/Users/ajung/sandboxes/xmldirector.plonecore/xmldirector/plonecore/davfs.py", line 95, in open return super(BaseWrapper, self).open(path, mode, _kwargs) File "/Users/ajung/.buildout/eggs/fs-0.5.2-py2.7.egg/fs/errors.py", line 257, in wrapper return func(self,args,kwds) File "/Users/ajung/.buildout/eggs/fs-0.5.2-py2.7.egg/fs/osfs/init.py", line 221, in open sys_path = self.getsyspath(path) File "/Users/ajung/.buildout/eggs/fs-0.5.2-py2.7.egg/fs/osfs/init**.py", line 158, in getsyspath path = relpath(normpath(path)).replace(u"/", os.sep) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 45: ordinal not in range(128)

willmcgugan commented 9 years ago

I don't think it will fix it, but can you try against 0.5.3?

Can I just check you are calling open with a unicode string? Paths within a FS object should all be unicode.

zopyx commented 9 years ago

fs 0.5.3 has the same problem. And yes, the related unittest creates a filename as unicode string

with handle.open(PREFIX + u'/üöä/üöä.xml', 'wb') as fp: ....

willmcgugan commented 9 years ago

I can't reproduce that here. On OSX, Python2.7. Any chance you could give me a short script that shows the problem?

btw, test_connector.py has a strange coding declaration, first line. Not sure if that's related.

willmcgugan commented 9 years ago

I can't reproduce this issue. Let me know if you can reproduce it with a simple code snippet.