summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2011-12-21 18:27:50 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2011-12-21 18:27:50 (GMT)
commit7d4d074c9996f07a859a6e5a38774aa65a4ff85c (patch)
tree0b687fb4e67971b42df43b78a3bc78ae1701a065 /Lib/tarfile.py
parent5b95eb90a7167285b6544b50865227c584943c9a (diff)
downloadcpython-7d4d074c9996f07a859a6e5a38774aa65a4ff85c.zip
cpython-7d4d074c9996f07a859a6e5a38774aa65a4ff85c.tar.gz
cpython-7d4d074c9996f07a859a6e5a38774aa65a4ff85c.tar.bz2
Issue #13639: Accept unicode filenames in tarfile.open(mode="w|gz").
Passing a unicode filename to tarfile.open() along with mode "w|gz" failed with a UnicodeError because the filename was not encoded properly before being written to the gzipped stream in the FNAME extra field.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index ed5bcf2..bd73965 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -454,6 +454,8 @@ class _Stream:
0)
timestamp = struct.pack("<L", long(time.time()))
self.__write("\037\213\010\010%s\002\377" % timestamp)
+ if type(self.name) is unicode:
+ self.name = self.name.encode("iso-8859-1", "replace")
if self.name.endswith(".gz"):
self.name = self.name[:-3]
self.__write(self.name + NUL)