reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
diff --git a/Lib/distutils/command/bdist.py b/Lib/distutils/command/bdist.py
index 72b0cef..1a360b5 100644
--- a/Lib/distutils/command/bdist.py
+++ b/Lib/distutils/command/bdist.py
@@ -6,10 +6,9 @@
 __revision__ = "$Id$"
 
 import os
-
-from distutils.util import get_platform
 from distutils.core import Command
-from distutils.errors import DistutilsPlatformError, DistutilsOptionError
+from distutils.errors import *
+from distutils.util import get_platform
 
 
 def show_formats():
@@ -40,12 +39,6 @@
                      "[default: dist]"),
                     ('skip-build', None,
                      "skip rebuilding everything (for testing/debugging)"),
-                    ('owner=', 'u',
-                     "Owner name used when creating a tar file"
-                     " [default: current user]"),
-                    ('group=', 'g',
-                     "Group name used when creating a tar file"
-                     " [default: current group]"),
                    ]
 
     boolean_options = ['skip-build']
@@ -87,8 +80,6 @@
         self.formats = None
         self.dist_dir = None
         self.skip_build = 0
-        self.group = None
-        self.owner = None
 
     def finalize_options(self):
         # have to finalize 'plat_name' before 'bdist_base'
@@ -134,11 +125,6 @@
             if cmd_name not in self.no_format_option:
                 sub_cmd.format = self.formats[i]
 
-            # passing the owner and group names for tar archiving
-            if cmd_name == 'bdist_dumb':
-                sub_cmd.owner = self.owner
-                sub_cmd.group = self.group
-
             # If we're going to need to run this command again, tell it to
             # keep its temporary files around so subsequent runs go faster.
             if cmd_name in commands[i+1:]:
diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py
index c2af95f..2d39922 100644
--- a/Lib/distutils/command/bdist_dumb.py
+++ b/Lib/distutils/command/bdist_dumb.py
@@ -7,18 +7,16 @@
 __revision__ = "$Id$"
 
 import os
-
-from sysconfig import get_python_version
-
-from distutils.util import get_platform
 from distutils.core import Command
+from distutils.util import get_platform
 from distutils.dir_util import remove_tree, ensure_relative
-from distutils.errors import DistutilsPlatformError
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_dumb(Command):
 
-    description = 'create a "dumb" built distribution'
+    description = "create a \"dumb\" built distribution"
 
     user_options = [('bdist-dir=', 'd',
                      "temporary directory for creating the distribution"),
@@ -37,12 +35,6 @@
                     ('relative', None,
                      "build the archive using relative paths"
                      "(default: false)"),
-                    ('owner=', 'u',
-                     "Owner name used when creating a tar file"
-                     " [default: current user]"),
-                    ('group=', 'g',
-                     "Group name used when creating a tar file"
-                     " [default: current group]"),
                    ]
 
     boolean_options = ['keep-temp', 'skip-build', 'relative']
@@ -59,8 +51,6 @@
         self.dist_dir = None
         self.skip_build = 0
         self.relative = 0
-        self.owner = None
-        self.group = None
 
     def finalize_options(self):
         if self.bdist_dir is None:
@@ -118,8 +108,7 @@
 
         # Make the archive
         filename = self.make_archive(pseudoinstall_root,
-                                     self.format, root_dir=archive_root,
-                                     owner=self.owner, group=self.group)
+                                     self.format, root_dir=archive_root)
         if self.distribution.has_ext_modules():
             pyversion = get_python_version()
         else:
diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py
index f13c73b..c4be47b 100644
--- a/Lib/distutils/command/bdist_msi.py
+++ b/Lib/distutils/command/bdist_msi.py
@@ -6,15 +6,15 @@
 """
 Implements the bdist_msi command.
 """
-import sys, os
-from sysconfig import get_python_version, get_platform
 
+import sys, os
 from distutils.core import Command
 from distutils.dir_util import remove_tree
+from distutils.sysconfig import get_python_version
 from distutils.version import StrictVersion
 from distutils.errors import DistutilsOptionError
+from distutils.util import get_platform
 from distutils import log
-
 import msilib
 from msilib import schema, sequence, text
 from msilib import Directory, Feature, Dialog, add_data
