Skip to content

Commit

Permalink
pyzfs: python3 support (library 2/2)
Browse files Browse the repository at this point in the history
* All pool, dataset, and nvlist keys must be of type bytes.

Reviewed-by: John Ramsden <johnramsden@riseup.net>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #8096
  • Loading branch information
behlendorf authored and madwizard committed Jan 7, 2019
1 parent 53c213a commit 100cb8d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions contrib/pyzfs/libzfs_core/_error_translation.py
Expand Up @@ -732,7 +732,7 @@ def _pool_name(name):
'@' separates a snapshot name from the rest of the dataset name.
'#' separates a bookmark name from the rest of the dataset name.
'''
return re.split('[/@#]', name, 1)[0]
return re.split(b'[/@#]', name, 1)[0]


def _fs_name(name):
Expand All @@ -742,26 +742,26 @@ def _fs_name(name):
'@' separates a snapshot name from the rest of the dataset name.
'#' separates a bookmark name from the rest of the dataset name.
'''
return re.split('[@#]', name, 1)[0]
return re.split(b'[@#]', name, 1)[0]


def _is_valid_name_component(component):
allowed = string.ascii_letters + string.digits + '-_.: '
return component and all(x in allowed for x in component)
allowed = string.ascii_letters + string.digits + u'-_.: '
return component and all(x in allowed.encode() for x in component)


def _is_valid_fs_name(name):
return name and all(_is_valid_name_component(c) for c in name.split('/'))
return name and all(_is_valid_name_component(c) for c in name.split(b'/'))


def _is_valid_snap_name(name):
parts = name.split('@')
parts = name.split(b'@')
return (len(parts) == 2 and _is_valid_fs_name(parts[0]) and
_is_valid_name_component(parts[1]))


def _is_valid_bmark_name(name):
parts = name.split('#')
parts = name.split(b'#')
return (len(parts) == 2 and _is_valid_fs_name(parts[0]) and
_is_valid_name_component(parts[1]))

Expand Down
20 changes: 10 additions & 10 deletions contrib/pyzfs/libzfs_core/_libzfs_core.py
Expand Up @@ -113,7 +113,7 @@ def lzc_create(name, ds_type='zfs', props=None, key=None):
if props is None:
props = {}
if key is None:
key = bytes("")
key = b""
else:
key = bytes(key)
if ds_type == 'zfs':
Expand Down Expand Up @@ -848,7 +848,7 @@ def lzc_change_key(fsname, crypt_cmd, props=None, key=None):
if props is None:
props = {}
if key is None:
key = bytes("")
key = b""
else:
key = bytes(key)
cmd = {
Expand Down Expand Up @@ -931,13 +931,13 @@ def lzc_channel_program(
error.
'''
output = {}
params_nv = nvlist_in({"argv": params})
params_nv = nvlist_in({b"argv": params})
with nvlist_out(output) as outnvl:
ret = _lib.lzc_channel_program(
poolname, program, instrlimit, memlimit, params_nv, outnvl)
errors.lzc_channel_program_translate_error(
ret, poolname, output.get("error"))
return output.get("return")
ret, poolname, output.get(b"error"))
return output.get(b"return")


def lzc_channel_program_nosync(
Expand Down Expand Up @@ -976,13 +976,13 @@ def lzc_channel_program_nosync(
error.
'''
output = {}
params_nv = nvlist_in({"argv": params})
params_nv = nvlist_in({b"argv": params})
with nvlist_out(output) as outnvl:
ret = _lib.lzc_channel_program_nosync(
poolname, program, instrlimit, memlimit, params_nv, outnvl)
errors.lzc_channel_program_translate_error(
ret, poolname, output.get("error"))
return output.get("return")
ret, poolname, output.get(b"error"))
return output.get(b"return")


def lzc_receive_resumable(
Expand Down Expand Up @@ -1406,7 +1406,7 @@ def lzc_receive_with_cmdprops(
if cmdprops is None:
cmdprops = {}
if key is None:
key = bytes("")
key = b""
else:
key = bytes(key)

Expand Down Expand Up @@ -1511,7 +1511,7 @@ def lzc_sync(poolname, force=False):
`innvl` has been replaced by the `force` boolean and `outnvl` has been
conveniently removed since it's not used.
'''
innvl = nvlist_in({"force": force})
innvl = nvlist_in({b"force": force})
with nvlist_out({}) as outnvl:
ret = _lib.lzc_sync(poolname, innvl, outnvl)
errors.lzc_sync_translate_error(ret, poolname)
Expand Down
8 changes: 4 additions & 4 deletions contrib/pyzfs/libzfs_core/_nvlist.py
Expand Up @@ -160,10 +160,10 @@ def _type_info(typeid):

# only integer properties need to be here
_prop_name_to_type_str = {
"rewind-request": "uint32",
"type": "uint32",
"N_MORE_ERRORS": "int32",
"pool_context": "int32",
b"rewind-request": "uint32",
b"type": "uint32",
b"N_MORE_ERRORS": "int32",
b"pool_context": "int32",
}


Expand Down
4 changes: 2 additions & 2 deletions contrib/pyzfs/libzfs_core/ctypes.py
Expand Up @@ -31,8 +31,8 @@ def _func(value):
try:
type_info.elements[value]
except KeyError as e:
raise OverflowError('Invalid enum <%s> value %s' %
(type_info.cname, e.message))
raise OverflowError('Invalid enum <%s> value %s: %s' %
(type_info.cname, value, e))
else:
_ffi.new(type_name + '*', value)
return _ffi.cast(type_name, value)
Expand Down

0 comments on commit 100cb8d

Please sign in to comment.