Fix distutils byte-compilation to comply with PEP 3147 (#11254).

Patch by Jeff Ramnani.  Tested with -B, -O and -OO.
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 023ddff..631f5df 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -4,7 +4,11 @@
 one of the other *util.py modules.
 """
 
-import sys, os, string, re
+import os
+import re
+import imp
+import sys
+import string
 from distutils.errors import DistutilsPlatformError
 from distutils.dep_util import newer
 from distutils.spawn import spawn
@@ -529,7 +533,10 @@
             # Terminology from the py_compile module:
             #   cfile - byte-compiled file
             #   dfile - purported source filename (same as 'file' by default)
-            cfile = file + (__debug__ and "c" or "o")
+            if optimize >= 0:
+                cfile = imp.cache_from_source(file, debug_override=not optimize)
+            else:
+                cfile = imp.cache_from_source(file)
             dfile = file
             if prefix:
                 if file[:len(prefix)] != prefix: