We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pip on windows
Prerequisites:
Windows
python 2.7
setuptools 3.6
easy_install
pip

Problem:
we have a requirements file that contains "pyinstaller" package dependency. I suppose that it somehow depends on cryptography and it in its turn somehow depends on cffi package and that's why it tries to install it as well. For now we specify this depency in a following way:

pyinstaller==2.1.1dev-89e99dd # from requirements file.

Next we try to install our pack of requirements with 

pip -f {our additional private repository} -U -egg -r {requirements file name}

From the build log screenshot attached you can see the following string(build_log attachment):

[12:59:39]:  [Step 7/15] Installed c:\users\administrator\envs\python27-32bit\lib\site-packages\cryptography-0.3-py2.7-win32.egg
[12:59:39]:  [Step 7/15] 
[12:59:39]:  [Step 7/15] error: c:\buildagent\temp\buildtmp\easy_install-snsbak\cryptography-0.3\cffi-0.8.2-py2.7-win32.egg_cffi_backend.pyd: Access is denied

I've done a few of investigation and attached a screenshot of related file activity with a highlighted important items (file_activity_list attachment). It seems that python cannod delete this _cffi_backend.pyd file. A few more investigation revealed that the file creation mode allows to delete this file(file_open_result attachment). From the event properties(event_properties attachment) I see that all related modules appear as if they are loaded using LoadLibray windows api, that's how it supposed to be done with python C extensions if we want to use this code. But it appears to me that someone forgot to unload all these modules before trying to delete them and that's why the file cannot be deleted. Please refer to _cffi_backend_loading attachment - it proves _cffi_backend.pyd is being loaded as a library(WinDbg screen). And the very next screenshot is the state of pip install command when WinDbg broke on module load - _break_python_screen attachment. Yet I pointed out the same problem if I just parse this requirements file with pkg_tools and specify install_requires setup's argument with these requirements - setup develop fails with the same result. As to me this problem more relates to easy_install/setuptools core. And yet to mention - without '--egg' argument the problem doesn't reproduce.

