-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use text_type (unicode for PY2, str for PY3) #12
Conversation
Thanks! merging. |
Any chance of a new release with this fix? |
Looking at this a bit more closely, I think it's better to work with bytes, since that's what Unix filesystems do natively. This module is never used on Windows, IIUC. I would do something like this: try:
fsencode = os.fsencode # Py 3
except AttributeError
def fsencode(p): # Py 2
return p.encode(sys.getfilesystemencoding())
def send2trash():
if isinstance(path, text_type):
# Convert to bytes
path = fsencode(path) Python 3 has ways of roundtripping bytes that can't be decoded in paths, which can't be fully emulated in Python 2. It probably doesn't make much difference on modern desktop systems where the filesystem encoding is reported as UTF-8. But in some situations, Python might decide that the filesystem encoding is ASCII. If you convert all paths to unicode, no path with non-ascii characters can be handled. If you convert all paths to bytes, then passing in the raw bytes of the path will still work in that situation. |
@takluyver As I write in #11 , I'm waiting for some kind of confirmation that the fix actually works. I don't use this package myself. As soon as someone bothers confirming, I'll bother releasing. As for using bytes, I agree with you and I've said something along those lines in #11, but it's a bit more dangerous to work with bytes because the code below has been written assuming strings. This fix here has the advantage of being minimal and of fixing an immediate bug. |
Manually tested on Fedora; I confirm that this fixes it for a unicode path on Python 2, without breaking it for a bytes path, or for either kind of path on Python 3. One future proofing note: I tend to check Would you be interested in any automated testing in this repo? I can make a PR to use Travis or Circle to run the |
Alright, thanks for confirming. Creating a release now. Thanks for the CI offer, but this is a very low activity project. I suspect that the |
Fair enough. We're having a go at integrating send2trash into the Jupyter Notebook, so if things come up, we can try to help fix them. If that means there's a bit more activity, the offer of CI setup stands. A simple Travis config like this changes very little. |
Code is based on the |
@hsoft |
Thanks for the release! |
That fixed the error we were seeing, but unfortunately there's a different error now.
Sorry, I should have tested it more carefully before giving the thumbs up. 😞 It looks like Python 2's urllib.quote() doesn't handle unicode strings. I'll work on a fix tomorrow. |
Also add unicode_literals import That will likely fix the next problem you will hit, catting str and unicode |
Unfortunately not. The problem is coming from I'm working on changing the plat_other code to use bytes paths throughout. |
Closes #11
Thanks @miigotu
I figured, might as well change this to the whole file.