From a6f81a736c503e45e1fca9fe49f9f46b9ced7cb8 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 8 May 2023 11:36:34 +0100 Subject: Blacken openstackclient.api Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: I1df5bc4c35f02147fe5ac5b4073f0e01e7d51c2f Signed-off-by: Stephen Finucane --- openstackclient/api/api.py | 57 +++++--------------------- openstackclient/api/compute_v2.py | 9 ++--- openstackclient/api/image_v1.py | 6 +-- openstackclient/api/object_store_v1.py | 73 +++++++++++++++++++--------------- 4 files changed, 53 insertions(+), 92 deletions(-) (limited to 'openstackclient/api') diff --git a/openstackclient/api/api.py b/openstackclient/api/api.py index d4772f94..f02c87dc 100644 --- a/openstackclient/api/api.py +++ b/openstackclient/api/api.py @@ -30,12 +30,7 @@ class KeystoneSession(object): """ - def __init__( - self, - session=None, - endpoint=None, - **kwargs - ): + def __init__(self, session=None, endpoint=None, **kwargs): """Base object that contains some common API objects and methods :param Session session: @@ -87,11 +82,7 @@ class BaseAPI(KeystoneSession): """Base API""" def __init__( - self, - session=None, - service_type=None, - endpoint=None, - **kwargs + self, session=None, service_type=None, endpoint=None, **kwargs ): """Base object that contains some common API objects and methods @@ -110,13 +101,7 @@ class BaseAPI(KeystoneSession): # The basic action methods all take a Session and return dict/lists - def create( - self, - url, - session=None, - method=None, - **params - ): + def create(self, url, session=None, method=None, **params): """Create a new resource :param string url: @@ -136,12 +121,7 @@ class BaseAPI(KeystoneSession): except json.JSONDecodeError: return ret - def delete( - self, - url, - session=None, - **params - ): + def delete(self, url, session=None, **params): """Delete a resource :param string url: @@ -152,14 +132,7 @@ class BaseAPI(KeystoneSession): return self._request('DELETE', url, **params) - def list( - self, - path, - session=None, - body=None, - detailed=False, - **params - ): + def list(self, path, session=None, body=None, detailed=False, **params): """Return a list of resources GET ${ENDPOINT}/${PATH}?${PARAMS} @@ -255,9 +228,7 @@ class BaseAPI(KeystoneSession): if len(data) > 1: msg = _("Multiple %(resource)s exist with %(attr)s='%(value)s'") raise exceptions.CommandError( - msg % {'resource': resource, - 'attr': attr, - 'value': value} + msg % {'resource': resource, 'attr': attr, 'value': value} ) # Search by id @@ -267,16 +238,10 @@ class BaseAPI(KeystoneSession): return data[0] msg = _("No %(resource)s with a %(attr)s or ID of '%(value)s' found") raise exceptions.CommandError( - msg % {'resource': resource, - 'attr': attr, - 'value': value} + msg % {'resource': resource, 'attr': attr, 'value': value} ) - def find_bulk( - self, - path, - **kwargs - ): + def find_bulk(self, path, **kwargs): """Bulk load and filter locally :param string path: @@ -302,11 +267,7 @@ class BaseAPI(KeystoneSession): return ret - def find_one( - self, - path, - **kwargs - ): + def find_one(self, path, **kwargs): """Find a resource by name or ID :param string path: diff --git a/openstackclient/api/compute_v2.py b/openstackclient/api/compute_v2.py index e30177a2..aa0554b1 100644 --- a/openstackclient/api/compute_v2.py +++ b/openstackclient/api/compute_v2.py @@ -22,6 +22,7 @@ from osc_lib.i18n import _ # TODO(dtroyer): Mingrate this to osc-lib class InvalidValue(Exception): """An argument value is not valid: wrong type, out of range, etc""" + message = "Supplied value is not valid" @@ -291,11 +292,7 @@ class APIv2(api.BaseAPI): return self.list(url)["hosts"] def host_set( - self, - host=None, - status=None, - maintenance_mode=None, - **params + self, host=None, status=None, maintenance_mode=None, **params ): """Modify host properties @@ -576,7 +573,7 @@ class APIv2(api.BaseAPI): value=security_group, ) if security_group is not None: - for (k, v) in params.items(): + for k, v in params.items(): # Only set a value if it is already present if k in security_group: security_group[k] = v diff --git a/openstackclient/api/image_v1.py b/openstackclient/api/image_v1.py index e15d825a..1bd15069 100644 --- a/openstackclient/api/image_v1.py +++ b/openstackclient/api/image_v1.py @@ -33,11 +33,7 @@ class APIv1(api.BaseAPI): self.endpoint = self.endpoint + self._endpoint_suffix def image_list( - self, - detailed=False, - public=False, - private=False, - **filter + self, detailed=False, public=False, private=False, **filter ): """Get available images diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index 67c79230..ac40cf6c 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -36,10 +36,7 @@ class APIv1(api.BaseAPI): super(APIv1, self).__init__(**kwargs) def container_create( - self, - container=None, - public=False, - storage_policy=None + self, container=None, public=False, storage_policy=None ): """Create a container @@ -62,7 +59,8 @@ class APIv1(api.BaseAPI): headers['x-storage-policy'] = storage_policy response = self.create( - urllib.parse.quote(container), method='PUT', headers=headers) + urllib.parse.quote(container), method='PUT', headers=headers + ) data = { 'account': self._find_account_id(), @@ -192,9 +190,7 @@ class APIv1(api.BaseAPI): data = { 'account': self._find_account_id(), 'container': container, - 'object_count': response.headers.get( - 'x-container-object-count' - ), + 'object_count': response.headers.get('x-container-object-count'), 'bytes_used': response.headers.get('x-container-bytes-used'), 'storage_policy': response.headers.get('x-storage-policy'), } @@ -208,8 +204,9 @@ class APIv1(api.BaseAPI): if 'x-container-sync-key' in response.headers: data['sync_key'] = response.headers.get('x-container-sync-key') - properties = self._get_properties(response.headers, - 'x-container-meta-') + properties = self._get_properties( + response.headers, 'x-container-meta-' + ) if properties: data['properties'] = properties @@ -228,8 +225,9 @@ class APIv1(api.BaseAPI): properties to remove from the container """ - headers = self._unset_properties(properties, - 'X-Remove-Container-Meta-%s') + headers = self._unset_properties( + properties, 'X-Remove-Container-Meta-%s' + ) if headers: self.create(urllib.parse.quote(container), headers=headers) @@ -259,8 +257,10 @@ class APIv1(api.BaseAPI): # object's name in the container. object_name_str = name if name else object - full_url = "%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object_name_str)) + full_url = "%s/%s" % ( + urllib.parse.quote(container), + urllib.parse.quote(object_name_str), + ) with io.open(object, 'rb') as f: response = self.create( full_url, @@ -293,8 +293,10 @@ class APIv1(api.BaseAPI): if container is None or object is None: return - self.delete("%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object))) + self.delete( + "%s/%s" + % (urllib.parse.quote(container), urllib.parse.quote(object)) + ) def object_list( self, @@ -394,8 +396,8 @@ class APIv1(api.BaseAPI): response = self._request( 'GET', - "%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object)), + "%s/%s" + % (urllib.parse.quote(container), urllib.parse.quote(object)), stream=True, ) if response.status_code == 200: @@ -429,9 +431,11 @@ class APIv1(api.BaseAPI): headers = self._set_properties(properties, 'X-Object-Meta-%s') if headers: - self.create("%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object)), - headers=headers) + self.create( + "%s/%s" + % (urllib.parse.quote(container), urllib.parse.quote(object)), + headers=headers, + ) def object_unset( self, @@ -451,9 +455,11 @@ class APIv1(api.BaseAPI): headers = self._unset_properties(properties, 'X-Remove-Object-Meta-%s') if headers: - self.create("%s/%s" % (urllib.parse.quote(container), - urllib.parse.quote(object)), - headers=headers) + self.create( + "%s/%s" + % (urllib.parse.quote(container), urllib.parse.quote(object)), + headers=headers, + ) def object_show( self, @@ -473,9 +479,11 @@ class APIv1(api.BaseAPI): if container is None or object is None: return {} - response = self._request('HEAD', "%s/%s" % - (urllib.parse.quote(container), - urllib.parse.quote(object))) + response = self._request( + 'HEAD', + "%s/%s" + % (urllib.parse.quote(container), urllib.parse.quote(object)), + ) data = { 'account': self._find_account_id(), @@ -484,9 +492,7 @@ class APIv1(api.BaseAPI): 'content-type': response.headers.get('content-type'), } if 'content-length' in response.headers: - data['content-length'] = response.headers.get( - 'content-length' - ) + data['content-length'] = response.headers.get('content-length') if 'last-modified' in response.headers: data['last-modified'] = response.headers.get('last-modified') if 'etag' in response.headers: @@ -549,8 +555,9 @@ class APIv1(api.BaseAPI): properties to remove from the account """ - headers = self._unset_properties(properties, - 'X-Remove-Account-Meta-%s') + headers = self._unset_properties( + properties, 'X-Remove-Account-Meta-%s' + ) if headers: self.create("", headers=headers) @@ -596,5 +603,5 @@ class APIv1(api.BaseAPI): properties = {} for k, v in headers.items(): if k.lower().startswith(header_tag): - properties[k[len(header_tag):]] = v + properties[k[len(header_tag) :]] = v return properties -- cgit v1.2.1