Skip to content

Instantly share code, notes, and snippets.

@ajkerrigan
Last active March 8, 2020 17:56
Show Gist options
  • Select an option

  • Save ajkerrigan/161b9568092e4d42491b030bab227fa1 to your computer and use it in GitHub Desktop.

Select an option

Save ajkerrigan/161b9568092e4d42491b030bab227fa1 to your computer and use it in GitHub Desktop.
VisiData - Auto-prompt for zip passwords
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)
@ajkerrigan
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment