Skip to content

Commit

Permalink
Fix source code style to comply with PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
ktrushin authored and arp102 committed Mar 27, 2023
1 parent 155c050 commit 263cb34
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 40 deletions.
4 changes: 2 additions & 2 deletions kmip/core/messages/payloads/discover_versions.py
Expand Up @@ -40,7 +40,7 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
)
tstream = BytearrayStream(istream.read(self.length))

while(self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)):
while (self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)):
protocol_version = ProtocolVersion()
protocol_version.read(tstream, kmip_version=kmip_version)
self.protocol_versions.append(protocol_version)
Expand Down Expand Up @@ -99,7 +99,7 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
)
tstream = BytearrayStream(istream.read(self.length))

while(self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)):
while (self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)):
protocol_version = ProtocolVersion()
protocol_version.read(tstream, kmip_version=kmip_version)
self.protocol_versions.append(protocol_version)
Expand Down
28 changes: 16 additions & 12 deletions kmip/core/messages/payloads/query.py
Expand Up @@ -105,7 +105,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

query_functions = []
while(self.is_tag_next(enums.Tags.QUERY_FUNCTION, local_buffer)):
while (self.is_tag_next(enums.Tags.QUERY_FUNCTION, local_buffer)):
query_function = primitives.Enumeration(
enums.QueryFunction,
tag=enums.Tags.QUERY_FUNCTION
Expand Down Expand Up @@ -709,7 +709,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

operations = []
while(self.is_tag_next(enums.Tags.OPERATION, local_buffer)):
while (self.is_tag_next(enums.Tags.OPERATION, local_buffer)):
operation = primitives.Enumeration(
enums.Operation,
tag=enums.Tags.OPERATION
Expand All @@ -719,7 +719,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._operations = operations

object_types = []
while(self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer)):
while (self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer)):
object_type = primitives.Enumeration(
enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
Expand Down Expand Up @@ -747,7 +747,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._server_information = server_information

application_namespaces = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.APPLICATION_NAMESPACE,
local_buffer
)
Expand All @@ -761,7 +761,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):

if kmip_version >= enums.KMIPVersion.KMIP_1_1:
extensions_information = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.EXTENSION_INFORMATION,
local_buffer
)
Expand All @@ -776,7 +776,11 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):

if kmip_version >= enums.KMIPVersion.KMIP_1_2:
attestation_types = []
while(self.is_tag_next(enums.Tags.ATTESTATION_TYPE, local_buffer)):
while (self.is_tag_next(
enums.Tags.ATTESTATION_TYPE,
local_buffer
)
):
attestation_type = primitives.Enumeration(
enums.AttestationType,
tag=enums.Tags.ATTESTATION_TYPE
Expand All @@ -787,14 +791,14 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):

if kmip_version >= enums.KMIPVersion.KMIP_1_3:
rngs_parameters = []
while(self.is_tag_next(enums.Tags.RNG_PARAMETERS, local_buffer)):
while (self.is_tag_next(enums.Tags.RNG_PARAMETERS, local_buffer)):
rng_parameters = objects.RNGParameters()
rng_parameters.read(local_buffer, kmip_version=kmip_version)
rngs_parameters.append(rng_parameters)
self._rng_parameters = rngs_parameters

profiles_information = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.PROFILE_INFORMATION,
local_buffer
)
Expand All @@ -808,7 +812,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._profile_information = profiles_information

validations_information = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.VALIDATION_INFORMATION,
local_buffer
)
Expand All @@ -822,7 +826,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._validation_information = validations_information

capabilities_information = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.CAPABILITY_INFORMATION,
local_buffer
)
Expand All @@ -836,7 +840,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._capability_information = capabilities_information

client_registration_methods = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.CLIENT_REGISTRATION_METHOD,
local_buffer
)
Expand All @@ -862,7 +866,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
self._defaults_information = defaults_information

protection_storage_masks = []
while(self.is_tag_next(
while (self.is_tag_next(
enums.Tags.PROTECTION_STORAGE_MASK,
local_buffer
)
Expand Down
34 changes: 21 additions & 13 deletions kmip/pie/objects.py
Expand Up @@ -658,7 +658,8 @@ class SymmetricKey(Key):
}

def __init__(self, algorithm, length, value, masks=None,
name='Symmetric Key', key_wrapping_data=None, app_specific_info=None):
name='Symmetric Key', key_wrapping_data=None,
app_specific_info=None):
"""
Create a SymmetricKey.
Expand All @@ -674,8 +675,9 @@ def __init__(self, algorithm, length, value, masks=None,
key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing
application_namespace and application_data. Optional, defaults
to None.
"""
super(SymmetricKey, self).__init__(
key_wrapping_data=key_wrapping_data
Expand Down Expand Up @@ -826,7 +828,8 @@ class PublicKey(Key):

def __init__(self, algorithm, length, value,
format_type=enums.KeyFormatType.X_509, masks=None,
name='Public Key', key_wrapping_data=None, app_specific_info=None):
name='Public Key', key_wrapping_data=None,
app_specific_info=None):
"""
Create a PublicKey.
Expand All @@ -844,8 +847,9 @@ def __init__(self, algorithm, length, value,
key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing
application_namespace and application_data. Optional, defaults
to None.
"""
super(PublicKey, self).__init__(
key_wrapping_data=key_wrapping_data
Expand Down Expand Up @@ -996,7 +1000,8 @@ class PrivateKey(Key):
}

def __init__(self, algorithm, length, value, format_type, masks=None,
name='Private Key', key_wrapping_data=None, app_specific_info=None):
name='Private Key', key_wrapping_data=None,
app_specific_info=None):
"""
Create a PrivateKey.
Expand All @@ -1013,8 +1018,9 @@ def __init__(self, algorithm, length, value, format_type, masks=None,
key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing
application_namespace and application_data. Optional, defaults
to None.
"""
super(PrivateKey, self).__init__(
key_wrapping_data=key_wrapping_data
Expand Down Expand Up @@ -1595,7 +1601,8 @@ class SecretData(CryptographicObject):
'sqlite_autoincrement': True
}

