Last active
March 8, 2020 17:56
-
-
Save ajkerrigan/161b9568092e4d42491b030bab227fa1 to your computer and use it in GitHub Desktop.
VisiData - Auto-prompt for zip passwords
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
| import zipfile | |
| from functools import wraps | |
| from visidata import vd | |
| def open_decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| try: | |
| return func(*args, **kwargs) | |
| except RuntimeError as err: | |
| if 'password required' in err.args[0]: | |
| pwd = vd.input(f'{args[0].filename} is encrypted, enter password: ', type='password') | |
| return func(*args, **kwargs, pwd=pwd.encode()) | |
| return wrapper | |
| zipfile.ZipFile.open = open_decorator(zipfile.ZipFile.open) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a sample, and one glaring issue is that it both echoes back the password and adds it to a history buffer. Useful as a proof of concept, but I'd imagine as a follow-up it'd be worth trying to combine VisiData's built-in line editing input functionality with getpass and explicitly avoid echoing or adding to history.