[New-bugs-announce] [issue17656] Python 2.7.4 Breaks ZipFile Extraction

Vhati report at bugs.python.org
Mon Apr 8 05:20:59 CEST 2013


New submission from Vhati:

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

----------
components: Unicode
messages: 186264
nosy: Vhati, ezio.melotti
priority: normal
severity: normal
status: open
title: Python 2.7.4 Breaks ZipFile Extraction
type: crash
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17656>
_______________________________________


More information about the New-bugs-announce mailing list