mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -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):
|
def validate_zonemgr(zonemgr):
|
||||||
assert isinstance(zonemgr, DNSName)
|
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'))
|
raise ValueError(_('too many \'@\' characters'))
|
||||||
|
|
||||||
|
|
||||||
|
@ -423,7 +423,11 @@ def zonemgr_callback(option, opt_str, value, parser):
|
|||||||
encoding = getattr(sys.stdin, 'encoding', None)
|
encoding = getattr(sys.stdin, 'encoding', None)
|
||||||
if encoding is None:
|
if encoding is None:
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
|
|
||||||
|
# value is of a string type in both py2 and py3
|
||||||
|
if not isinstance(value, unicode):
|
||||||
value = value.decode(encoding)
|
value = value.decode(encoding)
|
||||||
|
|
||||||
validate_zonemgr_str(value)
|
validate_zonemgr_str(value)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
# FIXME we can do this in better way
|
# 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:
|
if stderr_encoding is None:
|
||||||
stderr_encoding = 'utf-8'
|
stderr_encoding = 'utf-8'
|
||||||
error = unicode(e).encode(stderr_encoding)
|
error = unicode(e).encode(stderr_encoding)
|
||||||
parser.error("invalid zonemgr: " + error)
|
parser.error(b"invalid zonemgr: " + error)
|
||||||
|
|
||||||
parser.values.zonemgr = value
|
parser.values.zonemgr = value
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user