-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Unzip with encoded filenames
- Written by Oleg Broytman. Copyright (C) 2009, 2010 PhiloSoft Design.
+ Written by Oleg Broytman. Copyright (C) 2009-2024 PhiloSoft Design.
"""
import sys, os, time
for zinfo in zf.infolist():
path = zinfo.filename
- if not isinstance(path, unicode):
- path = path.decode('cp866')
- recoded_path = path.encode(default_encoding)
- print recoded_path
+ if isinstance(path, bytes):
+ recoded_path = path.decode('cp866').encode(default_encoding)
+ else:
+ recoded_path = path
+ print(recoded_path)
if path.startswith('./'):
- tgt = os.path.join(out, recoded_path[2:])
- else:
- tgt = os.path.join(out, recoded_path)
+ recoded_path = recoded_path[2:]
+ tgt = os.path.join(out, recoded_path)
tgtdir = os.path.dirname(tgt)
if not os.path.exists(tgtdir):
if not tgt.endswith('/'):
infile = zf.open(zinfo.filename)
- fp = open(tgt, 'wb')
- copyfileobj(infile, fp)
- fp.close()
+ if zinfo.external_attr == 0xA1ED0000:
+ os.symlink(infile.read(), tgt)
+ else: # regular file
+ fp = open(tgt, 'wb')
+ copyfileobj(infile, fp)
+ fp.close()
infile.close()
- dt = time.mktime(zinfo.date_time + (0, 0, -1))
- os.utime(tgt, (dt, dt))
+ if zinfo.external_attr != 0xA1ED0000:
+ # set timestamp for directories and files but not symlinks
+ dt = time.mktime(zinfo.date_time + (0, 0, -1))
+ os.utime(tgt, (dt, dt))
zf.close()