4343
4444MIN_PYTHON_VERSION = (3 , 6 )
4545if sys .version_info < MIN_PYTHON_VERSION :
46- sys .exit ("Python %s.%s or newer is required by imgtool."
47- % MIN_PYTHON_VERSION )
46+ sys .exit ("Python {}.{} or newer is required by imgtool." .format (* MIN_PYTHON_VERSION ))
4847
4948SlottedSemiSemVersion = namedtuple ('SemiSemVersion' , ['major' , 'minor' , 'revision' ,
5049 'build' , 'slot' ])
@@ -358,9 +357,8 @@ def convert(self, value, param, ctx):
358357 try :
359358 return int (value , 0 )
360359 except ValueError :
361- self .fail ('%s is not a valid integer. Please use code literals '
362- 'prefixed with 0b/0B, 0o/0O, or 0x/0X as necessary.'
363- % value , param , ctx )
360+ self .fail (f'{ value } is not a valid integer. Please use code literals '
361+ 'prefixed with 0b/0B, 0o/0O, or 0x/0X as necessary.' , param , ctx )
364362
365363
366364@click .argument ('outfile' )
@@ -501,16 +499,15 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
501499 img .load (infile )
502500 key = load_key (key ) if key else None
503501 enckey = load_key (encrypt ) if encrypt else None
504- if enckey and key :
505- if ((isinstance (key , keys .ECDSA256P1 ) and
506- not isinstance (enckey , keys .ECDSA256P1Public ))
507- or (isinstance (key , keys .ECDSA384P1 ) and
508- not isinstance (enckey , keys .ECDSA384P1Public ))
509- or (isinstance (key , keys .RSA ) and
510- not isinstance (enckey , keys .RSAPublic ))):
511- # FIXME
512- raise click .UsageError ("Signing and encryption must use the same "
513- "type of key" )
502+ if enckey and key and ((isinstance (key , keys .ECDSA256P1 ) and
503+ not isinstance (enckey , keys .ECDSA256P1Public ))
504+ or (isinstance (key , keys .ECDSA384P1 ) and
505+ not isinstance (enckey , keys .ECDSA384P1Public ))
506+ or (isinstance (key , keys .RSA ) and
507+ not isinstance (enckey , keys .RSAPublic ))):
508+ # FIXME
509+ raise click .UsageError ("Signing and encryption must use the same "
510+ "type of key" )
514511
515512 if pad_sig and hasattr (key , 'pad_sig' ):
516513 key .pad_sig = True
@@ -520,10 +517,10 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
520517 for tlv in custom_tlv :
521518 tag = int (tlv [0 ], 0 )
522519 if tag in custom_tlvs :
523- raise click .UsageError ('Custom TLV %s already exists.' % hex ( tag ) )
520+ raise click .UsageError (f 'Custom TLV { hex ( tag ) } already exists.' )
524521 if tag in image .TLV_VALUES .values ():
525522 raise click .UsageError (
526- 'Custom TLV %s conflicts with predefined TLV.' % hex ( tag ) )
523+ f 'Custom TLV { hex ( tag ) } conflicts with predefined TLV.' )
527524
528525 value = tlv [1 ]
529526 if value .startswith ('0x' ):
0 commit comments