Fixing format string indices

This change adds indices to all format strings, ensuring
interoperability with Python 2.6.
This commit is contained in:
Peter Hamilton 2015-02-23 09:52:15 -05:00
parent f6b420d2db
commit 0cd2d3dab6
18 changed files with 68 additions and 67 deletions

View File

@ -104,14 +104,14 @@ class Name(Struct):
not isinstance(self.name_value, Name.NameValue) and \
not isinstance(self.name_value, str):
member = 'name_value'
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_value', type(Name.NameValue),
type(self.name_value)))
if self.name_type and \
not isinstance(self.name_type, Name.NameType) and \
not isinstance(self.name_type, str):
member = 'name_type'
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_type', type(Name.NameType),
type(self.name_type)))
@ -125,7 +125,7 @@ class Name(Struct):
name = 'Name'
msg = ErrorStrings.BAD_EXP_RECV
member = 'name_value'
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_value', type(Name.NameValue),
type(name_value)))
@ -137,7 +137,7 @@ class Name(Struct):
name = 'Name'
msg = ErrorStrings.BAD_EXP_RECV
member = 'name_type'
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_type', type(Name.NameType),
type(name_type)))
@ -357,27 +357,27 @@ class ApplicationSpecificInformation(Struct):
if self.application_namespace is not None:
if self.application_data is None:
member = 'application_data'
raise ValueError(msg.format('{}.{}'.format(name, member),
raise ValueError(msg.format('{0}.{1}'.format(name, member),
'value', 'not None', 'None'))
else:
member = 'application_namespace'
exp_type = self.ApplicationNamespace
if not isinstance(self.application_namespace, exp_type):
rcv_type = type(self.application_namespace)
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'type', exp_type, rcv_type))
if self.application_data is not None:
if self.application_namespace is None:
member = 'application_namespace'
raise ValueError(msg.format('{}.{}'.format(name, member),
raise ValueError(msg.format('{0}.{1}'.format(name, member),
'value', 'not None', 'None'))
else:
member = 'application_data'
exp_type = self.ApplicationData
if not isinstance(self.application_data, exp_type):
rcv_type = type(self.application_data)
raise TypeError(msg.format('{}.{}'.format(name, member),
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'type', exp_type, rcv_type))
@classmethod

View File

@ -115,7 +115,7 @@ class AttributeValueFactory(object):
else:
if not isinstance(name, str):
raise ValueError('Unrecognized attribute type: '
'{}'.format(name))
'{0}'.format(name))
elif name.startswith('x-'):
# Custom attribute indicated
value = self._create_custom_attribute(value)

View File

@ -49,7 +49,7 @@ class AttributeFactory(object):
pass
else:
msg = utils.build_er_error(Attribute, 'name',
'{} or {}'.format('Enum', 'str'),
'{0} or {1}'.format('Enum', 'str'),
type(name))
raise TypeError(msg)

View File

@ -34,7 +34,7 @@ class CredentialFactory(object):
elif cred_type is CredentialType.DEVICE:
value = self._create_device_credential(value)
else:
msg = 'Unrecognized credential type: {}'
msg = 'Unrecognized credential type: {0}'
raise ValueError(msg.format(cred_type))
return self._create_credential(cred_type, value)

View File

@ -64,7 +64,7 @@ class KeyFactory(object):
elif key_format is KeyFormatType.TRANSPARENT_ECMQV_PUBLIC_KEY:
return self._create_transparent_ecmqv_public_key(value)
else:
msg = 'Unrecognized key format type: {}'
msg = 'Unrecognized key format type: {0}'
raise ValueError(msg.format(key_format))
def _create_raw_key(self, value):

View File

@ -64,15 +64,16 @@ if __name__ == '__main__':
credential)
client.close()
logger.debug('create() result status: {}'.format(
logger.debug('create() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('created object type: {}'.format(result.object_type.enum))
logger.debug('created UUID: {}'.format(result.uuid.value))
logger.debug('created template attribute: {}'.
logger.debug('created object type: {0}'.format(
result.object_type.enum))
logger.debug('created UUID: {0}'.format(result.uuid.value))
logger.debug('created template attribute: {0}'.
format(result.template_attribute))
else:
logger.debug('create() result reason: {}'.format(
logger.debug('create() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('create() result message: {}'.format(
logger.debug('create() result message: {0}'.format(
result.result_message.value))

View File

@ -65,6 +65,6 @@ if __name__ == '__main__':
result = client.destroy(uuid, credential)
client.close()
logger.debug('destroy() result status: {}'.format(
logger.debug('destroy() result status: {0}'.format(
result.result_status.enum))
logger.debug('destroyed UUID: {}'.format(result.uuid.value))
logger.debug('destroyed UUID: {0}'.format(result.uuid.value))

View File

@ -63,7 +63,7 @@ if __name__ == '__main__':
result = client.get(uuid, credential)
client.close()
logger.debug('get() result status: {}'.format(result.result_status.enum))
logger.debug('retrieved object type: {}'.format(result.object_type.enum))
logger.debug('retrieved UUID: {}'.format(result.uuid.value))
logger.debug('retrieved secret: {}'.format(result.secret))
logger.debug('get() result status: {0}'.format(result.result_status.enum))
logger.debug('retrieved object type: {0}'.format(result.object_type.enum))
logger.debug('retrieved UUID: {0}'.format(result.uuid.value))
logger.debug('retrieved secret: {0}'.format(result.secret))

View File

@ -71,10 +71,10 @@ if __name__ == '__main__':
result = client.locate(attributes=attrs, credential=credential)
client.close()
logger.debug('locate() result status: {}'.
logger.debug('locate() result status: {0}'.
format(result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('retrieved object type: {}'.
logger.debug('retrieved object type: {0}'.
format(result.object_type.enum))
logger.debug('Located UUIDs: {}'.format(','.join([u.value for u in
result.uuids])))
logger.debug('Located UUIDs: {0}'.format(','.join([u.value for u in
result.uuids])))

View File

@ -77,8 +77,8 @@ if __name__ == '__main__':
credential)
client.close()
logger.debug('register() result status: {}'.format(
logger.debug('register() result status: {0}'.format(
result.result_status.enum))
logger.debug('registered UUID: {}'.format(result.uuid.value))
logger.debug('registered template attribute: {}'.
logger.debug('registered UUID: {0}'.format(result.uuid.value))
logger.debug('registered template attribute: {0}'.
format(result.template_attribute))

View File

@ -120,17 +120,17 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('create() result status: {}'.format(
logger.debug('create() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('created object type: {}'.format(
logger.debug('created object type: {0}'.format(
result.object_type.enum))
logger.debug('created UUID: {}'.format(result.uuid.value))
logger.debug('created template attribute: {}'.
logger.debug('created UUID: {0}'.format(result.uuid.value))
logger.debug('created template attribute: {0}'.
format(result.template_attribute))
else:
logger.debug('create() result reason: {}'.format(
logger.debug('create() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('create() result message: {}'.format(
logger.debug('create() result message: {0}'.format(
result.result_message.value))

View File

@ -113,20 +113,20 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('create_key_pair() result status: {}'.format(
logger.debug('create_key_pair() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('created private key UUID: {}'.format(
logger.debug('created private key UUID: {0}'.format(
result.private_key_uuid))
logger.debug('created public key UUID: {}'.format(
logger.debug('created public key UUID: {0}'.format(
result.public_key_uuid))
logger.debug('created private key template attribute: {}'.format(
logger.debug('created private key template attribute: {0}'.format(
result.private_key_template_attribute))
logger.debug('created public key template attribute: {}'.format(
logger.debug('created public key template attribute: {0}'.format(
result.public_key_template_attribute))
else:
logger.debug('create() result reason: {}'.format(
logger.debug('create() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('create() result message: {}'.format(
logger.debug('create() result message: {0}'.format(
result.result_message.value))

View File

@ -71,13 +71,13 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('destroy() result status: {}'.format(
logger.debug('destroy() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('destroyed UUID: {}'.format(result.uuid.value))
logger.debug('destroyed UUID: {0}'.format(result.uuid.value))
else:
logger.debug('destroy() result reason: {}'.format(
logger.debug('destroy() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('destroy() result message: {}'.format(
logger.debug('destroy() result message: {0}'.format(
result.result_message.value))

View File

@ -47,7 +47,7 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('discover_versions() result status: {}'.format(
logger.debug('discover_versions() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
@ -61,7 +61,7 @@ if __name__ == '__main__':
else:
logger.debug('number of protocol versions returned: 0')
else:
logger.debug('discover_versions() result reason: {}'.format(
logger.debug('discover_versions() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('discover_versions() result message: {}'.format(
logger.debug('discover_versions() result message: {0}'.format(
result.result_message.value))

View File

@ -71,16 +71,16 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('get() result status: {}'.format(
logger.debug('get() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('retrieved object type: {}'.format(
logger.debug('retrieved object type: {0}'.format(
result.object_type.enum))
logger.debug('retrieved UUID: {}'.format(result.uuid.value))
logger.debug('retrieved secret: {}'.format(result.secret))
logger.debug('retrieved UUID: {0}'.format(result.uuid.value))
logger.debug('retrieved secret: {0}'.format(result.secret))
else:
logger.debug('get() result reason: {}'.format(
logger.debug('get() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('get() result message: {}'.format(
logger.debug('get() result message: {0}'.format(
result.result_message.value))

View File

@ -86,7 +86,7 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('locate() result status: {}'.format(
logger.debug('locate() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
@ -94,7 +94,7 @@ if __name__ == '__main__':
for uuid in result.uuids:
logging.debug('{0}'.format(uuid))
else:
logger.debug('get() result reason: {}'.format(
logger.debug('get() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('get() result message: {}'.format(
logger.debug('get() result message: {0}'.format(
result.result_message.value))

View File

@ -121,15 +121,15 @@ if __name__ == '__main__':
client.close()
# Display operation results
logger.debug('register() result status: {}'.format(
logger.debug('register() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.debug('registered UUID: {}'.format(result.uuid.value))
logger.debug('registered template attribute: {}'.
logger.debug('registered UUID: {0}'.format(result.uuid.value))
logger.debug('registered template attribute: {0}'.
format(result.template_attribute))
else:
logger.debug('register() result reason: {}'.format(
logger.debug('register() result reason: {0}'.format(
result.result_reason.enum))
logger.debug('register() result message: {}'.format(
logger.debug('register() result message: {0}'.format(
result.result_message.value))

View File

@ -121,7 +121,7 @@ class Processor(object):
elif result_status.enum is RS.OPERATION_UNDONE:
result_reason = result[1]
else:
msg = 'Unrecognized operation result status: {}'
msg = 'Unrecognized operation result status: {0}'
raise RuntimeError(msg.format(result_status))
resp_bi = ResponseBatchItem(operation=operation,
@ -144,7 +144,7 @@ class Processor(object):
elif batch_error_cont_option.enum is BECO.CONTINUE:
continue
else:
msg = 'Unrecognized batch error continuation option: {}'
msg = 'Unrecognized batch error continuation option: {0}'
raise RuntimeError(msg.format(batch_error_cont_option))
response_batch_count = BatchCount(len(response_batch_items))