Created
December 25, 2016 20:36
-
-
Save ischurov/cf4c0eae198ea1d63ad4b8b4db72558d to your computer and use it in GitHub Desktop.
A helper function useful to decode cp866-encoded filenames in tar archives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decode_escaped_cp866(s): | |
out = [] | |
for token in re.finditer(r"%([0-9A-F]{2})|(.)", s): | |
if token.group(1) is not None: | |
out.append(bytes([int(token.group(1), 16)])) | |
elif token.group(2) is not None: | |
out.append(token.group(2).encode('utf-8')) | |
return b"".join(out).decode('cp866') | |
print(decode_escaped_cp866("%8C%A0%E0%A8%EF - %84%87")) | |
# Мария - ДЗ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment