+ return self.core.system.get_address(proto) or default
+
+
+class DDNSProtocolDynDNS2(object):
+ """
+ This is an abstract class that implements the DynDNS updater
+ protocol version 2. As this is a popular way to update dynamic
+ DNS records, this class is supposed make the provider classes
+ shorter and simpler.
+ """
+
+ # Information about the format of the request is to be found
+ # http://dyn.com/support/developers/api/perform-update/
+ # http://dyn.com/support/developers/api/return-codes/
+
+ def _prepare_request_data(self):
+ data = {
+ "hostname" : self.hostname,
+ "myip" : self.get_address("ipv4"),
+ }
+
+ return data
+
+ def update(self):
+ data = self._prepare_request_data()
+
+ # Send update to the server.
+ response = self.send_request(self.url, data=data,
+ username=self.username, password=self.password)
+
+ # Get the full response message.
+ output = response.read()
+
+ # Handle success messages.
+ if output.startswith("good") or output.startswith("nochg"):
+ return
+
+ # Handle error codes.
+ if output == "badauth":
+ raise DDNSAuthenticationError
+ elif output == "abuse":
+ raise DDNSAbuseError
+ elif output == "notfqdn":
+ raise DDNSRequestError(_("No valid FQDN was given."))
+ elif output == "nohost":
+ raise DDNSRequestError(_("Specified host does not exist."))
+ elif output == "911":
+ raise DDNSInternalServerError
+ elif output == "dnserr":
+ raise DDNSInternalServerError(_("DNS error encountered."))
+ elif output == "badagent":
+ raise DDNSBlockedError
+
+ # If we got here, some other update error happened.
+ raise DDNSUpdateError(_("Server response: %s") % output)
+
+
+class DDNSResponseParserXML(object):
+ """
+ This class provides a parser for XML responses which
+ will be sent by various providers. This class uses the python
+ shipped XML minidom module to walk through the XML tree and return
+ a requested element.
+ """
+
+ def get_xml_tag_value(self, document, content):
+ # Send input to the parser.
+ xmldoc = xml.dom.minidom.parseString(document)
+
+ # Get XML elements by the given content.
+ element = xmldoc.getElementsByTagName(content)
+
+ # If no element has been found, we directly can return None.
+ if not element:
+ return None
+
+ # Only get the first child from an element, even there are more than one.
+ firstchild = element[0].firstChild
+
+ # Get the value of the child.
+ value = firstchild.nodeValue
+
+ # Return the value.
+ return value