Skip to content

Commit b26cb5b

Browse files
committed
Upgraded to PEP8 1.3.3 to stay aligned with Nova, etc.
Made all the necessary changes to pass new PEP8 standards. Also cleaned up docstrings to conform to the HACKING stanards. Change-Id: Ib8df3030da7a7885655689ab5da0717748c9edbe
1 parent aa4f12a commit b26cb5b

21 files changed

Lines changed: 325 additions & 522 deletions

openstackclient/common/clientmanager.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@
1313
# under the License.
1414
#
1515

16-
"""Manage access to the clients, including authenticating when needed.
17-
"""
16+
"""Manage access to the clients, including authenticating when needed."""
1817

1918
import logging
2019

2120
from openstackclient.compute import client as compute_client
2221
from openstackclient.identity import client as identity_client
2322
from openstackclient.image import client as image_client
2423

24+
2525
LOG = logging.getLogger(__name__)
2626

2727

2828
class ClientCache(object):
29-
"""Descriptor class for caching created client handles.
30-
"""
31-
29+
"""Descriptor class for caching created client handles."""
3230
def __init__(self, factory):
3331
self.factory = factory
3432
self._handle = None
@@ -41,20 +39,14 @@ def __get__(self, instance, owner):
4139

4240

4341
class ClientManager(object):
44-
"""Manages access to API clients, including authentication.
45-
"""
46-
42+
"""Manages access to API clients, including authentication."""
4743
compute = ClientCache(compute_client.make_client)
4844
identity = ClientCache(identity_client.make_client)
4945
image = ClientCache(image_client.make_client)
5046

51-
def __init__(self, token=None, url=None,
52-
auth_url=None,
53-
tenant_name=None, tenant_id=None,
54-
username=None, password=None,
55-
region_name=None,
56-
api_version=None,
57-
):
47+
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
48+
tenant_id=None, username=None, password=None,
49+
region_name=None, api_version=None):
5850
self._token = token
5951
self._url = url
6052
self._auth_url = auth_url
@@ -74,8 +66,7 @@ def __init__(self, token=None, url=None,
7466
return
7567

7668
def get_endpoint_for_service_type(self, service_type):
77-
"""Return the endpoint URL for the service type.
78-
"""
69+
"""Return the endpoint URL for the service type."""
7970
# See if we are using password flow auth, i.e. we have a
8071
# service catalog to select endpoints from
8172
if self._service_catalog:

openstackclient/common/command.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
# under the License.
1414
#
1515

16-
"""
17-
OpenStack base command
18-
"""
16+
"""OpenStack base command"""
1917

2018
from cliff.command import Command
2119

2220

2321
class OpenStackCommand(Command):
24-
"""Base class for OpenStack commands
25-
"""
26-
22+
"""Base class for OpenStack commands."""
2723
api = None
2824

2925
def run(self, parsed_args):

openstackclient/common/exceptions.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# under the License.
1414
#
1515

16-
"""
17-
Exception definitions.
18-
"""
16+
"""Exception definitions."""
1917

2018

2119
class CommandError(Exception):
@@ -27,8 +25,7 @@ class AuthorizationFailure(Exception):
2725

2826

2927
class NoTokenLookupException(Exception):
30-
"""This form of authentication does not support looking up
31-
endpoints from an existing token."""
28+
"""This does not support looking up endpoints from an existing token."""
3229
pass
3330

3431

@@ -38,15 +35,12 @@ class EndpointNotFound(Exception):
3835

3936

4037
class UnsupportedVersion(Exception):
41-
"""Indicates that the user is trying to use an unsupported
42-
version of the API"""
38+
"""The user is trying to use an unsupported version of the API"""
4339
pass
4440

4541

4642
class ClientException(Exception):
47-
"""
48-
The base exception class for all exceptions this library raises.
49-
"""
43+
"""The base exception class for all exceptions this library raises."""
5044
def __init__(self, code, message=None, details=None):
5145
self.code = code
5246
self.message = message or self.__class__.message
@@ -57,59 +51,44 @@ def __str__(self):
5751

5852

5953
class BadRequest(ClientException):
60-
"""
61-
HTTP 400 - Bad request: you sent some malformed data.
62-
"""
54+
"""HTTP 400 - Bad request: you sent some malformed data."""
6355
http_status = 400
6456
message = "Bad request"
6557

6658

6759
class Unauthorized(ClientException):
68-
"""
69-
HTTP 401 - Unauthorized: bad credentials.
70-
"""
60+
"""HTTP 401 - Unauthorized: bad credentials."""
7161
http_status = 401
7262
message = "Unauthorized"
7363

7464

7565
class Forbidden(ClientException):
76-
"""
77-
HTTP 403 - Forbidden: your credentials don't give you access to this
78-
resource.
79-
"""
66+
"""HTTP 403 - Forbidden: not authorized to access to this resource."""
8067
http_status = 403
8168
message = "Forbidden"
8269

8370

8471
class NotFound(ClientException):
85-
"""
86-
HTTP 404 - Not found
87-
"""
72+
"""HTTP 404 - Not found"""
8873
http_status = 404
8974
message = "Not found"
9075

9176

9277
class Conflict(ClientException):
93-
"""
94-
HTTP 409 - Conflict
95-
"""
78+
"""HTTP 409 - Conflict"""
9679
http_status = 409
9780
message = "Conflict"
9881

9982

10083
class OverLimit(ClientException):
101-
"""
102-
HTTP 413 - Over limit: you're over the API limits for this time period.
103-
"""
84+
"""HTTP 413 - Over limit: reached the API limits for this time period."""
10485
http_status = 413
10586
message = "Over limit"
10687

10788

10889
# NotImplemented is a python keyword.
10990
class HTTPNotImplemented(ClientException):
110-
"""
111-
HTTP 501 - Not Implemented: the server does not support this operation.
112-
"""
91+
"""HTTP 501 - Not Implemented: server does not support this operation."""
11392
http_status = 501
11493
message = "Not Implemented"
11594

@@ -120,14 +99,18 @@ class HTTPNotImplemented(ClientException):
12099
# for c in ClientException.__subclasses__())
121100
#
122101
# Instead, we have to hardcode it:
123-
_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized,
124-
Forbidden, NotFound, OverLimit, HTTPNotImplemented])
102+
_code_map = dict((c.http_status, c) for c in [
103+
BadRequest,
104+
Unauthorized,
105+
Forbidden,
106+
NotFound,
107+
OverLimit,
108+
HTTPNotImplemented
109+
])
125110

