From 0579077599fcf859be76b622487070f85faa1a4d Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 8 Nov 2017 13:08:30 +0100 Subject: [PATCH] New property name_unicode for a zone object and using it for output. --- pp_lib/pdns_zone.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pp_lib/pdns_zone.py b/pp_lib/pdns_zone.py index 4a83d4a..05cdc40 100644 --- a/pp_lib/pdns_zone.py +++ b/pp_lib/pdns_zone.py @@ -17,12 +17,12 @@ import copy # Third party modules # Own modules -from .common import pp, to_bytes +from .common import pp, to_bytes, to_utf8 from .errors import PpError from .obj import PpBaseObjectError, PpBaseObject -__version__ = '0.1.2' +__version__ = '0.2.1' LOG = logging.getLogger(__name__) @@ -165,7 +165,7 @@ class PdnsApiZone(PpBaseObject): # ----------------------------------------------------------- @property def name(self): - """The kname of the zone.""" + """The name of the zone.""" return getattr(self, '_name', None) @name.setter @@ -179,6 +179,17 @@ class PdnsApiZone(PpBaseObject): else: self._name = None + # ----------------------------------------------------------- + @property + def name_unicode(self): + """The name of the zone in unicode, if it is an IDNA encoded zone.""" + n = getattr(self, '_name', None) + if n is None: + return None + if 'xn--' in n: + return to_utf8(n).decode('idna') + return n + # ----------------------------------------------------------- @property def notified_serial(self): @@ -217,6 +228,7 @@ class PdnsApiZone(PpBaseObject): res['last_check'] = self.last_check res['masters'] = copy.copy(self.masters) res['name'] = self.name + res['name_unicode'] = self.name_unicode res['notified_serial'] = self.notified_serial res['serial'] = self.serial res['url'] = self.url @@ -267,7 +279,7 @@ class PdnsApiZone(PpBaseObject): tpl = self.get_list_template() params = { - 'name': self.name, + 'name': self.name_unicode, 'len_zone': len_zone, 'kind': self.kind, 'serial': self.serial, -- 2.39.5