Repository: pypa/pip

Issue:
pip uses deprecated SafeConfigParser
* Pip version: 9.0.1
* Python version: 3.6.1
* Operating system: Mac OS X 10.12.4

### Description:

With `error::DeprecationWarning` in `PYTHONWARNINGS`:

```
pip uninstall -y faker
/Users/davidchudzicki/.cache/hypothesis-build-runtimes/.tox/py36-full/lib/python3.6/site-packages/pip/pep425tags.py:260: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Exception:
Traceback (most recent call last):
  File "/Users/davidchudzicki/.cache/hypothesis-build-runtimes/.tox/py36-full/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Users/davidchudzicki/.cache/hypothesis-build-runtimes/.tox/py36-full/lib/python3.6/site-packages/pip/commands/uninstall.py", line 76, in run
    requirement_set.uninstall(auto_confirm=options.yes)
  File "/Users/davidchudzicki/.cache/hypothesis-build-runtimes/.tox/py36-full/lib/python3.6/site-packages/pip/req/req_set.py", line 346, in uninstall
    req.uninstall(auto_confirm=auto_confirm)
  File "/Users/davidchudzicki/.cache/hypothesis-build-runtimes/.tox/py36-full/lib/python3.6/site-packages/pip/req/req_install.py", line 732, in uninstall
    config = configparser.SafeConfigParser(**options)
  File "/Users/davidchudzicki/.cache/hypothesis-build-runtimes/versions/python3.6/lib/python3.6/configparser.py", line 1212, in __init__
    DeprecationWarning, stacklevel=2
DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead.
```


Discussion:
Hey @dchudz! Thanks for filing this issue!

I don't see this exact same line in master but there's definitely something similar to this in the codebase today.
This issue is a good starting point for anyone who wants to help out with pip's development -- it's simple and the process of fixing this should be a good introduction to pip's development workflow. :)
This particular SafeConfigParser was removed in d64b871d97f64fa10ca5a3f390d14fb35d761390

There is however another one

```
src/pip/_internal/vcs/mercurial.py
36:        config = configparser.SafeConfigParser()
```
Ah thanks/sorry @brycepg! I should have checked master and not just the latest release.
> There is however another one

Great! I guess that is still something that needs fixing. :)

Resolving patch:
diff --git a/src/pip/_internal/vcs/mercurial.py b/src/pip/_internal/vcs/mercurial.py
--- a/src/pip/_internal/vcs/mercurial.py
+++ b/src/pip/_internal/vcs/mercurial.py
@@ -45,7 +45,7 @@ def fetch_new(self, dest, url, rev_options):
 
     def switch(self, dest, url, rev_options):
         repo_config = os.path.join(dest, self.dirname, 'hgrc')
-        config = configparser.SafeConfigParser()
+        config = configparser.RawConfigParser()
         try:
             config.read(repo_config)
             config.set('paths', 'default', url)


Test patch:
diff --git a/tests/unit/test_vcs_mercurial.py b/tests/unit/test_vcs_mercurial.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/test_vcs_mercurial.py
@@ -0,0 +1,32 @@
+"""
+Contains functional tests of the Mercurial class.
+"""
+
+import os
+
+from pip._vendor.six.moves import configparser
+
+from pip._internal.vcs.mercurial import Mercurial
+from tests.lib import need_mercurial
+
+
+@need_mercurial
+def test_mercurial_switch_updates_config_file_when_found(tmpdir):
+    hg = Mercurial()
+    options = hg.make_rev_options()
+    hg_dir = os.path.join(tmpdir, '.hg')
+    os.mkdir(hg_dir)
+
+    config = configparser.RawConfigParser()
+    config.add_section('paths')
+    config.set('paths', 'default', 'old_url')
+
+    hgrc_path = os.path.join(hg_dir, 'hgrc')
+    with open(hgrc_path, 'w') as f:
+        config.write(f)
+    hg.switch(tmpdir, 'new_url', options)
+
+    config.read(hgrc_path)
+
+    default_path = config.get('paths', 'default')
+    assert default_path == 'new_url'