+# Provide custom format type 'H' for hexadecimal output
+# with leading decimal digit (assembler syntax).
+class AsmFormatter(string.Formatter):
+ def format_field(self, value, format_spec):
+ if format_spec.endswith('H'):
+ result = format(value, format_spec[:-1] + 'X')
+ return result if result[0] in string.digits else '0' + result
+ else:
+ return format(value, format_spec)
+
+formatter = AsmFormatter()
+