Browse code

YAML output: handle lack of support for sort_keys.

Xavier G authored on 11/05/2020 20:58:14
Showing 1 changed files

  • yamltab index 5e8a4cf..761733d 100755
... ...
@@ -315,7 +315,15 @@ def keytab_to_yaml(buf, args):
315 315
 def output_data(data, args, exit=None):
316 316
 	serialized_data = prepare_serialization(data)
317 317
 	if args.output_format == 'yaml':
318
-		yaml.dump(serialized_data, sys.stdout, width=160, sort_keys=False)
318
+		yaml_width = 160
319
+		try:
320
+			yaml.dump(serialized_data, sys.stdout, width=yaml_width, sort_keys=False)
321
+		except TypeError as error:
322
+			# Handle lack of support for sort_keys:
323
+			if 'sort_keys' in str(error):
324
+				yaml.dump(serialized_data, sys.stdout, width=yaml_width)
325
+			else:
326
+				raise
319 327
 	else:
320 328
 		json.dump(serialized_data, sys.stdout, indent=4)
321 329
 	if exit is not None: