def __init__(self, packet, server='localhost', port='8443', user='******', password='******', key=None, timeout=240): """Represents the data that is going to be sent to the Plesk Panel endpoint. :param packet: The packet for sending to the Plesk Panel endpoint. Allowed values: dict, xml.etree.ElementTree.Element or an XML string (without headers). :param server: The server IP Address or uri. Default: localhost. :param port: The port of the Plesk Panel. Default: 8443. :param user: The credentials of the Plesk Panel. Default: admin. :param password: The password of the user. Default: setup. :param key: (optional) Use a secret key instead of username and password. :param timeout: The timeout of the request. Default: 240. """ self.server = server self.port = port if isinstance(packet, dict): warnings.warn("Missing OrderedDict package. Dict's are not ordered, elements SHOULD be in order or the request may fail.", ImportWarning) self.packetxml = dict2xml(packet) elif isinstance(packet, type(xmlobj)): self.packetxml = elem2xml(packet) elif isinstance(packet, str): self.packetxml = packet else: raise TypeError('Unrecognized packet type: %s' %type(packet)) if key: self.headers = { 'KEY': key } else: self.headers = { 'HTTP_AUTH_LOGIN': user, 'HTTP_AUTH_PASSWD': password } self.headers.update({'Content-Type': 'text/xml'}) self.timeout = timeout
def __init__(self, packet, server='localhost', port='8443', user='******', password='******', key=None, timeout=240): """Represents the data that is going to be sent to the Plesk Panel endpoint. :param packet: The packet for sending to the Plesk Panel endpoint. Allowed values: dict, xml.etree.ElementTree.Element or an XML string (without headers). :param server: The server IP Address or uri. Default: localhost. :param port: The port of the Plesk Panel. Default: 8443. :param user: The credentials of the Plesk Panel. Default: admin. :param password: The password of the user. Default: setup. :param key: (optional) Use a secret key instead of username and password. :param timeout: The timeout of the request. Default: 240. """ self.server = server self.port = port if isinstance(packet, dict): warnings.warn( "Missing OrderedDict package. Dict's are not ordered, elements SHOULD be in order or the request may fail.", ImportWarning) self.packetxml = dict2xml(packet) elif isinstance(packet, type(xmlobj)): self.packetxml = elem2xml(packet) elif isinstance(packet, str): self.packetxml = packet else: raise TypeError('Unrecognized packet type: %s' % type(packet)) if key: self.headers = {'KEY': key} else: self.headers = { 'HTTP_AUTH_LOGIN': user, 'HTTP_AUTH_PASSWD': password } self.headers.update({'Content-Type': 'text/xml'}) self.timeout = timeout
def xml(self, prettify=False): """ Return the XML representation """ warnings.warn("Missing OrderedDict package. Dict's are not ordered, elements SHOULD be in order or the request may fail.", ImportWarning) return dict2xml(self.dict(), prettify)
def xml(self, prettify=False): """ Return the XML representation """ warnings.warn( "Missing OrderedDict package. Dict's are not ordered, elements SHOULD be in order or the request may fail.", ImportWarning) return dict2xml(self.dict(), prettify)