Modify values in the Record 'extra' dictionary attribute in the Zerigo DNS
driver to be set to None instead of an empty string ('') if a value for
the provided key is not set.Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d84dead8 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d84dead8 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d84dead8 Branch: refs/heads/0.13.2 Commit: d84dead876bc23930ba4d692e9212eb47a82c8ac Parents: ebcfe18 Author: Tomaz Muraus <[email protected]> Authored: Fri Sep 6 23:36:26 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Fri Sep 13 15:11:52 2013 +0200 ---------------------------------------------------------------------- CHANGES | 5 +++++ libcloud/dns/drivers/zerigo.py | 10 +++++----- libcloud/test/dns/test_zerigo.py | 2 ++ libcloud/utils/xml.py | 13 +++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/d84dead8/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 249d2d0..45d12f5 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,11 @@ Changes with Apache Libcloud 0.13.2 if a record has a TTL set. [Tomaz Muraus] + - Modify values in the Record 'extra' dictionary attribute in the Zerigo DNS + driver to be set to None instead of an empty string ('') if a value for + the provided key is not set. + [Tomaz Muraus] + Changes with Apache Libcloud 0.13.1 *) General http://git-wip-us.apache.org/repos/asf/libcloud/blob/d84dead8/libcloud/dns/drivers/zerigo.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/drivers/zerigo.py b/libcloud/dns/drivers/zerigo.py index e92c2c3..0ff16e0 100644 --- a/libcloud/dns/drivers/zerigo.py +++ b/libcloud/dns/drivers/zerigo.py @@ -419,11 +419,11 @@ class ZerigoDNSDriver(DNSDriver): type = self._string_to_record_type(type) data = findtext(element=elem, xpath='data') - notes = findtext(element=elem, xpath='notes') - state = findtext(element=elem, xpath='state') - fqdn = findtext(element=elem, xpath='fqdn') - priority = findtext(element=elem, xpath='priority') - ttl = findtext(element=elem, xpath='ttl') + notes = findtext(element=elem, xpath='notes', no_text_value=None) + state = findtext(element=elem, xpath='state', no_text_value=None) + fqdn = findtext(element=elem, xpath='fqdn', no_text_value=None) + priority = findtext(element=elem, xpath='priority', no_text_value=None) + ttl = findtext(element=elem, xpath='ttl', no_text_value=None) if ttl: ttl = int(ttl) http://git-wip-us.apache.org/repos/asf/libcloud/blob/d84dead8/libcloud/test/dns/test_zerigo.py ---------------------------------------------------------------------- diff --git a/libcloud/test/dns/test_zerigo.py b/libcloud/test/dns/test_zerigo.py index de4a5d4..16aa827 100644 --- a/libcloud/test/dns/test_zerigo.py +++ b/libcloud/test/dns/test_zerigo.py @@ -70,6 +70,8 @@ class ZerigoTests(unittest.TestCase): self.assertEqual(records[0].type, RecordType.A) self.assertEqual(records[0].data, '172.16.16.1') self.assertEqual(records[0].extra['fqdn'], 'www.example.com') + self.assertEqual(records[0].extra['notes'], None) + self.assertEqual(records[0].extra['priority'], None) self.assertEqual(records[1].name, 'test') self.assertEqual(records[1].extra['ttl'], 3600) http://git-wip-us.apache.org/repos/asf/libcloud/blob/d84dead8/libcloud/utils/xml.py ---------------------------------------------------------------------- diff --git a/libcloud/utils/xml.py b/libcloud/utils/xml.py index 71aa7cc..d05b843 100644 --- a/libcloud/utils/xml.py +++ b/libcloud/utils/xml.py @@ -22,8 +22,17 @@ def fixxpath(xpath, namespace=None): return '/'.join(['{%s}%s' % (namespace, e) for e in xpath.split('/')]) -def findtext(element, xpath, namespace=None): - return element.findtext(fixxpath(xpath=xpath, namespace=namespace)) +def findtext(element, xpath, namespace=None, no_text_value=''): + """ + :param no_text_value: Value to return if the provided element has no text + value. + :type no_text_value: ``object`` + """ + value = element.findtext(fixxpath(xpath=xpath, namespace=namespace)) + + if value == '': + return no_text_value + return value def findattr(element, xpath, namespace=None):
