Skip to content

Commit

Permalink
[zip-] handle loading/extracting files locally + remotely #2127
Browse files Browse the repository at this point in the history
  • Loading branch information
anjakefala committed Nov 20, 2023
1 parent 037b0d1 commit 0e1afd8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions visidata/loaders/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ class ZipSheet(Sheet):

def openZipFile(self, fp, *args, **kwargs):
'''Use VisiData input to handle password-protected zip files.'''
if isinstance(fp, zipfile.ZipFile):
zip_open = fp.open
elif isinstance(fp, unzip_http.RemoteZipFile):
zip_open = fp._open
try:
return fp._open(*args, **kwargs)
return zip_open(*args, **kwargs)
except RuntimeError as err:
if 'password required' in err.args[0]:
pwd = vd.input(f'{args[0].filename} is encrypted, enter password: ', display=False)
return fp._open(*args, **kwargs, pwd=pwd.encode('utf-8'))
return zip_open(*args, **kwargs, pwd=pwd.encode('utf-8'))
vd.exceptionCaught(err)

def openRow(self, row):
Expand Down

0 comments on commit 0e1afd8

Please # to comment.