Improves performance and removes duplicated code by leveraging Python's built-in html.escape(). Note: changes escaping of single quotes from ' to ', which may affect literal output.
Reverted "Fixes #24727 -- Prevented ClearableFileInput from masking
exceptions on Python 2" and added a regression test.
This reverts commit 5c412dd8a7.
This is preparation for landing the template-based widget rendering
patch and goes a long way to making these tests more useful for future
development. The old doctest heritage is strong here.