mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 14:40:27 +00:00
Update utils.py
This commit is contained in:
parent
33ec2acd3f
commit
c7eaec27d8
@ -238,24 +238,22 @@ class customBoxes:
|
|||||||
}
|
}
|
||||||
order = ["reverse", "ip6arpa", "inaddrarpa"]
|
order = ["reverse", "ip6arpa", "inaddrarpa"]
|
||||||
|
|
||||||
def pretty_domain_name(value):
|
def pretty_domain_name(domain_name):
|
||||||
"""
|
# Add a debugging statement to print out the domain name
|
||||||
Display domain name in original format.
|
print("Received domain name:", domain_name)
|
||||||
If it is IDN domain (Punycode starts with xn--), do the
|
|
||||||
idna decoding.
|
# Check if the domain name is encoded using Punycode
|
||||||
Note that any part of the domain name can be individually punycoded
|
if domain_name.endswith('.xn--'):
|
||||||
"""
|
try:
|
||||||
if isinstance(value, str):
|
# Decode the domain name using the idna library
|
||||||
if value.startswith('xn--') \
|
domain_name = idna.decode(domain_name)
|
||||||
or value.find('.xn--') != -1:
|
except Exception as e:
|
||||||
try:
|
# If the decoding fails, raise an exception with more information
|
||||||
return to_idna(value, 'decode')
|
raise Exception('Cannot decode IDN domain: {}'.format(e))
|
||||||
except:
|
|
||||||
raise Exception('Cannot decode IDN domain')
|
# Return the "pretty" version of the domain name
|
||||||
else:
|
return domain_name
|
||||||
return value
|
|
||||||
else:
|
|
||||||
raise Exception('Require the Punycode in string format')
|
|
||||||
|
|
||||||
def to_idna(value, action):
|
def to_idna(value, action):
|
||||||
splits = value.split('.')
|
splits = value.split('.')
|
||||||
|
Loading…
Reference in New Issue
Block a user