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
Tarfile.add with bytes path is failing #70185
Comments
With python 3.4, Tarfile doesn't properly support adding a files with bytes path. Only unicode is supported. It's failing with exception similar to:
File "/usr/lib/python3.4/tarfile.py", line 1907, in add It uses os.sep, and u"/". Instead, it should use something like posixpath.py:_get_sep(path). |
See also bpo-21996. |
Does using a surrogateescape encoded filename work? (You won't get the error you report...my question is, does that do the right thing when building the archive?) |
Is the tarfile module designed to support bytes for file names in general? The documentation doesn’t seem to mention bytes anywhere relevant. This seems more like a new feature rather than a bug to me. |
I'm using bytes in Unix to represent a path. From As such, I'm expecting to use bytes to represent a path with tarfile. Also, tar file format doesn't define any specific encoding for filename. I'me xpecting to but any kind of bytes data for a given filename... since this was wokring in tarfile with py2.
I will need to have further look into surrogateescape. I read somewhere it was an experimental feature, so I didn't try it. Thanks both for your quick feedback in this holidays. |
It looks like surrogate-escaped bytes should be supported thanks to bpo-8390, although this is not so useful if you use the “pax” format (which always uses UTF-8 internally). To generate a surrogate-escaped string, you can “decode” it with the following error handler: >>> b"non-as\xA9ii".decode("ascii", "surrogateescape")
'non-as\udca9ii' |
It's a bit tricky, but with help of surrogateescape I get the expected result. I'm closing this bug. Thanks |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: