mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
py3: fixing zonemgr_callback
Since OptionParser behaves differently in Python 2/3, zonemgr_callback now handles value as str in both version. https://pagure.io/freeipa/issue/5990 Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
This commit is contained in:
parent
06fbf4b312
commit
75d26e1f01
@ -380,7 +380,7 @@ def validate_domain_name(domain_name, allow_underscore=False, allow_slash=False)
|
||||
|
||||
def validate_zonemgr(zonemgr):
|
||||
assert isinstance(zonemgr, DNSName)
|
||||
if any('@' in label for label in zonemgr.labels):
|
||||
if any(b'@' in label for label in zonemgr.labels):
|
||||
raise ValueError(_('too many \'@\' characters'))
|
||||
|
||||
|
||||
|
@ -423,7 +423,11 @@ def zonemgr_callback(option, opt_str, value, parser):
|
||||
encoding = getattr(sys.stdin, 'encoding', None)
|
||||
if encoding is None:
|
||||
encoding = 'utf-8'
|
||||
value = value.decode(encoding)
|
||||
|
||||
# value is of a string type in both py2 and py3
|
||||
if not isinstance(value, unicode):
|
||||
value = value.decode(encoding)
|
||||
|
||||
validate_zonemgr_str(value)
|
||||
except ValueError as e:
|
||||
# FIXME we can do this in better way
|
||||
@ -433,7 +437,7 @@ def zonemgr_callback(option, opt_str, value, parser):
|
||||
if stderr_encoding is None:
|
||||
stderr_encoding = 'utf-8'
|
||||
error = unicode(e).encode(stderr_encoding)
|
||||
parser.error("invalid zonemgr: " + error)
|
||||
parser.error(b"invalid zonemgr: " + error)
|
||||
|
||||
parser.values.zonemgr = value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user