@@ -28,6 +28,7 @@
         default, cancel, bitmap=true)"""
         Dialog.__init__(self, *args)
         ruler = self.h - 36
+        bmwidth = 152*ruler/328
         #if kw.get("bitmap", True):
         #    self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin")
         self.line("BottomLine", 0, ruler, self.w, 0)
@@ -418,6 +419,7 @@
         # see "Dialog Style Bits"
         modal = 3      # visible | modal
         modeless = 1   # visible
+        track_disk_space = 32
 
         # UI customization properties
         add_data(db, "Property",
diff --git a/Lib/distutils/command/bdist_rpm.py b/Lib/distutils/command/bdist_rpm.py
index 0a579db..452f950 100644
--- a/Lib/distutils/command/bdist_rpm.py
+++ b/Lib/distutils/command/bdist_rpm.py
@@ -5,14 +5,13 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-
+import sys, os
 from distutils.core import Command
 from distutils.debug import DEBUG
+from distutils.util import get_platform
 from distutils.file_util import write_file
-from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
-                              DistutilsFileError, DistutilsExecError)
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_rpm(Command):
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 71cc798..d6d01c6 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -5,16 +5,13 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-
-from sysconfig import get_python_version
-
+import sys, os
 from distutils.core import Command
-from distutils.dir_util import remove_tree
-from distutils.errors import DistutilsOptionError, DistutilsPlatformError
-from distutils import log
 from distutils.util import get_platform
+from distutils.dir_util import create_tree, remove_tree
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
+from distutils import log
 
 class bdist_wininst(Command):
 
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 4d30f8f..9c2667c 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -5,15 +5,16 @@
 __revision__ = "$Id$"
 
 import sys, os
-
-from distutils.util import get_platform
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
+from distutils.util import get_platform
+
 
 def show_compilers():
     from distutils.ccompiler import show_compilers
     show_compilers()
 
+
 class build(Command):
 
     description = "build everything needed to install"
@@ -126,6 +127,7 @@
         for cmd_name in self.get_sub_commands():
             self.run_command(cmd_name)
 
+
     # -- Predicates for the sub-command list ---------------------------
 
     def has_pure_modules(self):
@@ -140,6 +142,7 @@
     def has_scripts(self):
         return self.distribution.has_scripts()
 
+
     sub_commands = [('build_py',      has_pure_modules),
                     ('build_clib',    has_c_libraries),
                     ('build_ext',     has_ext_modules),
diff --git a/Lib/distutils/command/build_clib.py b/Lib/distutils/command/build_clib.py
index 4c6443c..258d7c1 100644
--- a/Lib/distutils/command/build_clib.py
+++ b/Lib/distutils/command/build_clib.py
@@ -18,8 +18,8 @@
 
 import os
 from distutils.core import Command
-from distutils.errors import DistutilsSetupError
-from distutils.ccompiler import customize_compiler
+from distutils.errors import *
+from distutils.sysconfig import customize_compiler
 from distutils import log
 
 def show_compilers():
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 8f41fac..bd61bc5 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -7,14 +7,12 @@
 __revision__ = "$Id$"
 
 import sys, os, re
-from warnings import warn
-
-from distutils.util import get_platform
 from distutils.core import Command
 from distutils.errors import *
-from distutils.ccompiler import customize_compiler
+from distutils.sysconfig import customize_compiler, get_python_version
 from distutils.dep_util import newer_group
 from distutils.extension import Extension
+from distutils.util import get_platform
 from distutils import log
 
 # this keeps compatibility from 2.3 to 2.5
@@ -114,39 +112,6 @@
          "list available compilers", show_compilers),
         ]
 
-    # making 'compiler' a property to deprecate
-    # its usage as something else than a compiler type
-    # e.g. like a compiler instance
-    def __init__(self, dist):
-        self._compiler = None
-        Command.__init__(self, dist)
-
-    def __setattr__(self, name, value):
-        # need this to make sure setattr() (used in distutils)
-        # doesn't kill our property
-        if name == 'compiler':
-            self._set_compiler(value)
-        else:
-            self.__dict__[name] = value
-
-    def _set_compiler(self, compiler):
-        if not isinstance(compiler, str) and compiler is not None:
-            # we don't want to allow that anymore in the future
-            warn("'compiler' specifies the compiler type in build_ext. "
-                 "If you want to get the compiler object itself, "
-                 "use 'compiler_obj'", DeprecationWarning)
-        self._compiler = compiler
-
-    def _get_compiler(self):
-        if not isinstance(self._compiler, str) and self._compiler is not None:
-            # we don't want to allow that anymore in the future
-            warn("'compiler' specifies the compiler type in build_ext. "
-                 "If you want to get the compiler object itself, "
-                 "use 'compiler_obj'", DeprecationWarning)
-        return self._compiler
-
-    compiler = property(_get_compiler, _set_compiler)
-
     def initialize_options(self):
         self.extensions = None
         self.build_lib = None
@@ -171,7 +136,8 @@
         self.user = None
 
     def finalize_options(self):
-        _sysconfig = __import__('sysconfig')
+        from distutils import sysconfig
+
         self.set_undefined_options('build',
                                    ('build_lib', 'build_lib'),
                                    ('build_temp', 'build_temp'),
@@ -188,8 +154,8 @@
 
         # Make sure Python's include directories (for Python.h, pyconfig.h,
         # etc.) are in the include search path.
-        py_include = _sysconfig.get_path('include')
-        plat_py_include = _sysconfig.get_path('platinclude')
+        py_include = sysconfig.get_python_inc()
+        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
         if self.include_dirs is None:
             self.include_dirs = self.distribution.include_dirs or []
         if isinstance(self.include_dirs, str):
@@ -261,13 +227,13 @@
         if os.name == 'os2':
             self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
 
-        # for extensions under Cygwin Python's library directory must be
+        # for extensions under Cygwin and AtheOS Python's library directory must be
         # appended to library_dirs
-        if sys.platform[:6] == 'cygwin':
+        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
-                                  "python" + _sysconfig.get_python_version(),
+                                                      "python" + get_python_version(),
                                                       "config"))
             else:
                 # building python standard extensions
@@ -275,13 +241,13 @@
 
         # for extensions under Linux or Solaris with a shared Python library,
         # Python's library directory must be appended to library_dirs
-        _sysconfig.get_config_var('Py_ENABLE_SHARED')
+        sysconfig.get_config_var('Py_ENABLE_SHARED')
         if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
              or sys.platform.startswith('sunos'))
-            and _sysconfig.get_config_var('Py_ENABLE_SHARED')):
+            and sysconfig.get_config_var('Py_ENABLE_SHARED')):
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
-                self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
+                self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
             else:
                 # building python standard extensions
                 self.library_dirs.append('.')
@@ -344,50 +310,38 @@
 
         # Setup the CCompiler object that we'll use to do all the
         # compiling and linking
-
-        # used to prevent the usage of an existing compiler for the
-        # compiler option when calling new_compiler()
-        # this will be removed in 3.3 and 2.8
-        if not isinstance(self._compiler, str):
-            self._compiler = None
-
-        self.compiler_obj = new_compiler(compiler=self._compiler,
-                                         verbose=self.verbose,
-                                         dry_run=self.dry_run,
-                                         force=self.force)
-
-        # used to keep the compiler object reachable with
-        # "self.compiler". this will be removed in 3.3 and 2.8
-        self._compiler = self.compiler_obj
-
-        customize_compiler(self.compiler_obj)
+        self.compiler = new_compiler(compiler=self.compiler,
+                                     verbose=self.verbose,
+                                     dry_run=self.dry_run,
+                                     force=self.force)
+        customize_compiler(self.compiler)
         # If we are cross-compiling, init the compiler now (if we are not
         # cross-compiling, init would not hurt, but people may rely on
         # late initialization of compiler even if they shouldn't...)
         if os.name == 'nt' and self.plat_name != get_platform():
-            self.compiler_obj.initialize(self.plat_name)
+            self.compiler.initialize(self.plat_name)
 
         # And make sure that any compile/link-related options (which might
         # come from the command-line or from the setup script) are set in
         # that CCompiler object -- that way, they automatically apply to
         # all compiling and linking done here.
         if self.include_dirs is not None:
-            self.compiler_obj.set_include_dirs(self.include_dirs)
+            self.compiler.set_include_dirs(self.include_dirs)
         if self.define is not None:
             # 'define' option is a list of (name,value) tuples
             for (name, value) in self.define:
-                self.compiler_obj.define_macro(name, value)
+                self.compiler.define_macro(name, value)
         if self.undef is not None:
             for macro in self.undef:
-                self.compiler_obj.undefine_macro(macro)
+                self.compiler.undefine_macro(macro)
         if self.libraries is not None:
-            self.compiler_obj.set_libraries(self.libraries)
+            self.compiler.set_libraries(self.libraries)
         if self.library_dirs is not None:
-            self.compiler_obj.set_library_dirs(self.library_dirs)
+            self.compiler.set_library_dirs(self.library_dirs)
         if self.rpath is not None:
-            self.compiler_obj.set_runtime_library_dirs(self.rpath)
+            self.compiler.set_runtime_library_dirs(self.rpath)
         if self.link_objects is not None:
-            self.compiler_obj.set_link_objects(self.link_objects)
+            self.compiler.set_link_objects(self.link_objects)
 
         # Now actually compile and link everything.
         self.build_extensions()
@@ -548,13 +502,13 @@
         for undef in ext.undef_macros:
             macros.append((undef,))
 
-        objects = self.compiler_obj.compile(sources,
-                                            output_dir=self.build_temp,
-                                            macros=macros,
-                                            include_dirs=ext.include_dirs,
-                                            debug=self.debug,
-                                            extra_postargs=extra_args,
-                                            depends=ext.depends)
+        objects = self.compiler.compile(sources,
+                                         output_dir=self.build_temp,
+                                         macros=macros,
+                                         include_dirs=ext.include_dirs,
+                                         debug=self.debug,
+                                         extra_postargs=extra_args,
+                                         depends=ext.depends)
 
         # XXX -- this is a Vile HACK!
         #
@@ -575,9 +529,9 @@
         extra_args = ext.extra_link_args or []
 
         # Detect target language, if not provided
-        language = ext.language or self.compiler_obj.detect_language(sources)
+        language = ext.language or self.compiler.detect_language(sources)
 
-        self.compiler_obj.link_shared_object(
+        self.compiler.link_shared_object(
             objects, ext_path,
             libraries=self.get_libraries(ext),
             library_dirs=ext.library_dirs,
@@ -710,13 +664,13 @@
         of the file from which it will be loaded (eg. "foo/bar.so", or
         "foo\bar.pyd").
         """