![file_activity_list](https://cloud.githubusercontent.com/assets/7242142/3082926/4def0fa4-e4db-11e3-8e14-37f52ea5b2ee.png)
![event_properties](https://cloud.githubusercontent.com/assets/7242142/3082956/ba432474-e4db-11e3-8d6f-5d0996c35a44.png)
![file_open_result](https://cloud.githubusercontent.com/assets/7242142/3082983/1417a8e4-e4dc-11e3-9289-0bf61c7cf2c9.png)

![build_log](https://cloud.githubusercontent.com/assets/7242142/3082887/b8bc80e2-e4da-11e3-945a-a0c1137bb6bb.png)
![_cffi_backend_loading](https://cloud.githubusercontent.com/assets/7242142/3160093/dddbe462-eb1a-11e3-8e08-48cfade1b261.png)
![_break_python_screen](https://cloud.githubusercontent.com/assets/7242142/3160112/29cc9c0e-eb1b-11e3-88a6-2601f7a8dbe5.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pip/_vendor/requests/__init__.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 #   __
4 #  /__)  _  _     _   _ _/   _
5 # / (   (- (/ (/ (- _)  /  _)
6 #          /
7 
8 """
9 Requests HTTP library
10 ~~~~~~~~~~~~~~~~~~~~~
11 
12 Requests is an HTTP library, written in Python, for human beings. Basic GET
13 usage:
14 
15    >>> import requests
16    >>> r = requests.get('https://www.python.org')
17    >>> r.status_code
18    200
19    >>> 'Python is a programming language' in r.content
20    True
21 
22 ... or POST:
23 
24    >>> payload = dict(key1='value1', key2='value2')
25    >>> r = requests.post('http://httpbin.org/post', data=payload)
26    >>> print(r.text)
27    {
28      ...
29      "form": {
30        "key2": "value2",
31        "key1": "value1"
32      },
33      ...
34    }
35 
36 The other HTTP methods are supported - see `requests.api`. Full documentation
37 is at <http://python-requests.org>.
38 
39 :copyright: (c) 2016 by Kenneth Reitz.
40 :license: Apache 2.0, see LICENSE for more details.
41 
42 """
43 
44 __title__ = 'requests'
45 __version__ = '2.10.0'
46 __build__ = 0x021000
47 __author__ = 'Kenneth Reitz'
48 __license__ = 'Apache 2.0'
49 __copyright__ = 'Copyright 2016 Kenneth Reitz'
50 
51 # Attempt to enable urllib3's SNI support, if possible
52 try:
53     from .packages.urllib3.contrib import pyopenssl
54     pyopenssl.inject_into_urllib3()
55 except ImportError:
56     pass
57 
58 import warnings
59 
60 # urllib3's DependencyWarnings should be silenced.
61 from .packages.urllib3.exceptions import DependencyWarning
62 warnings.simplefilter('ignore', DependencyWarning)
63 
64 from . import utils
65 from .models import Request, Response, PreparedRequest
66 from .api import request, get, head, post, patch, put, delete, options
67 from .sessions import session, Session
68 from .status_codes import codes
69 from .exceptions import (
70     RequestException, Timeout, URLRequired,
71     TooManyRedirects, HTTPError, ConnectionError,
72     FileModeWarning, ConnectTimeout, ReadTimeout
73 )
74 
75 # Set default logging handler to avoid "No handler found" warnings.
76 import logging
77 try:  # Python 2.7+
78     from logging import NullHandler
79 except ImportError:
80     class NullHandler(logging.Handler):
81         def emit(self, record):
82             pass
83 
84 logging.getLogger(__name__).addHandler(NullHandler())
85 
86 import warnings
87 
88 # FileModeWarnings go off per the default.
89 warnings.simplefilter('default', FileModeWarning, append=True)
90
```

Path: `pip/_vendor/requests/compat.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 """
4 pythoncompat
5 """
6 
7 from .packages import chardet
8 
9 import sys
10 
11 # -------
12 # Pythons
13 # -------
14 
15 # Syntax sugar.
16 _ver = sys.version_info
17 
18 #: Python 2.x?
19 is_py2 = (_ver[0] == 2)
20 
21 #: Python 3.x?
22 is_py3 = (_ver[0] == 3)
23 
24 try:
25     import simplejson as json
26 except (ImportError, SyntaxError):
27     # simplejson does not support Python 3.2, it throws a SyntaxError
28     # because of u'...' Unicode literals.
29     import json
30 
31 # ---------
32 # Specifics
33 # ---------
34 
35 if is_py2:
36     from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass
37     from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
38     from urllib2 import parse_http_list
39     import cookielib
40     from Cookie import Morsel
41     from StringIO import StringIO
42     from .packages.urllib3.packages.ordered_dict import OrderedDict
43 
44     builtin_str = str
45     bytes = str
46     str = unicode
47     basestring = basestring
48     numeric_types = (int, long, float)
49 
50 elif is_py3:
51     from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
52     from urllib.request import parse_http_list, getproxies, proxy_bypass
53     from http import cookiejar as cookielib
54     from http.cookies import Morsel
55     from io import StringIO
56     from collections import OrderedDict
57 
58     builtin_str = str
59     str = str
60     bytes = bytes
61     basestring = (str, bytes)
62     numeric_types = (int, float)
63
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pip/_vendor/requests/__init__.py b/pip/_vendor/requests/__init__.py
--- a/pip/_vendor/requests/__init__.py
+++ b/pip/_vendor/requests/__init__.py
@@ -49,11 +49,13 @@
 __copyright__ = 'Copyright 2016 Kenneth Reitz'
 
 # Attempt to enable urllib3's SNI support, if possible
-try:
-    from .packages.urllib3.contrib import pyopenssl
-    pyopenssl.inject_into_urllib3()
-except ImportError:
-    pass
+# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this
+#       prevents upgrading cryptography.
+# try:
+#     from .packages.urllib3.contrib import pyopenssl
+#     pyopenssl.inject_into_urllib3()
+# except ImportError:
+#     pass
 
 import warnings
 
diff --git a/pip/_vendor/requests/compat.py b/pip/_vendor/requests/compat.py
--- a/pip/_vendor/requests/compat.py
+++ b/pip/_vendor/requests/compat.py
@@ -21,12 +21,14 @@
 #: Python 3.x?
 is_py3 = (_ver[0] == 3)
 
-try:
-    import simplejson as json
-except (ImportError, SyntaxError):
-    # simplejson does not support Python 3.2, it throws a SyntaxError
-    # because of u'...' Unicode literals.
-    import json
+# Note: We've patched out simplejson support in pip because it prevents
+#       upgrading simplejson on Windows.
+# try:
+#     import simplejson as json
+# except (ImportError, SyntaxError):
+#     # simplejson does not support Python 3.2, it throws a SyntaxError
+#     # because of u'...' Unicode literals.
+import json
 
 # ---------
 # Specifics

{"golden_diff": "diff --git a/pip/_vendor/requests/__init__.py b/pip/_vendor/requests/__init__.py\n--- a/pip/_vendor/requests/__init__.py\n+++ b/pip/_vendor/requests/__init__.py\n@@ -49,11 +49,13 @@\n __copyright__ = 'Copyright 2016 Kenneth Reitz'\n \n # Attempt to enable urllib3's SNI support, if possible\n-try:\n-    from .packages.urllib3.contrib import pyopenssl\n-    pyopenssl.inject_into_urllib3()\n-except ImportError:\n-    pass\n+# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this\n+#       prevents upgrading cryptography.\n+# try:\n+#     from .packages.urllib3.contrib import pyopenssl\n+#     pyopenssl.inject_into_urllib3()\n+# except ImportError:\n+#     pass\n \n import warnings\n \ndiff --git a/pip/_vendor/requests/compat.py b/pip/_vendor/requests/compat.py\n--- a/pip/_vendor/requests/compat.py\n+++ b/pip/_vendor/requests/compat.py\n@@ -21,12 +21,14 @@\n #: Python 3.x?\n is_py3 = (_ver[0] == 3)\n \n-try:\n-    import simplejson as json\n-except (ImportError, SyntaxError):\n-    # simplejson does not support Python 3.2, it throws a SyntaxError\n-    # because of u'...' Unicode literals.\n-    import json\n+# Note: We've patched out simplejson support in pip because it prevents\n+#       upgrading simplejson on Windows.\n+# try:\n+#     import simplejson as json\n+# except (ImportError, SyntaxError):\n+#     # simplejson does not support Python 3.2, it throws a SyntaxError\n+#     # because of u'...' Unicode literals.\n+import json\n \n # ---------\n # Specifics\n", "issue": "pip on windows\nPrerequisites:\nWindows\npython 2.7\nsetuptools 3.6\neasy_install\npip\n\nProblem:\nwe have a requirements file that contains \"pyinstaller\" package dependency. I suppose that it somehow depends on cryptography and it in its turn somehow depends on cffi package and that's why it tries to install it as well. For now we specify this depency in a following way:\n\npyinstaller==2.1.1dev-89e99dd # from requirements file.\n\nNext we try to install our pack of requirements with \n\npip -f {our additional private repository} -U -egg -r {requirements file name}\n\nFrom the build log screenshot attached you can see the following string(build_log attachment):\n\n[12:59:39]:  [Step 7/15] Installed c:\\users\\administrator\\envs\\python27-32bit\\lib\\site-packages\\cryptography-0.3-py2.7-win32.egg\n[12:59:39]:  [Step 7/15] \n[12:59:39]:  [Step 7/15] error: c:\\buildagent\\temp\\buildtmp\\easy_install-snsbak\\cryptography-0.3\\cffi-0.8.2-py2.7-win32.egg_cffi_backend.pyd: Access is denied\n\nI've done a few of investigation and attached a screenshot of related file activity with a highlighted important items (file_activity_list attachment). It seems that python cannod delete this _cffi_backend.pyd file. A few more investigation revealed that the file creation mode allows to delete this file(file_open_result attachment). From the event properties(event_properties attachment) I see that all related modules appear as if they are loaded using LoadLibray windows api, that's how it supposed to be done with python C extensions if we want to use this code. But it appears to me that someone forgot to unload all these modules before trying to delete them and that's why the file cannot be deleted. Please refer to _cffi_backend_loading attachment - it proves _cffi_backend.pyd is being loaded as a library(WinDbg screen). And the very next screenshot is the state of pip install command when WinDbg broke on module load - _break_python_screen attachment. Yet I pointed out the same problem if I just parse this requirements file with pkg_tools and specify install_requires setup's argument with these requirements - setup develop fails with the same result. As to me this problem more relates to easy_install/setuptools core. And yet to mention - without '--egg' argument the problem doesn't reproduce.\n\n![file_activity_list](https://cloud.githubusercontent.com/assets/7242142/3082926/4def0fa4-e4db-11e3-8e14-37f52ea5b2ee.png)\n![event_properties](https://cloud.githubusercontent.com/assets/7242142/3082956/ba432474-e4db-11e3-8d6f-5d0996c35a44.png)\n![file_open_result](https://cloud.githubusercontent.com/assets/7242142/3082983/1417a8e4-e4dc-11e3-9289-0bf61c7cf2c9.png)\n\n![build_log](https://cloud.githubusercontent.com/assets/7242142/3082887/b8bc80e2-e4da-11e3-945a-a0c1137bb6bb.png)\n![_cffi_backend_loading](https://cloud.githubusercontent.com/assets/7242142/3160093/dddbe462-eb1a-11e3-8e08-48cfade1b261.png)\n![_break_python_screen](https://cloud.githubusercontent.com/assets/7242142/3160112/29cc9c0e-eb1b-11e3-88a6-2601f7a8dbe5.png)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n#   __\n#  /__)  _  _     _   _ _/   _\n# / (   (- (/ (/ (- _)  /  _)\n#          /\n\n\"\"\"\nRequests HTTP library\n~~~~~~~~~~~~~~~~~~~~~\n\nRequests is an HTTP library, written in Python, for human beings. Basic GET\nusage:\n\n   >>> import requests\n   >>> r = requests.get('https://www.python.org')\n   >>> r.status_code\n   200\n   >>> 'Python is a programming language' in r.content\n   True\n\n... or POST:\n\n   >>> payload = dict(key1='value1', key2='value2')\n   >>> r = requests.post('http://httpbin.org/post', data=payload)\n   >>> print(r.text)\n   {\n     ...\n     \"form\": {\n       \"key2\": \"value2\",\n       \"key1\": \"value1\"\n     },\n     ...\n   }\n\nThe other HTTP methods are supported - see `requests.api`. Full documentation\nis at <http://python-requests.org>.\n\n:copyright: (c) 2016 by Kenneth Reitz.\n:license: Apache 2.0, see LICENSE for more details.\n\n\"\"\"\n\n__title__ = 'requests'\n__version__ = '2.10.0'\n__build__ = 0x021000\n__author__ = 'Kenneth Reitz'\n__license__ = 'Apache 2.0'\n__copyright__ = 'Copyright 2016 Kenneth Reitz'\n\n# Attempt to enable urllib3's SNI support, if possible\ntry:\n    from .packages.urllib3.contrib import pyopenssl\n    pyopenssl.inject_into_urllib3()\nexcept ImportError:\n    pass\n\nimport warnings\n\n# urllib3's DependencyWarnings should be silenced.\nfrom .packages.urllib3.exceptions import DependencyWarning\nwarnings.simplefilter('ignore', DependencyWarning)\n\nfrom . import utils\nfrom .models import Request, Response, PreparedRequest\nfrom .api import request, get, head, post, patch, put, delete, options\nfrom .sessions import session, Session\nfrom .status_codes import codes\nfrom .exceptions import (\n    RequestException, Timeout, URLRequired,\n    TooManyRedirects, HTTPError, ConnectionError,\n    FileModeWarning, ConnectTimeout, ReadTimeout\n)\n\n# Set default logging handler to avoid \"No handler found\" warnings.\nimport logging\ntry:  # Python 2.7+\n    from logging import NullHandler\nexcept ImportError:\n    class NullHandler(logging.Handler):\n        def emit(self, record):\n            pass\n\nlogging.getLogger(__name__).addHandler(NullHandler())\n\nimport warnings\n\n# FileModeWarnings go off per the default.\nwarnings.simplefilter('default', FileModeWarning, append=True)\n", "path": "pip/_vendor/requests/__init__.py"}, {"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\npythoncompat\n\"\"\"\n\nfrom .packages import chardet\n\nimport sys\n\n# -------\n# Pythons\n# -------\n\n# Syntax sugar.\n_ver = sys.version_info\n\n#: Python 2.x?\nis_py2 = (_ver[0] == 2)\n\n#: Python 3.x?\nis_py3 = (_ver[0] == 3)\n\ntry:\n    import simplejson as json\nexcept (ImportError, SyntaxError):\n    # simplejson does not support Python 3.2, it throws a SyntaxError\n    # because of u'...' Unicode literals.\n    import json\n\n# ---------\n# Specifics\n# ---------\n\nif is_py2:\n    from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass\n    from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag\n    from urllib2 import parse_http_list\n    import cookielib\n    from Cookie import Morsel\n    from StringIO import StringIO\n    from .packages.urllib3.packages.ordered_dict import OrderedDict\n\n    builtin_str = str\n    bytes = str\n    str = unicode\n    basestring = basestring\n    numeric_types = (int, long, float)\n\nelif is_py3:\n    from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag\n    from urllib.request import parse_http_list, getproxies, proxy_bypass\n    from http import cookiejar as cookielib\n    from http.cookies import Morsel\n    from io import StringIO\n    from collections import OrderedDict\n\n    builtin_str = str\n    str = str\n    bytes = bytes\n    basestring = (str, bytes)\n    numeric_types = (int, float)\n", "path": "pip/_vendor/requests/compat.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n#   __\n#  /__)  _  _     _   _ _/   _\n# / (   (- (/ (/ (- _)  /  _)\n#          /\n\n\"\"\"\nRequests HTTP library\n~~~~~~~~~~~~~~~~~~~~~\n\nRequests is an HTTP library, written in Python, for human beings. Basic GET\nusage:\n\n   >>> import requests\n   >>> r = requests.get('https://www.python.org')\n   >>> r.status_code\n   200\n   >>> 'Python is a programming language' in r.content\n   True\n\n... or POST:\n\n   >>> payload = dict(key1='value1', key2='value2')\n   >>> r = requests.post('http://httpbin.org/post', data=payload)\n   >>> print(r.text)\n   {\n     ...\n     \"form\": {\n       \"key2\": \"value2\",\n       \"key1\": \"value1\"\n     },\n     ...\n   }\n\nThe other HTTP methods are supported - see `requests.api`. Full documentation\nis at <http://python-requests.org>.\n\n:copyright: (c) 2016 by Kenneth Reitz.\n:license: Apache 2.0, see LICENSE for more details.\n\n\"\"\"\n\n__title__ = 'requests'\n__version__ = '2.10.0'\n__build__ = 0x021000\n__author__ = 'Kenneth Reitz'\n__license__ = 'Apache 2.0'\n__copyright__ = 'Copyright 2016 Kenneth Reitz'\n\n# Attempt to enable urllib3's SNI support, if possible\n# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this\n#       prevents upgrading cryptography.\n# try:\n#     from .packages.urllib3.contrib import pyopenssl\n#     pyopenssl.inject_into_urllib3()\n# except ImportError:\n#     pass\n\nimport warnings\n\n# urllib3's DependencyWarnings should be silenced.\nfrom .packages.urllib3.exceptions import DependencyWarning\nwarnings.simplefilter('ignore', DependencyWarning)\n\nfrom . import utils\nfrom .models import Request, Response, PreparedRequest\nfrom .api import request, get, head, post, patch, put, delete, options\nfrom .sessions import session, Session\nfrom .status_codes import codes\nfrom .exceptions import (\n    RequestException, Timeout, URLRequired,\n    TooManyRedirects, HTTPError, ConnectionError,\n    FileModeWarning, ConnectTimeout, ReadTimeout\n)\n\n# Set default logging handler to avoid \"No handler found\" warnings.\nimport logging\ntry:  # Python 2.7+\n    from logging import NullHandler\nexcept ImportError:\n    class NullHandler(logging.Handler):\n        def emit(self, record):\n            pass\n\nlogging.getLogger(__name__).addHandler(NullHandler())\n\nimport warnings\n\n# FileModeWarnings go off per the default.\nwarnings.simplefilter('default', FileModeWarning, append=True)\n", "path": "pip/_vendor/requests/__init__.py"}, {"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\npythoncompat\n\"\"\"\n\nfrom .packages import chardet\n\nimport sys\n\n# -------\n# Pythons\n# -------\n\n# Syntax sugar.\n_ver = sys.version_info\n\n#: Python 2.x?\nis_py2 = (_ver[0] == 2)\n\n#: Python 3.x?\nis_py3 = (_ver[0] == 3)\n\n# Note: We've patched out simplejson support in pip because it prevents\n#       upgrading simplejson on Windows.\n# try:\n#     import simplejson as json\n# except (ImportError, SyntaxError):\n#     # simplejson does not support Python 3.2, it throws a SyntaxError\n#     # because of u'...' Unicode literals.\nimport json\n\n# ---------\n# Specifics\n# ---------\n\nif is_py2:\n    from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass\n    from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag\n    from urllib2 import parse_http_list\n    import cookielib\n    from Cookie import Morsel\n    from StringIO import StringIO\n    from .packages.urllib3.packages.ordered_dict import OrderedDict\n\n    builtin_str = str\n    bytes = str\n    str = unicode\n    basestring = basestring\n    numeric_types = (int, long, float)\n\nelif is_py3:\n    from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag\n    from urllib.request import parse_http_list, getproxies, proxy_bypass\n    from http import cookiejar as cookielib\n    from http.cookies import Morsel\n    from io import StringIO\n    from collections import OrderedDict\n\n    builtin_str = str\n    str = str\n    bytes = bytes\n    basestring = (str, bytes)\n    numeric_types = (int, float)\n", "path": "pip/_vendor/requests/compat.py"}]}