Issue #12319: Support for chunked encoding of HTTP request bodies

When the body object is a file, its size is no longer determined with
fstat(), since that can report the wrong result (e.g. reading from a pipe).
Instead, determine the size using seek(), or fall back to chunked encoding
for unseekable files.

Also, change the logic for detecting text files to check for TextIOBase
inheritance, rather than inspecting the “mode” attribute, which may not
exist (e.g. BytesIO and StringIO).  The Content-Length for text files is no
longer determined ahead of time, because the original logic could have been
wrong depending on the codec and newline translation settings.

Patch by Demian Brecht and Rolf Krahl, with a few tweaks by me.
diff --git a/Misc/ACKS b/Misc/ACKS
index 9cc1c1e..46f4ae7 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -795,6 +795,7 @@
 Jerzy Kozera
 Maksim Kozyarchuk
 Stefan Krah
+Rolf Krahl
 Bob Kras
 Sebastian Kreft
 Holger Krekel
diff --git a/Misc/NEWS b/Misc/NEWS
index 5d98cdd..e0cd715 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -160,6 +160,14 @@
   then further affects other traceback display operations in the module). Patch
   by Emanuel Barry.
 
+- Issue #12319: Chunked transfer encoding support added to
+  http.client.HTTPConnection requests.  The
+  urllib.request.AbstractHTTPHandler class does not enforce a Content-Length
+  header any more.  If a HTTP request has a non-empty body, but no
+  Content-Length header, and the content length cannot be determined
+  up front, rather than throwing an error, the library now falls back
+  to use chunked transfer encoding.
+
 - Issue #27664: Add to concurrent.futures.thread.ThreadPoolExecutor()
   the ability to specify a thread name prefix.