diff options
| author | Josh Kearney <josh@jk0.org> | 2013-01-31 13:31:41 -0600 |
|---|---|---|
| committer | Josh Kearney <josh@jk0.org> | 2013-01-31 13:31:41 -0600 |
| commit | b26cb5bf683e7f4f03d9704524a188b76ac5e9b9 (patch) | |
| tree | f059ddb3b7e15f50d722cf1fbd2b0eaf8242b1a4 /openstackclient/common | |
| parent | aa4f12aec1d13d02df2ecc2710d85ebd90d6dfe7 (diff) | |
| download | python-openstackclient-b26cb5bf683e7f4f03d9704524a188b76ac5e9b9.tar.gz | |
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
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/clientmanager.py | 25 | ||||
| -rw-r--r-- | openstackclient/common/command.py | 8 | ||||
| -rw-r--r-- | openstackclient/common/exceptions.py | 57 | ||||
| -rw-r--r-- | openstackclient/common/openstackkeyring.py | 26 | ||||
| -rw-r--r-- | openstackclient/common/utils.py | 4 |
5 files changed, 43 insertions, 77 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index f6f6642e..830ecde7 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -13,8 +13,7 @@ # under the License. # -"""Manage access to the clients, including authenticating when needed. -""" +"""Manage access to the clients, including authenticating when needed.""" import logging @@ -22,13 +21,12 @@ from openstackclient.compute import client as compute_client from openstackclient.identity import client as identity_client from openstackclient.image import client as image_client + LOG = logging.getLogger(__name__) class ClientCache(object): - """Descriptor class for caching created client handles. - """ - + """Descriptor class for caching created client handles.""" def __init__(self, factory): self.factory = factory self._handle = None @@ -41,20 +39,14 @@ class ClientCache(object): class ClientManager(object): - """Manages access to API clients, including authentication. - """ - + """Manages access to API clients, including authentication.""" compute = ClientCache(compute_client.make_client) identity = ClientCache(identity_client.make_client) image = ClientCache(image_client.make_client) - def __init__(self, token=None, url=None, - auth_url=None, - tenant_name=None, tenant_id=None, - username=None, password=None, - region_name=None, - api_version=None, - ): + def __init__(self, token=None, url=None, auth_url=None, tenant_name=None, + tenant_id=None, username=None, password=None, + region_name=None, api_version=None): self._token = token self._url = url self._auth_url = auth_url @@ -74,8 +66,7 @@ class ClientManager(object): return def get_endpoint_for_service_type(self, service_type): - """Return the endpoint URL for the service type. - """ + """Return the endpoint URL for the service type.""" # See if we are using password flow auth, i.e. we have a # service catalog to select endpoints from if self._service_catalog: diff --git a/openstackclient/common/command.py b/openstackclient/common/command.py index cfcb605c..64e855df 100644 --- a/openstackclient/common/command.py +++ b/openstackclient/common/command.py @@ -13,17 +13,13 @@ # under the License. # -""" -OpenStack base command -""" +"""OpenStack base command""" from cliff.command import Command class OpenStackCommand(Command): - """Base class for OpenStack commands - """ - + """Base class for OpenStack commands.""" api = None def run(self, parsed_args): diff --git a/openstackclient/common/exceptions.py b/openstackclient/common/exceptions.py index 9dfb4bc7..ab043db0 100644 --- a/openstackclient/common/exceptions.py +++ b/openstackclient/common/exceptions.py @@ -13,9 +13,7 @@ # under the License. # -""" -Exception definitions. -""" +"""Exception definitions.""" class CommandError(Exception): @@ -27,8 +25,7 @@ class AuthorizationFailure(Exception): class NoTokenLookupException(Exception): - """This form of authentication does not support looking up - endpoints from an existing token.""" + """This does not support looking up endpoints from an existing token.""" pass @@ -38,15 +35,12 @@ class EndpointNotFound(Exception): class UnsupportedVersion(Exception): - """Indicates that the user is trying to use an unsupported - version of the API""" + """The user is trying to use an unsupported version of the API""" pass class ClientException(Exception): - """ - The base exception class for all exceptions this library raises. - """ + """The base exception class for all exceptions this library raises.""" def __init__(self, code, message=None, details=None): self.code = code self.message = message or self.__class__.message @@ -57,59 +51,44 @@ class ClientException(Exception): class BadRequest(ClientException): - """ - HTTP 400 - Bad request: you sent some malformed data. - """ + """HTTP 400 - Bad request: you sent some malformed data.""" http_status = 400 message = "Bad request" class Unauthorized(ClientException): - """ - HTTP 401 - Unauthorized: bad credentials. - """ + """HTTP 401 - Unauthorized: bad credentials.""" http_status = 401 message = "Unauthorized" class Forbidden(ClientException): - """ - HTTP 403 - Forbidden: your credentials don't give you access to this - resource. - """ + """HTTP 403 - Forbidden: not authorized to access to this resource.""" http_status = 403 message = "Forbidden" class NotFound(ClientException): - """ - HTTP 404 - Not found - """ + """HTTP 404 - Not found""" http_status = 404 message = "Not found" class Conflict(ClientException): - """ - HTTP 409 - Conflict - """ + """HTTP 409 - Conflict""" http_status = 409 message = "Conflict" class OverLimit(ClientException): - """ - HTTP 413 - Over limit: you're over the API limits for this time period. - """ + """HTTP 413 - Over limit: reached the API limits for this time period.""" http_status = 413 message = "Over limit" # NotImplemented is a python keyword. class HTTPNotImplemented(ClientException): - """ - HTTP 501 - Not Implemented: the server does not support this operation. - """ + """HTTP 501 - Not Implemented: server does not support this operation.""" http_status = 501 message = "Not Implemented" @@ -120,14 +99,18 @@ class HTTPNotImplemented(ClientException): # for c in ClientException.__subclasses__()) # # Instead, we have to hardcode it: -_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized, - Forbidden, NotFound, OverLimit, HTTPNotImplemented]) +_code_map = dict((c.http_status, c) for c in [ + BadRequest, + Unauthorized, + Forbidden, + NotFound, + OverLimit, + HTTPNotImplemented +]) def from_response(response, body): - """ - Return an instance of a ClientException or subclass - based on an httplib2 response. + """Return an instance of a ClientException based on an httplib2 response. Usage:: diff --git a/openstackclient/common/openstackkeyring.py b/openstackclient/common/openstackkeyring.py index 78c74b8f..e7431e54 100644 --- a/openstackclient/common/openstackkeyring.py +++ b/openstackclient/common/openstackkeyring.py @@ -13,50 +13,48 @@ # under the License. # -""" -Keyring backend for Openstack, to store encrypted password in a file. -""" +"""Keyring backend for Openstack, to store encrypted password in a file.""" from Crypto.Cipher import AES import keyring import os + KEYRING_FILE = os.path.join(os.path.expanduser('~'), '.openstack-keyring.cfg') class OpenstackKeyring(keyring.backend.BasicFileKeyring): - """ Openstack Keyring to store encrypted password """ - + """Openstack Keyring to store encrypted password.""" filename = KEYRING_FILE def supported(self): - """ applicable for all platforms, but not recommend """ + """Applicable for all platforms, but not recommend.""" pass def _init_crypter(self): - """ initialize the crypter using the class name """ + """Initialize the crypter using the class name.""" block_size = 32 padding = '0' # init the cipher with the class name, upto block_size password = __name__[block_size:] - password = password + (block_size - len(password) % \ - block_size) * padding + password = password + (block_size - len(password) % + block_size) * padding return AES.new(password, AES.MODE_CFB) def encrypt(self, password): - """ encrypt the given password """ + """Encrypt the given password.""" crypter = self._init_crypter() return crypter.encrypt(password) def decrypt(self, password_encrypted): - """ decrypt the given password """ + """Decrypt the given password.""" crypter = self._init_crypter() return crypter.decrypt(password_encrypted) def os_keyring(): - """ initialize the openstack keyring """ - return keyring.core.load_keyring(None, - 'openstackclient.common.openstackkeyring.OpenstackKeyring') + """Initialize the openstack keyring.""" + keyring = 'openstackclient.common.openstackkeyring.OpenstackKeyring' + return keyring.core.load_keyring(None, keyring) diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 19cca3f5..6477285e 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -13,9 +13,7 @@ # under the License. # -""" -Common client utilities -""" +"""Common client utilities""" import os import sys |
