bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)

27 files changed