This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Vhati
Recipients Vhati, ezio.melotti
Date 2013-04-08.03:20:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1365391259.55.0.44522935247.issue17656@psf.upfronthosting.co.za>
In-reply-to
Content
Python 2.7.4 fails while extracting zip files when 'member' is a unicode path.

---
Traceback (most recent call last):
  ...
    my_zip.extract(item, tmp_folder_path)
  File "D:\Apps\Python274\lib\zipfile.py", line 1024, in extract
    return self._extract_member(member, path, pwd)
  File "D:\Apps\Python274\lib\zipfile.py", line 1057, in _extract_member
    arcname = arcname.translate(table)
TypeError: character mapping must return integer, None or unicode
---
2.7.3 had no problems because the call to translate() is new.


The following, copied from ZipFile.py, will recreate the error.
--
import string
illegal = ':<>|"?*'
table = string.maketrans(illegal, '_' * len(illegal))

arcname = "hi"
arcname = arcname.translate(table)
# ascii strings are fine

arcname = u"hi"
arcname = arcname.translate(table)
# unicode fails
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: character mapping must return integer, None or unicode
---

I tried using unicode literals for the illegal string and maketrans underscore arg, but that didn't work. Suggestions?


Here's a link to the doc for translate().
http://docs.python.org/2/library/stdtypes.html#str.translate
History
Date User Action Args
2013-04-08 03:20:59Vhatisetrecipients: + Vhati, ezio.melotti
2013-04-08 03:20:59Vhatisetmessageid: <1365391259.55.0.44522935247.issue17656@psf.upfronthosting.co.za>
2013-04-08 03:20:59Vhatilinkissue17656 messages
2013-04-08 03:20:58Vhaticreate