Fix source code style to comply with PEP8

This commit is contained in:
Konstantin Trushin 2023-03-27 18:24:34 +04:00 committed by arp102
parent 155c05069f
commit 263cb34662
9 changed files with 54 additions and 40 deletions

View File

@ -40,7 +40,7 @@ class DiscoverVersionsRequestPayload(base.RequestPayload):
) )
tstream = BytearrayStream(istream.read(self.length)) 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 = ProtocolVersion()
protocol_version.read(tstream, kmip_version=kmip_version) protocol_version.read(tstream, kmip_version=kmip_version)
self.protocol_versions.append(protocol_version) self.protocol_versions.append(protocol_version)
@ -99,7 +99,7 @@ class DiscoverVersionsResponsePayload(base.ResponsePayload):
) )
tstream = BytearrayStream(istream.read(self.length)) 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 = ProtocolVersion()
protocol_version.read(tstream, kmip_version=kmip_version) protocol_version.read(tstream, kmip_version=kmip_version)
self.protocol_versions.append(protocol_version) self.protocol_versions.append(protocol_version)

View File

@ -105,7 +105,7 @@ class QueryRequestPayload(base.RequestPayload):
local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
query_functions = [] 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( query_function = primitives.Enumeration(
enums.QueryFunction, enums.QueryFunction,
tag=enums.Tags.QUERY_FUNCTION tag=enums.Tags.QUERY_FUNCTION
@ -709,7 +709,7 @@ class QueryResponsePayload(base.ResponsePayload):
local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
operations = [] operations = []
while(self.is_tag_next(enums.Tags.OPERATION, local_buffer)): while (self.is_tag_next(enums.Tags.OPERATION, local_buffer)):
operation = primitives.Enumeration( operation = primitives.Enumeration(
enums.Operation, enums.Operation,
tag=enums.Tags.OPERATION tag=enums.Tags.OPERATION
@ -719,7 +719,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._operations = operations self._operations = operations
object_types = [] 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( object_type = primitives.Enumeration(
enums.ObjectType, enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE tag=enums.Tags.OBJECT_TYPE
@ -747,7 +747,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._server_information = server_information self._server_information = server_information
application_namespaces = [] application_namespaces = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.APPLICATION_NAMESPACE, enums.Tags.APPLICATION_NAMESPACE,
local_buffer local_buffer
) )
@ -761,7 +761,7 @@ class QueryResponsePayload(base.ResponsePayload):
if kmip_version >= enums.KMIPVersion.KMIP_1_1: if kmip_version >= enums.KMIPVersion.KMIP_1_1:
extensions_information = [] extensions_information = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.EXTENSION_INFORMATION, enums.Tags.EXTENSION_INFORMATION,
local_buffer local_buffer
) )
@ -776,7 +776,11 @@ class QueryResponsePayload(base.ResponsePayload):
if kmip_version >= enums.KMIPVersion.KMIP_1_2: if kmip_version >= enums.KMIPVersion.KMIP_1_2:
attestation_types = [] 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( attestation_type = primitives.Enumeration(
enums.AttestationType, enums.AttestationType,
tag=enums.Tags.ATTESTATION_TYPE tag=enums.Tags.ATTESTATION_TYPE
@ -787,14 +791,14 @@ class QueryResponsePayload(base.ResponsePayload):
if kmip_version >= enums.KMIPVersion.KMIP_1_3: if kmip_version >= enums.KMIPVersion.KMIP_1_3:
rngs_parameters = [] 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 = objects.RNGParameters()
rng_parameters.read(local_buffer, kmip_version=kmip_version) rng_parameters.read(local_buffer, kmip_version=kmip_version)
rngs_parameters.append(rng_parameters) rngs_parameters.append(rng_parameters)
self._rng_parameters = rngs_parameters self._rng_parameters = rngs_parameters
profiles_information = [] profiles_information = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.PROFILE_INFORMATION, enums.Tags.PROFILE_INFORMATION,
local_buffer local_buffer
) )
@ -808,7 +812,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._profile_information = profiles_information self._profile_information = profiles_information
validations_information = [] validations_information = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.VALIDATION_INFORMATION, enums.Tags.VALIDATION_INFORMATION,
local_buffer local_buffer
) )
@ -822,7 +826,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._validation_information = validations_information self._validation_information = validations_information
capabilities_information = [] capabilities_information = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.CAPABILITY_INFORMATION, enums.Tags.CAPABILITY_INFORMATION,
local_buffer local_buffer
) )
@ -836,7 +840,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._capability_information = capabilities_information self._capability_information = capabilities_information
client_registration_methods = [] client_registration_methods = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.CLIENT_REGISTRATION_METHOD, enums.Tags.CLIENT_REGISTRATION_METHOD,
local_buffer local_buffer
) )
@ -862,7 +866,7 @@ class QueryResponsePayload(base.ResponsePayload):
self._defaults_information = defaults_information self._defaults_information = defaults_information
protection_storage_masks = [] protection_storage_masks = []
while(self.is_tag_next( while (self.is_tag_next(
enums.Tags.PROTECTION_STORAGE_MASK, enums.Tags.PROTECTION_STORAGE_MASK,
local_buffer local_buffer
) )

View File

@ -658,7 +658,8 @@ class SymmetricKey(Key):
} }
def __init__(self, algorithm, length, value, masks=None, 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. Create a SymmetricKey.
@ -674,8 +675,9 @@ class SymmetricKey(Key):
key_wrapping_data(dict): A dictionary containing key wrapping data key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped. settings, describing how the key value has been wrapped.
Optional, defaults to None. Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data. app_specific_info(list): A list of dictionaries containing
Optional, defaults to None. application_namespace and application_data. Optional, defaults
to None.
""" """
super(SymmetricKey, self).__init__( super(SymmetricKey, self).__init__(
key_wrapping_data=key_wrapping_data key_wrapping_data=key_wrapping_data
@ -826,7 +828,8 @@ class PublicKey(Key):
def __init__(self, algorithm, length, value, def __init__(self, algorithm, length, value,
format_type=enums.KeyFormatType.X_509, masks=None, 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. Create a PublicKey.
@ -844,8 +847,9 @@ class PublicKey(Key):
key_wrapping_data(dict): A dictionary containing key wrapping data key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped. settings, describing how the key value has been wrapped.
Optional, defaults to None. Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data. app_specific_info(list): A list of dictionaries containing
Optional, defaults to None. application_namespace and application_data. Optional, defaults
to None.
""" """
super(PublicKey, self).__init__( super(PublicKey, self).__init__(
key_wrapping_data=key_wrapping_data key_wrapping_data=key_wrapping_data
@ -996,7 +1000,8 @@ class PrivateKey(Key):
} }
def __init__(self, algorithm, length, value, format_type, masks=None, 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. Create a PrivateKey.
@ -1013,8 +1018,9 @@ class PrivateKey(Key):
key_wrapping_data(dict): A dictionary containing key wrapping data key_wrapping_data(dict): A dictionary containing key wrapping data
settings, describing how the key value has been wrapped. settings, describing how the key value has been wrapped.
Optional, defaults to None. Optional, defaults to None.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data. app_specific_info(list): A list of dictionaries containing
Optional, defaults to None. application_namespace and application_data. Optional, defaults
to None.
""" """
super(PrivateKey, self).__init__( super(PrivateKey, self).__init__(
key_wrapping_data=key_wrapping_data key_wrapping_data=key_wrapping_data
@ -1595,7 +1601,8 @@ class SecretData(CryptographicObject):
'sqlite_autoincrement': True '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. Create a SecretData object.
@ -1606,8 +1613,9 @@ class SecretData(CryptographicObject):
masks(list): A list of CryptographicUsageMask enumerations masks(list): A list of CryptographicUsageMask enumerations
defining how the key will be used. defining how the key will be used.
name(string): The string name of the key. name(string): The string name of the key.
app_specific_info(list): A list of dictionaries containing application_namespace and application_data. app_specific_info(list): A list of dictionaries containing
Optional, defaults to None. application_namespace and application_data. Optional, defaults
to None.
""" """
super(SecretData, self).__init__() super(SecretData, self).__init__()
@ -1616,7 +1624,7 @@ class SecretData(CryptographicObject):
self.value = value self.value = value
self.data_type = data_type self.data_type = data_type
self.names = [name] self.names = [name]
if app_specific_info: if app_specific_info:
self._application_specific_informations = app_specific_info self._application_specific_informations = app_specific_info

View File

@ -274,7 +274,7 @@ class CryptographyEngine(api.CryptographicEngine):
c = cmac.CMAC(cipher_algorithm(key), backend=default_backend()) c = cmac.CMAC(cipher_algorithm(key), backend=default_backend())
c.update(data) c.update(data)
mac_data = c.finalize() mac_data = c.finalize()
except Exception as e: except Exception:
raise exceptions.CryptographicFailure( raise exceptions.CryptographicFailure(
"An error occurred while computing a CMAC. " "An error occurred while computing a CMAC. "
"See the server log for more information." "See the server log for more information."

View File

@ -439,7 +439,7 @@ class KmipEngine(object):
).filter( ).filter(
objects.ManagedObject.unique_identifier == unique_identifier objects.ManagedObject.unique_identifier == unique_identifier
).one()[0] ).one()[0]
except exc.NoResultFound as e: except exc.NoResultFound:
self._logger.warning( self._logger.warning(
"Could not identify object type for object: {0}".format( "Could not identify object type for object: {0}".format(
unique_identifier unique_identifier

View File

@ -107,7 +107,7 @@ class KmipSession(threading.Thread):
while True: while True:
try: try:
self._handle_message_loop() self._handle_message_loop()
except exceptions.ConnectionClosed as e: except exceptions.ConnectionClosed:
break break
except Exception as e: except Exception as e:
self._logger.info("Failure handling message loop") self._logger.info("Failure handling message loop")

View File

@ -103,7 +103,8 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
self.assertNotEqual(unwrapped_key.value, wrapped_key.value) self.assertNotEqual(unwrapped_key.value, wrapped_key.value)
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) 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(key_id)
self.client.destroy(wrapping_id) self.client.destroy(wrapping_id)
@ -184,11 +185,11 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
) )
self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id)
self.client.destroy(key_id) self.client.destroy(key_id)
def test_register_app_specific_get(self): def test_register_app_specific_get(self):
""" """
Test that a key with app specifc info can be registered with the server and that its Test that a key with app specifc info can be registered with the
metadata is retrieved with the get operation. server and that its metadata is retrieved with the get operation.
""" """
key = objects.SymmetricKey( key = objects.SymmetricKey(
enums.CryptographicAlgorithm.AES, enums.CryptographicAlgorithm.AES,
@ -275,7 +276,8 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
enums.CryptographicAlgorithm.RSA) enums.CryptographicAlgorithm.RSA)
self.assertEqual(private_key.cryptographic_length, 2048) self.assertEqual(private_key.cryptographic_length, 2048)
finally: 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.client.destroy(public_uid)
self.assertRaises( self.assertRaises(
exceptions.KmipOperationFailure, self.client.get, public_uid) exceptions.KmipOperationFailure, self.client.get, public_uid)
@ -283,7 +285,8 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
exceptions.KmipOperationFailure, self.client.destroy, exceptions.KmipOperationFailure, self.client.destroy,
public_uid) 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.client.destroy(private_uid)
self.assertRaises( self.assertRaises(
exceptions.KmipOperationFailure, self.client.get, private_uid) exceptions.KmipOperationFailure, self.client.get, private_uid)
@ -551,7 +554,7 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
exceptions.KmipOperationFailure, self.client.get, uid) exceptions.KmipOperationFailure, self.client.get, uid)
self.assertRaises( self.assertRaises(
exceptions.KmipOperationFailure, self.client.destroy, uid) exceptions.KmipOperationFailure, self.client.destroy, uid)
def test_secret_data_register_get_destroy_app_specific(self): def test_secret_data_register_get_destroy_app_specific(self):
""" """
Test that the ProxyKmipClient can register, retrieve, and destroy a Test that the ProxyKmipClient can register, retrieve, and destroy a

View File

@ -1166,8 +1166,7 @@ class TestRequestMessage(TestCase):
type(attribute_name))) type(attribute_name)))
self.assertEqual('Object Type', attribute_name.value, self.assertEqual('Object Type', attribute_name.value,
self.msg.format('attribute name', 'value', self.msg.format('attribute name', 'value',
'Object Type', 'Object Type', attribute_name.value))
attribute_name.value))
attribute_value = attribute_a.attribute_value attribute_value = attribute_a.attribute_value
exp_type = attr.Enumeration exp_type = attr.Enumeration

View File

@ -174,7 +174,7 @@ class TestEnumUtilityFunctions(testtools.TestCase):
args = ("invalid", ) args = ("invalid", )
self.assertRaisesRegex( self.assertRaisesRegex(
ValueError, ValueError,
"Unrecognized attribute name: 'invalid'".format(args[0]), "Unrecognized attribute name: 'invalid'",
enums.convert_attribute_name_to_tag, enums.convert_attribute_name_to_tag,
*args *args
) )