gh-69370: Fix "python -m inspect --details" for unencodable paths (GH-155246)

It failed with UnicodeEncodeError if the path of the module contains
characters unencodable in the encoding of sys.stdout, e.g. undecodable
bytes of a file name.  Such characters are now escaped with backslashes,
unless stdout uses an error handler which can handle them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3 files changed