def __init__(self, value, data_type, masks=None, name='Secret Data', app_specific_info=None):
def __init__(self, value, data_type, masks=None, name='Secret Data',
app_specific_info=None):
"""
Create a SecretData object.
Expand All @@ -1606,8 +1613,9 @@ def __init__(self, value, data_type, masks=None, name='Secret Data', app_specifi
masks(list): A list of CryptographicUsageMask enumerations
defining how the key will be used.
name(string): The string name of the key.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data.
Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing
application_namespace and application_data. Optional, defaults
to None.
"""
super(SecretData, self).__init__()

Expand All @@ -1616,7 +1624,7 @@ def __init__(self, value, data_type, masks=None, name='Secret Data', app_specifi
self.value = value
self.data_type = data_type
self.names = [name]

if app_specific_info:
self._application_specific_informations = app_specific_info

Expand Down
2 changes: 1 addition & 1 deletion kmip/services/server/crypto/engine.py
Expand Up @@ -274,7 +274,7 @@ def mac(self, algorithm, key, data):
c = cmac.CMAC(cipher_algorithm(key), backend=default_backend())
c.update(data)
mac_data = c.finalize()
except Exception as e:
except Exception:
raise exceptions.CryptographicFailure(
"An error occurred while computing a CMAC. "
"See the server log for more information."
Expand Down
2 changes: 1 addition & 1 deletion kmip/services/server/engine.py
Expand Up @@ -439,7 +439,7 @@ def _get_object_type(self, unique_identifier):
).filter(
objects.ManagedObject.unique_identifier == unique_identifier
).one()[0]
except exc.NoResultFound as e:
except exc.NoResultFound:
self._logger.warning(
"Could not identify object type for object: {0}".format(
unique_identifier
Expand Down
2 changes: 1 addition & 1 deletion kmip/services/server/session.py
Expand Up @@ -107,7 +107,7 @@ def run(self):
while True:
try:
self._handle_message_loop()
except exceptions.ConnectionClosed as e:
except exceptions.ConnectionClosed:
break
except Exception as e:
self._logger.info("Failure handling message loop")
Expand Down
17 changes: 10 additions & 7 deletions kmip/tests/integration/services/test_proxykmipclient.py
Expand Up @@ -103,7 +103,8 @@ def test_create_get_wrapped_destroy(self):
self.assertNotEqual(unwrapped_key.value, wrapped_key.value)

self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, wrapping_id)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE,
wrapping_id)
self.client.destroy(key_id)
self.client.destroy(wrapping_id)

Expand Down Expand Up @@ -184,11 +185,11 @@ def test_register_wrapped_get_destroy(self):
)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id)
self.client.destroy(key_id)

def test_register_app_specific_get(self):
"""
Test that a key with app specifc info can be registered with the server and that its
metadata is retrieved with the get operation.
Test that a key with app specifc info can be registered with the
server and that its metadata is retrieved with the get operation.
"""
key = objects.SymmetricKey(
enums.CryptographicAlgorithm.AES,
Expand Down Expand Up @@ -275,15 +276,17 @@ def test_asymmetric_key_pair_create_get_destroy(self):
enums.CryptographicAlgorithm.RSA)
self.assertEqual(private_key.cryptographic_length, 2048)
finally:
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, public_uid)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE,
public_uid)
self.client.destroy(public_uid)
self.assertRaises(
exceptions.KmipOperationFailure, self.client.get, public_uid)
self.assertRaises(
exceptions.KmipOperationFailure, self.client.destroy,
public_uid)

self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, private_uid)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE,
private_uid)
self.client.destroy(private_uid)
self.assertRaises(
exceptions.KmipOperationFailure, self.client.get, private_uid)
Expand Down Expand Up @@ -551,7 +554,7 @@ def test_secret_data_register_get_destroy(self):
exceptions.KmipOperationFailure, self.client.get, uid)
self.assertRaises(
exceptions.KmipOperationFailure, self.client.destroy, uid)

def test_secret_data_register_get_destroy_app_specific(self):
"""
Test that the ProxyKmipClient can register, retrieve, and destroy a
Expand Down
3 changes: 1 addition & 2 deletions kmip/tests/unit/core/messages/test_messages.py
Expand Up @@ -1166,8 +1166,7 @@ def test_locate_request_read(self):
type(attribute_name)))
self.assertEqual('Object Type', attribute_name.value,
self.msg.format('attribute name', 'value',
'Object Type',
attribute_name.value))
'Object Type', attribute_name.value))

attribute_value = attribute_a.attribute_value
exp_type = attr.Enumeration
Expand Down
2 changes: 1 addition & 1 deletion kmip/tests/unit/core/test_enums.py
Expand Up @@ -174,7 +174,7 @@ def test_convert_attribute_name_to_tag(self):
args = ("invalid", )
self.assertRaisesRegex(
ValueError,
"Unrecognized attribute name: 'invalid'".format(args[0]),
"Unrecognized attribute name: 'invalid'",
enums.convert_attribute_name_to_tag,
*args
)
Expand Down

0 comments on commit 263cb34

Please sign in to comment.