diff --git a/libcloud/common/liquidweb.py b/libcloud/common/liquidweb.py index fb12e587ec..123e82fe44 100644 --- a/libcloud/common/liquidweb.py +++ b/libcloud/common/liquidweb.py @@ -18,7 +18,6 @@ from libcloud.common.base import JsonResponse from libcloud.common.base import ConnectionUserAndKey from libcloud.utils.py3 import b -from libcloud.utils.py3 import PY3 from libcloud.common.types import ProviderError @@ -165,29 +164,15 @@ class LiquidWebResponse(JsonResponse): error_dict = {} def __init__(self, response, connection): - self.connection = connection - - self.headers = dict(response.getheaders()) - self.error = response.reason - self.status = response.status - - # This attribute is used when usng LoggingConnection - original_data = getattr(response, '_original_data', None) - - if original_data: - self.body = response._original_data - else: - self.body = self._decompress_response(body=response.read(), - headers=self.headers) - - if PY3: - self.body = b(self.body).decode('utf-8') - self.objects, self.errors = self.parse_body() - if not self.success(): + self.errors = [] + super(LiquidWebResponse, self).__init__(response=response, + connection=connection) + self.objects, self.errors = self.parse_body_and_errors() + if self.errors: error = self.errors.pop() raise self._make_excp(error, self.status) - def parse_body(self): + def parse_body_and_errors(self): data = [] errors = [] js = super(LiquidWebResponse, self).parse_body() diff --git a/libcloud/common/vultr.py b/libcloud/common/vultr.py index 37bc76e5d8..aa57105c42 100644 --- a/libcloud/common/vultr.py +++ b/libcloud/common/vultr.py @@ -1,6 +1,4 @@ from libcloud.common.base import ConnectionKey, JsonResponse -from libcloud.utils.misc import lowercase_keys -from libcloud.utils.py3 import PY3, b __all__ = [ @@ -36,28 +34,14 @@ class VultrResponse(JsonResponse): def __init__(self, response, connection): - self.connection = connection - self.error = response.reason - self.status = response.status - self.headers = lowercase_keys(dict(response.getheaders())) - - original_data = getattr(response, '_original_data', None) - - if original_data: - self.body = response._original_data - - else: - self.body = self._decompress_response(body=response.read(), - headers=self.headers) - - if PY3: - self.body = b(self.body).decode('utf-8') - - self.objects, self.errors = self.parse_body() + self.errors = [] + super(VultrResponse, self).__init__(response=response, + connection=connection) + self.objects, self.errors = self.parse_body_and_errors() if not self.success(): raise self._make_excp(self.errors[0]) - def parse_body(self): + def parse_body_and_errors(self): """ Returns JSON data in a python list. """ diff --git a/libcloud/common/zonomi.py b/libcloud/common/zonomi.py index 6619b103b3..3ef913d262 100644 --- a/libcloud/common/zonomi.py +++ b/libcloud/common/zonomi.py @@ -14,7 +14,6 @@ from libcloud.common.base import XmlResponse from libcloud.common.base import ConnectionKey -from libcloud.utils.py3 import b, PY3 __all__ = [ @@ -51,25 +50,14 @@ class ZonomiResponse(XmlResponse): objects = None def __init__(self, response, connection): - self.connection = connection - self.headers = dict(response.getheaders()) - self.error = response.reason - self.status = response.status - - # This attribute is used when using LoggingConnection - original_data = getattr(response, '_original_data', None) - if original_data: - self.body = response._original_data - else: - self.body = self._decompress_response(body=response.read(), - headers=self.headers) - if PY3: - self.body = b(self.body).decode('utf-8') - self.objects, self.errors = self.parse_body() + self.errors = [] + super(ZonomiResponse, self).__init__(response=response, + connection=connection) + self.objects, self.errors = self.parse_body_and_errors() if self.errors: raise self._make_excp(self.errors[0]) - def parse_body(self): + def parse_body_and_errors(self): error_dict = {} actions = None result_counts = None @@ -116,8 +104,8 @@ def parse_body(self): return (data, errors) - # def success(self): - # return (len(self.errors) == 0) + def success(self): + return (len(self.errors) == 0) def _make_excp(self, error): """ diff --git a/libcloud/dns/drivers/vultr.py b/libcloud/dns/drivers/vultr.py index 04f7604f1e..3b66d9f046 100644 --- a/libcloud/dns/drivers/vultr.py +++ b/libcloud/dns/drivers/vultr.py @@ -73,9 +73,9 @@ def list_zones(self): """ action = '/v1/dns/list' params = {'api_key': self.key} - response, errors = self.connection.request(action=action, - params=params).parse_body() - zones = self._to_zones(response[0]) + response = self.connection.request(action=action, + params=params) + zones = self._to_zones(response.objects[0]) return zones @@ -99,9 +99,9 @@ def list_records(self, zone): action = '/v1/dns/records' params = {'domain': zone.domain} - response, errors = self.connection.request(action=action, - params=params).parse_body() - records = self._to_records(response[0], zone=zone) + response = self.connection.request(action=action, + params=params) + records = self._to_records(response.objects[0], zone=zone) return records @@ -118,9 +118,9 @@ def get_zone(self, zone_id): action = '/v1/dns/list' params = {'api_key': self.key} - response, errors = self.connection.request(action=action, - params=params).parse_body() - zones = self._to_zones(response[0]) + response = self.connection.request(action=action, + params=params) + zones = self._to_zones(response.objects[0]) if not self.ex_zone_exists(zone_id, zones): raise ZoneDoesNotExistError(value=None, zone_id=zone_id, @@ -247,10 +247,8 @@ def create_record(self, name, zone, type, data, extra=None): params = {'api_key': self.key} action = '/v1/dns/create_record' - response, errors = self.connection.request(action=action, - params=params, - data=encoded_data, - method='POST').parse_body() + self.connection.request(action=action, params=params, + data=encoded_data, method='POST') updated_zone_records = zone.list_records() for record in updated_zone_records: diff --git a/libcloud/dns/drivers/worldwidedns.py b/libcloud/dns/drivers/worldwidedns.py index f387dc5ebb..50022a0e5b 100644 --- a/libcloud/dns/drivers/worldwidedns.py +++ b/libcloud/dns/drivers/worldwidedns.py @@ -71,7 +71,7 @@ def __init__(self, key, secret=None, reseller_id=None, secure=True, :type reseller_id: ``str`` :param secure: Weither to use HTTPS or HTTP. Note: Some providers - only support HTTPS, and it is on by default. + only support HTTPS, and it is on by default. :type secure: ``bool`` :param host: Override hostname used for connections. @@ -180,10 +180,11 @@ def update_zone(self, zone, domain, type='master', ttl=None, extra=None, :type ttl: ``int`` :param extra: Extra attributes (driver specific) (optional). Values not - specified such as *SECURE*, *IP*, *FOLDER*, *HOSTMASTER*, *REFRESH*, - *RETRY* and *EXPIRE* will be kept as already is. The same will be for - *S(1 to 40)*, *T(1 to 40)* and *D(1 to 40)* if not in raw mode and - for *ZONENS* and *ZONEDATA* if it is. + specified such as *SECURE*, *IP*, *FOLDER*, *HOSTMASTER*, + *REFRESH*, *RETRY* and *EXPIRE* will be kept as already + is. The same will be for *S(1 to 40)*, *T(1 to 40)* and + *D(1 to 40)* if not in raw mode and for *ZONENS* and + *ZONEDATA* if it is. :type extra: ``dict`` :param ex_raw: Mode we use to do the update using zone file or not. @@ -283,8 +284,8 @@ def create_zone(self, domain, type='master', ttl=None, extra=None): :type ttl: ``int`` :param extra: Extra attributes (driver specific). (optional). Possible - parameter in here should be *DYN* which values should be 1 for standart - and 2 for dynamic. Default is 1. + parameter in here should be *DYN* which values should be + 1 for standart and 2 for dynamic. Default is 1. :type extra: ``dict`` :rtype: :class:`Zone`