Test the open of non-exitent tarfile in all modes.
#20206, #5803: more efficient algorithm that doesn't truncate output.

This fixes an edge case (20206) where if the input ended in a character
needing encoding but there was no newline on the string, the last byte
of the encoded character would be dropped.  The fix is to use a more
efficient algorithm, provided by Serhiy Storchaka (5803), that does not
have the bug.
#20236: Fix sphinx markup.
Issue #20242: Fixed basicConfig() format strings for the alternative formatting styles.
Fix typo.
complain when nbytes > buflen to fix possible buffer overflow (closes #20246)
merge 3.2 (#20246)
correct defaultdict signature in docstring (closes #20250)

Patch from Andrew Barnert.
remove overly strict assertion (closes #20251)
add test for #20251