-        _sysconfig = __import__('sysconfig')
+        from distutils.sysconfig import get_config_var
         ext_path = ext_name.split('.')
         # OS/2 has an 8 character module (extension) limit :-(
         if os.name == "os2":
             ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
         # extensions in debug_mode are named 'module_d.pyd' under windows
-        so_ext = _sysconfig.get_config_var('SO')
+        so_ext = get_config_var('SO')
         if os.name == 'nt' and self.debug:
             return os.path.join(*ext_path) + '_d' + so_ext
         return os.path.join(*ext_path) + so_ext
@@ -744,7 +698,7 @@
         # Append '_d' to the python import library on debug builds.
         if sys.platform == "win32":
             from distutils.msvccompiler import MSVCCompiler
-            if not isinstance(self.compiler_obj, MSVCCompiler):
+            if not isinstance(self.compiler, MSVCCompiler):
                 template = "python%d%d"
                 if self.debug:
                     template = template + '_d'
@@ -775,12 +729,28 @@
             # don't extend ext.libraries, it may be shared with other
             # extensions, it is a reference to the original list
             return ext.libraries + [pythonlib]
+        elif sys.platform[:6] == "atheos":
+            from distutils import sysconfig
+
+            template = "python%d.%d"
+            pythonlib = (template %
+                   (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+            # Get SHLIBS from Makefile
+            extra = []
+            for lib in sysconfig.get_config_var('SHLIBS').split():
+                if lib.startswith('-l'):
+                    extra.append(lib[2:])
+                else:
+                    extra.append(lib)
+            # don't extend ext.libraries, it may be shared with other
+            # extensions, it is a reference to the original list
+            return ext.libraries + [pythonlib, "m"] + extra
         elif sys.platform == 'darwin':
             # Don't use the default code below
             return ext.libraries
         else:
-            _sysconfig = __import__('sysconfig')
-            if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
+            from distutils import sysconfig
+            if sysconfig.get_config_var('Py_ENABLE_SHARED'):
                 template = "python%d.%d"
                 pythonlib = (template %
                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py
index 7cc9353..26002e4 100644
--- a/Lib/distutils/command/build_py.py
+++ b/Lib/distutils/command/build_py.py
@@ -4,16 +4,16 @@
 
 __revision__ = "$Id$"
 
-import os
+import sys, os
 import sys
 from glob import glob
 
 from distutils.core import Command
-from distutils.errors import DistutilsOptionError, DistutilsFileError
+from distutils.errors import *
 from distutils.util import convert_path, Mixin2to3
 from distutils import log
 
-class build_py(Command):
+class build_py (Command):
 
     description = "\"build\" pure Python modules (copy to build directory)"
 
@@ -133,6 +133,7 @@
 
     def build_package_data(self):
         """Copy data files into build directory"""
+        lastdir = None
         for package, src_dir, build_dir, filenames in self.data_files:
             for filename in filenames:
                 target = os.path.join(build_dir, filename)
diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py
index a54d6ed..8b08bfe 100644
--- a/Lib/distutils/command/build_scripts.py
+++ b/Lib/distutils/command/build_scripts.py
@@ -6,6 +6,7 @@
 
 import os, re
 from stat import ST_MODE
+from distutils import sysconfig
 from distutils.core import Command
 from distutils.dep_util import newer
 from distutils.util import convert_path, Mixin2to3
@@ -56,7 +57,6 @@
         ie. starts with "\#!" and contains "python"), then adjust the first
         line to refer to the current Python interpreter as we copy.
         """
-        _sysconfig = __import__('sysconfig')
         self.mkpath(self.build_dir)
         outfiles = []
         updated_files = []
@@ -96,16 +96,16 @@
                 updated_files.append(outfile)
                 if not self.dry_run:
                     outf = open(outfile, "w")
-                    if not _sysconfig.is_python_build():
+                    if not sysconfig.python_build:
                         outf.write("#!%s%s\n" %
                                    (self.executable,
                                     post_interp))
                     else:
                         outf.write("#!%s%s\n" %
                                    (os.path.join(
-                            _sysconfig.get_config_var("BINDIR"),
-                           "python%s%s" % (_sysconfig.get_config_var("VERSION"),
-                                           _sysconfig.get_config_var("EXE"))),
+                            sysconfig.get_config_var("BINDIR"),
+                           "python%s%s" % (sysconfig.get_config_var("VERSION"),
+                                           sysconfig.get_config_var("EXE"))),
                                     post_interp))
                     outf.writelines(f.readlines())
                     outf.close()
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 56f643c..ac80a54 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -11,12 +11,11 @@
 
 __revision__ = "$Id$"
 
-import os
-import re
+import sys, os, re
 
 from distutils.core import Command
 from distutils.errors import DistutilsExecError
-from distutils.ccompiler import customize_compiler
+from distutils.sysconfig import customize_compiler
 from distutils import log
 
 LANG_EXT = {"c": ".c", "c++": ".cxx"}
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index e3e387a..2a905d9 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -7,17 +7,26 @@
 import sys
 import os
 
-from sysconfig import get_config_vars, get_paths, get_path, get_config_var
-
 from distutils import log
 from distutils.core import Command
 from distutils.debug import DEBUG
+from distutils.sysconfig import get_config_vars
 from distutils.errors import DistutilsPlatformError
 from distutils.file_util import write_file
-from distutils.util import convert_path, change_root, get_platform
+from distutils.util import convert_path, subst_vars, change_root
+from distutils.util import get_platform
 from distutils.errors import DistutilsOptionError
 
-# kept for backward compat, will be removed in 3.2
+# this keeps compatibility from 2.3 to 2.5
+if sys.version < "2.6":
+    USER_BASE = None
+    USER_SITE = None
+    HAS_USER_SITE = False
+else:
+    from site import USER_BASE
+    from site import USER_SITE
+    HAS_USER_SITE = True
+
 if sys.version < "2.2":
     WINDOWS_SCHEME = {
         'purelib': '$base',
@@ -50,21 +59,15 @@
         'scripts': '$base/bin',
         'data'   : '$base',
         },
-    'unix_user': {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/include/python$py_version_short/$dist_name',
-        'scripts': '$userbase/bin',
-        'data'   : '$userbase',
-        },
     'nt': WINDOWS_SCHEME,
-    'nt_user': {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
-        'scripts': '$userbase/Scripts',
-        'data'   : '$userbase',
+    'mac': {
+        'purelib': '$base/Lib/site-packages',
+        'platlib': '$base/Lib/site-packages',
+        'headers': '$base/Include/$dist_name',
+        'scripts': '$base/Scripts',
+        'data'   : '$base',
         },
+
     'os2': {
         'purelib': '$base/Lib/site-packages',
         'platlib': '$base/Lib/site-packages',
@@ -72,26 +75,47 @@
         'scripts': '$base/Scripts',
         'data'   : '$base',
         },
-    'os2_home': {
+    }
+
+# user site schemes
+if HAS_USER_SITE:
+    INSTALL_SCHEMES['nt_user'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
+        'scripts': '$userbase/Scripts',
+        'data'   : '$userbase',
+        }
+
+    INSTALL_SCHEMES['unix_user'] = {
         'purelib': '$usersite',
         'platlib': '$usersite',
         'headers': '$userbase/include/python$py_version_short/$dist_name',
         'scripts': '$userbase/bin',
         'data'   : '$userbase',
-        },
-    }
+        }
 
+    INSTALL_SCHEMES['mac_user'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/$py_version_short/include/$dist_name',
+        'scripts': '$userbase/bin',
+        'data'   : '$userbase',
+        }
+
+    INSTALL_SCHEMES['os2_home'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/include/python$py_version_short/$dist_name',
+        'scripts': '$userbase/bin',
+        'data'   : '$userbase',
+        }
+
+# The keys to an installation scheme; if any new types of files are to be
+# installed, be sure to add an entry to every installation scheme above,
+# and to SCHEME_KEYS here.
 SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
-# end of backward compat
 
-def _subst_vars(s, local_vars):
-    try:
-        return s.format(**local_vars)
-    except KeyError:
-        try:
-            return s.format(**os.environ)
-        except KeyError as var:
-            raise AttributeError('{%s}' % var)
 
 class install(Command):
 
@@ -158,10 +182,11 @@
 
     boolean_options = ['compile', 'force', 'skip-build']
 
-    user_options.append(('user', None,
-                        "install in user site-package '%s'" % \
-                            get_path('purelib', '%s_user' % os.name)))
-    boolean_options.append('user')
+    if HAS_USER_SITE:
+        user_options.append(('user', None,
+                             "install in user site-package '%s'" % USER_SITE))
+        boolean_options.append('user')
+
     negative_opt = {'no-compile' : 'compile'}
 
 
@@ -191,8 +216,8 @@
         self.install_lib = None         # set to either purelib or platlib
         self.install_scripts = None
         self.install_data = None
-        self.install_userbase = get_config_var('userbase')
-        self.install_usersite = get_path('purelib', '%s_user' % os.name)
+        self.install_userbase = USER_BASE
+        self.install_usersite = USER_SITE
 
         self.compile = None
         self.optimize = None
@@ -302,9 +327,7 @@
         # about needing recursive variable expansion (shudder).
 
         py_version = sys.version.split()[0]
-        prefix, exec_prefix, srcdir, projectbase = get_config_vars('prefix', 'exec_prefix',
-                                                      'srcdir', 'projectbase')
-
+        (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
         self.config_vars = {'dist_name': self.distribution.get_name(),
                             'dist_version': self.distribution.get_version(),
                             'dist_fullname': self.distribution.get_fullname(),
@@ -315,12 +338,12 @@
                             'prefix': prefix,
                             'sys_exec_prefix': exec_prefix,
                             'exec_prefix': exec_prefix,
-                            'srcdir': srcdir,
-                            'projectbase': projectbase,
                            }
 
-        self.config_vars['userbase'] = self.install_userbase
-        self.config_vars['usersite'] = self.install_usersite
+        if HAS_USER_SITE:
+            self.config_vars['userbase'] = self.install_userbase
+            self.config_vars['usersite'] = self.install_usersite
+
         self.expand_basedirs()
 
         self.dump_dirs("post-expand_basedirs()")
@@ -424,10 +447,10 @@
                 raise DistutilsPlatformError(
                     "User base directory is not specified")
             self.install_base = self.install_platbase = self.install_userbase
-            self.select_scheme("posix_user")
+            self.select_scheme("unix_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("posix_home")
+            self.select_scheme("unix_home")
         else:
             if self.prefix is None:
                 if self.exec_prefix is not None:
@@ -443,7 +466,7 @@
 
             self.install_base = self.prefix
             self.install_platbase = self.exec_prefix
-            self.select_scheme("posix_prefix")
+            self.select_scheme("unix_prefix")
 
     def finalize_other(self):
         """Finalizes options for non-posix platforms"""
@@ -455,7 +478,7 @@
             self.select_scheme(os.name + "_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("posix_home")
+            self.select_scheme("unix_home")
         else:
             if self.prefix is None:
                 self.prefix = os.path.normpath(sys.prefix)
@@ -470,15 +493,11 @@
     def select_scheme(self, name):
         """Sets the install directories by applying the install schemes."""
         # it's the caller's problem if they supply a bad name!
-        scheme = get_paths(name, expand=False)
-        for key, value in scheme.items():
-            if key == 'platinclude':
-                key = 'headers'
-                value = os.path.join(value, self.distribution.get_name())
+        scheme = INSTALL_SCHEMES[name]
+        for key in SCHEME_KEYS:
             attrname = 'install_' + key
-            if hasattr(self, attrname):
-                if getattr(self, attrname) is None:
-                    setattr(self, attrname, value)
+            if getattr(self, attrname) is None:
+                setattr(self, attrname, scheme[key])
 
     def _expand_attrs(self, attrs):
         for attr in attrs:
@@ -486,7 +505,7 @@
             if val is not None:
                 if os.name == 'posix' or os.name == 'nt':
                     val = os.path.expanduser(val)
-                val = _subst_vars(val, self.config_vars)
+                val = subst_vars(val, self.config_vars)
                 setattr(self, attr, val)
 
     def expand_basedirs(self):
diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py
index 7d3dc53..bdf5f8f 100644
--- a/Lib/distutils/command/register.py
+++ b/Lib/distutils/command/register.py
@@ -7,15 +7,13 @@
 
 __revision__ = "$Id$"
 
-import os
-import string
-import getpass
+import os, string, getpass
 import io
-import urllib.parse
-import urllib.request
+import urllib.parse, urllib.request
 from warnings import warn
 
 from distutils.core import PyPIRCCommand
+from distutils.errors import *
 from distutils import log
 
 class register(PyPIRCCommand):
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
index f6e099b..bb21061 100644
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -7,14 +7,14 @@
 import os
 import string
 import sys
+from types import *
 from glob import glob
 from warnings import warn
 
 from distutils.core import Command
 from distutils import dir_util, dep_util, file_util, archive_util
 from distutils.text_file import TextFile
-from distutils.errors import (DistutilsPlatformError, DistutilsOptionError,
-                              DistutilsTemplateError)
+from distutils.errors import *
 from distutils.filelist import FileList
 from distutils import log
 from distutils.util import convert_path
@@ -76,10 +76,6 @@
         ('medata-check', None,
          "Ensure that all required elements of meta-data "
          "are supplied. Warn if any missing. [default]"),
-        ('owner=', 'u',
-         "Owner name used when creating a tar file [default: current user]"),
-        ('group=', 'g',
-         "Group name used when creating a tar file [default: current group]"),
         ]
 
     boolean_options = ['use-defaults', 'prune',
@@ -119,8 +115,6 @@
 
         self.archive_files = None
         self.metadata_check = 1
-        self.owner = None
-        self.group = None
 
     def finalize_options(self):
         if self.manifest is None:
@@ -424,8 +418,7 @@
             self.formats.append(self.formats.pop(self.formats.index('tar')))
 
         for fmt in self.formats:
-            file = self.make_archive(base_name, fmt, base_dir=base_dir,
-                                     owner=self.owner, group=self.group)
+            file = self.make_archive(base_name, fmt, base_dir=base_dir)
             archive_files.append(file)
             self.distribution.dist_files.append(('sdist', '', file))
 
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index bb1b7fc..f602fbe 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -1,19 +1,25 @@
 """distutils.command.upload
 
 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
-import os
-import io
-import socket
-import platform
-from urllib.request import urlopen, Request, HTTPError
-from base64 import standard_b64encode
-from urllib.parse import urlparse
-from hashlib import md5
 
-from distutils.errors import DistutilsOptionError
+from distutils.errors import *
 from distutils.core import PyPIRCCommand
 from distutils.spawn import spawn
 from distutils import log
+import sys
+import os, io
+import socket
+import platform
+import configparser
+import http.client as httpclient
+from base64 import standard_b64encode
+import urllib.parse
+
+# this keeps compatibility for 2.3 and 2.4
+if sys.version < "2.5":
+    from md5 import md5
+else:
+    from hashlib import md5
 
 class upload(PyPIRCCommand):
 
@@ -60,15 +66,6 @@
             self.upload_file(command, pyversion, filename)
 
     def upload_file(self, command, pyversion, filename):
-        # Makes sure the repository URL is compliant
-        schema, netloc, url, params, query, fragments = \
-            urlparse(self.repository)
-        if params or query or fragments:
-            raise AssertionError("Incompatible url %s" % self.repository)
-
-        if schema not in ('http', 'https'):
-            raise AssertionError("unsupported schema " + schema)
-
         # Sign if requested
         if self.sign:
             gpg_args = ["gpg", "--detach-sign", "-a", filename]
@@ -140,10 +137,10 @@
         for key, value in data.items():
             title = '\nContent-Disposition: form-data; name="%s"' % key
             # handle multiple entries for the same name
-            if not isinstance(value, list):
+            if type(value) != type([]):
                 value = [value]
             for value in value:
-                if isinstance(value, tuple):
+                if type(value) is tuple:
                     title += '; filename="%s"' % value[0]
                     value = value[1]
                 else:
@@ -161,30 +158,40 @@
         self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
 
         # build the Request
-        headers = {'Content-type':
-                        'multipart/form-data; boundary=%s' % boundary,
-                   'Content-length': str(len(body)),
-                   'Authorization': auth}
+        # We can't use urllib since we need to send the Basic
+        # auth right with the first request
+        # TODO(jhylton): Can we fix urllib?
+        schema, netloc, url, params, query, fragments = \
+            urllib.parse.urlparse(self.repository)
+        assert not params and not query and not fragments
+        if schema == 'http':
+            http = httpclient.HTTPConnection(netloc)
+        elif schema == 'https':
+            http = httpclient.HTTPSConnection(netloc)
+        else:
+            raise AssertionError("unsupported schema "+schema)
 
-        request = Request(self.repository, data=body,
-                          headers=headers)
-        # send the data
+        data = ''
+        loglevel = log.INFO
         try:
-            result = urlopen(request)
-            status = result.getcode()
-            reason = result.msg
+            http.connect()
+            http.putrequest("POST", url)
+            http.putheader('Content-type',
+                           'multipart/form-data; boundary=%s'%boundary)
+            http.putheader('Content-length', str(len(body)))
+            http.putheader('Authorization', auth)
+            http.endheaders()
+            http.send(body)
         except socket.error as e:
             self.announce(str(e), log.ERROR)
             return
-        except HTTPError as e:
-            status = e.code
-            reason = e.msg
 
-        if status == 200:
-            self.announce('Server response (%s): %s' % (status, reason),
+        r = http.getresponse()
+        if r.status == 200:
+            self.announce('Server response (%s): %s' % (r.status, r.reason),
                           log.INFO)
         else:
-            self.announce('Upload failed (%s): %s' % (status, reason),
+            self.announce('Upload failed (%s): %s' % (r.status, r.reason),
                           log.ERROR)
         if self.show_response:
-            self.announce('-'*75, result.read(), '-'*75)
+            self.announce('-'*75, r.read(), '-'*75)