126111

127112
def from_response(response, body):
128-
"""
129-
Return an instance of a ClientException or subclass
130-
based on an httplib2 response.
113+
"""Return an instance of a ClientException based on an httplib2 response.
131114
132115
Usage::
133116

openstackclient/common/openstackkeyring.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,48 @@
1313
# under the License.
1414
#
1515

16-
"""
17-
Keyring backend for Openstack, to store encrypted password in a file.
18-
"""
16+
"""Keyring backend for Openstack, to store encrypted password in a file."""
1917

2018
from Crypto.Cipher import AES
2119

2220
import keyring
2321
import os
2422

23+
2524
KEYRING_FILE = os.path.join(os.path.expanduser('~'), '.openstack-keyring.cfg')
2625

2726

2827
class OpenstackKeyring(keyring.backend.BasicFileKeyring):
29-
""" Openstack Keyring to store encrypted password """
30-
28+
"""Openstack Keyring to store encrypted password."""
3129
filename = KEYRING_FILE
3230

3331
def supported(self):
34-
""" applicable for all platforms, but not recommend """
32+
"""Applicable for all platforms, but not recommend."""
3533
pass
3634

3735
def _init_crypter(self):
38-
""" initialize the crypter using the class name """
36+
"""Initialize the crypter using the class name."""
3937
block_size = 32
4038
padding = '0'
4139

4240
# init the cipher with the class name, upto block_size
4341
password = __name__[block_size:]
44-
password = password + (block_size - len(password) % \
45-
block_size) * padding
42+
password = password + (block_size - len(password) %
43+
block_size) * padding
4644
return AES.new(password, AES.MODE_CFB)
4745

4846
def encrypt(self, password):
49-
""" encrypt the given password """
47+
"""Encrypt the given password."""
5048
crypter = self._init_crypter()
5149
return crypter.encrypt(password)
5250

5351
def decrypt(self, password_encrypted):
54-
""" decrypt the given password """
52+
"""Decrypt the given password."""
5553
crypter = self._init_crypter()
5654
return crypter.decrypt(password_encrypted)
5755

5856

5957
def os_keyring():
60-
""" initialize the openstack keyring """
61-
return keyring.core.load_keyring(None,
62-
'openstackclient.common.openstackkeyring.OpenstackKeyring')
58+
"""Initialize the openstack keyring."""
59+
keyring = 'openstackclient.common.openstackkeyring.OpenstackKeyring'
60+
return keyring.core.load_keyring(None, keyring)

openstackclient/common/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# under the License.
1414
#
1515

16-
"""
17-
Common client utilities
18-
"""
16+
"""Common client utilities"""
1917

2018
import os
2119
import sys

openstackclient/compute/client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727

2828

2929
def make_client(instance):
30-
"""Returns a compute service client.
31-
"""
30+
"""Returns a compute service client."""
3231
compute_client = utils.get_client_class(
3332
API_NAME,
3433
instance._api_version[API_NAME],
35-
API_VERSIONS,
36-
)
34+
API_VERSIONS)
3735
LOG.debug('instantiating compute client: %s' % compute_client)
3836
client = compute_client(
3937
username=instance._username,
@@ -49,8 +47,7 @@ def make_client(instance):
4947
extensions=[],
5048
service_type=API_NAME,
5149
# FIXME(dhellmann): what is service_name?
52-
service_name='',
53-
)
50+
service_name='')
5451

5552
# Populate the Nova client to skip another auth query to Identity
5653
if instance._url:

0 commit comments

Comments
 (0)