Skip to content

Commit

Permalink
pyzfs python3 support (4): compatible changes
Browse files Browse the repository at this point in the history
These changes are slightly less idomatic python, but
are valid and efficient in both python 2 and 3.

Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
Requires-builders: none
  • Loading branch information
aerusso authored and behlendorf committed Dec 12, 2018
1 parent c3b70d2 commit 0e2a47d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions contrib/pyzfs/libzfs_core/_error_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def _map(ret, name):
def lzc_release_translate_errors(ret, errlist, holds):
if ret == 0:
return
for _, hold_list in holds.items():
for snap in holds:
hold_list = holds[snap]
if not isinstance(hold_list, list):
raise lzc_exc.TypeError('holds must be in a list')

Expand Down Expand Up @@ -716,7 +717,8 @@ def _handle_err_list(ret, errlist, names, exception, mapper):
else:
errors = []
suppressed_count = errlist.pop('N_MORE_ERRORS', 0)
for name, err in errlist.items():
for name in errlist:
err = errlist[name]
errors.append(mapper(err, name))

raise exception(errors, suppressed_count)
Expand Down
9 changes: 5 additions & 4 deletions contrib/pyzfs/libzfs_core/_libzfs_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def lzc_hold(holds, fd=None):
errors.lzc_hold_translate_errors(ret, errlist, holds, fd)
# If there is no error (no exception raised by _handleErrList), but errlist
# is not empty, then it contains missing snapshots.
assert all(x == errno.ENOENT for x in errlist.values())
assert all(errlist[x] == errno.ENOENT for x in errlist)
return list(errlist.keys())


Expand Down Expand Up @@ -522,7 +522,8 @@ def lzc_release(holds):
'''
errlist = {}
holds_dict = {}
for snap, hold_list in holds.items():
for snap in holds:
hold_list = holds[snap]
if not isinstance(hold_list, list):
raise TypeError('holds must be in a list')
holds_dict[snap] = {hold: None for hold in hold_list}
Expand All @@ -532,7 +533,7 @@ def lzc_release(holds):
errors.lzc_release_translate_errors(ret, errlist, holds)
# If there is no error (no exception raised by _handleErrList), but errlist
# is not empty, then it contains missing snapshots and tags.
assert all(x == errno.ENOENT for x in errlist.values())
assert all(errlist[x] == errno.ENOENT for x in errlist)
return list(errlist.keys())


Expand Down Expand Up @@ -1882,7 +1883,7 @@ def lzc_get_props(name):
mountpoint_val = '/' + name
else:
mountpoint_val = None
result = {k: v['value'] for k, v in result.items()}
result = {k: result[k]['value'] for k in result}
if 'clones' in result:
result['clones'] = list(result['clones'].keys())
if mountpoint_val is not None:
Expand Down

0 comments on commit 0e2a47d

Please sign in to comment.