Skip to content

Instantly share code, notes, and snippets.

@mapix
Last active November 2, 2018 12:32
Show Gist options
  • Save mapix/cd4d9439655ef641b8849500dbfe6b5a to your computer and use it in GitHub Desktop.
Save mapix/cd4d9439655ef641b8849500dbfe6b5a to your computer and use it in GitHub Desktop.
#-*- coding: utf-8 -*-
# env PYTHONIOENCODING=utf8
# env LANG=en_US.UTF-8
# env LC_CTYPE=en_US.UTF-8
# env LC_ALL=en_US.UTF-8
# apt install locales
# locale-gen en_US.UTF-8
import sys
import os.path
import zipfile
def ensure_default_type(name):
if sys.version_info.major == 2:
if isinstance(name, unicode):
name = name.encode('utf-8')
else:
if isinstance(name, bytes):
name = name.decode('utf-8')
return name
def extractall(source, target):
source = ensure_default_type(source)
target = ensure_default_type(target)
r = zipfile.ZipFile(source, 'r')
for member in r.filelist:
if sys.version_info.major != 2 and not (member.flag_bits & 0x800):
member.filename = member.filename.encode('cp437').decode('utf-8')
r._extract_member(member, target, None)
extractall("/Users/ggg/upload_image.zip", u"中文路径")
extractall("/Users/ggg/upload_image.zip", u"中文路径bytes".encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment