We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Deprecate/Drop Support for Python 3.3?
Currently Python 3.3 support is not a major headache for support (unlike 3.2) because we're largely being limited by Python 2.6 and 2.7 in terms of what features we can support. However, I think it's important to periodically look at the usage and make sure that we're not supporting Python versions that are not really being used as no matter what, each version of Python we support incurs a cost in terms of overhead for support (more build matrix items, minor incompatibilities, etc).

With that in mind, I took a look at what % of the pip initiated traffic that PyPI received in the last month to see what our usage numbers look like.

Only pip 8 initiated traffic:

```
2.7 83.8%
3.5  6.3%
3.4  5.5%
2.6  3.8%
3.3  0.3%
3.6  0.1%
3.2  0.03%
```

All pip initiated traffic:

```
2.7 86.8%
3.4  5.2%
3.5  3.9%
2.6  3.4%
3.3  0.4%
3.2  0.07%
3.6  0.04%
```

Given that 3.3 support is well under 1%, do we want to deprecate support for Python 3.3 with intent to drop support for it in either pip 9 or pip 10? For myself, I say yes-- either as a pip 9 or a pip 10 deprecation.

@pypa/pip-committers ?


--- 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/basecommand.py`
Content:
```
1 """Base Command class, and related routines"""
2 from __future__ import absolute_import
3 
4 import logging
5 import logging.config
6 import os
7 import sys
8 import optparse
9 
10 from pip import cmdoptions
11 from pip.index import PackageFinder
12 from pip.locations import running_under_virtualenv
13 from pip.download import PipSession
14 from pip.exceptions import (BadCommand, InstallationError, UninstallationError,
15                             CommandError, PreviousBuildDirError)
16 
17 from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
18 from pip.req import InstallRequirement, parse_requirements
19 from pip.status_codes import (
20     SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,
21     PREVIOUS_BUILD_DIR_ERROR,
22 )
23 from pip.utils import get_prog, normalize_path
24 from pip.utils.logging import IndentingFormatter
25 from pip.utils.outdated import pip_version_check
26 
27 
28 __all__ = ['Command']
29 
30 
31 logger = logging.getLogger(__name__)
32 
33 
34 class Command(object):
35     name = None
36     usage = None
37     hidden = False
38     log_streams = ("ext://sys.stdout", "ext://sys.stderr")
39 
40     def __init__(self, isolated=False):
41         parser_kw = {
42             'usage': self.usage,
43             'prog': '%s %s' % (get_prog(), self.name),
44             'formatter': UpdatingDefaultsHelpFormatter(),
45             'add_help_option': False,
46             'name': self.name,
47             'description': self.__doc__,
48             'isolated': isolated,
49         }
50 
51         self.parser = ConfigOptionParser(**parser_kw)
52 
53         # Commands should add options to this option group
54         optgroup_name = '%s Options' % self.name.capitalize()
55         self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
56 
57         # Add the general options
58         gen_opts = cmdoptions.make_option_group(
59             cmdoptions.general_group,
60             self.parser,
61         )
62         self.parser.add_option_group(gen_opts)
63 
64     def _build_session(self, options, retries=None, timeout=None):
65         session = PipSession(
66             cache=(
67                 normalize_path(os.path.join(options.cache_dir, "http"))
68                 if options.cache_dir else None
69             ),
70             retries=retries if retries is not None else options.retries,
71             insecure_hosts=options.trusted_hosts,
72         )
73 
74         # Handle custom ca-bundles from the user
75         if options.cert:
76             session.verify = options.cert
77 
78         # Handle SSL client certificate
79         if options.client_cert:
80             session.cert = options.client_cert
81 
82         # Handle timeouts
83         if options.timeout or timeout:
84             session.timeout = (
85                 timeout if timeout is not None else options.timeout
86             )
87 
88         # Handle configured proxies
89         if options.proxy:
90             session.proxies = {
91                 "http": options.proxy,
92                 "https": options.proxy,
93             }
94 
95         # Determine if we can prompt the user for authentication or not
96         session.auth.prompting = not options.no_input
97 
98         return session
99 
100     def parse_args(self, args):
101         # factored out for testability
102         return self.parser.parse_args(args)
103 
104     def main(self, args):
105         options, args = self.parse_args(args)
106 
107         if options.quiet:
108             if options.quiet == 1:
109                 level = "WARNING"
110             if options.quiet == 2:
111                 level = "ERROR"
112             else:
113                 level = "CRITICAL"
114         elif options.verbose:
115             level = "DEBUG"
116         else:
117             level = "INFO"
118 
119         # The root logger should match the "console" level *unless* we
120         # specified "--log" to send debug logs to a file.
121         root_level = level
122         if options.log:
123             root_level = "DEBUG"
124 
125         logging.config.dictConfig({
126             "version": 1,
127             "disable_existing_loggers": False,
128             "filters": {
129                 "exclude_warnings": {
130                     "()": "pip.utils.logging.MaxLevelFilter",
131                     "level": logging.WARNING,
132                 },
133             },
134             "formatters": {
135                 "indent": {
136                     "()": IndentingFormatter,
137                     "format": "%(message)s",
138                 },
139             },
140             "handlers": {
141                 "console": {
142                     "level": level,
143                     "class": "pip.utils.logging.ColorizedStreamHandler",
144                     "stream": self.log_streams[0],
145                     "filters": ["exclude_warnings"],
146                     "formatter": "indent",
147                 },
148                 "console_errors": {
149                     "level": "WARNING",
150                     "class": "pip.utils.logging.ColorizedStreamHandler",
151                     "stream": self.log_streams[1],
152                     "formatter": "indent",
153                 },
154                 "user_log": {
155                     "level": "DEBUG",
156                     "class": "pip.utils.logging.BetterRotatingFileHandler",
157                     "filename": options.log or "/dev/null",
158                     "delay": True,
159                     "formatter": "indent",
160                 },
161             },
162             "root": {
163                 "level": root_level,
164                 "handlers": list(filter(None, [
165                     "console",
166                     "console_errors",
167                     "user_log" if options.log else None,
168                 ])),
169             },
170             # Disable any logging besides WARNING unless we have DEBUG level
171             # logging enabled. These use both pip._vendor and the bare names
172             # for the case where someone unbundles our libraries.
173             "loggers": dict(
174                 (
175                     name,
176                     {
177                         "level": (
178                             "WARNING"
179                             if level in ["INFO", "ERROR"]
180                             else "DEBUG"
181                         ),
182                     },
183                 )
184                 for name in ["pip._vendor", "distlib", "requests", "urllib3"]
185             ),
186         })
187 
188         # TODO: try to get these passing down from the command?
189         #      without resorting to os.environ to hold these.
190 
191         if options.no_input:
192             os.environ['PIP_NO_INPUT'] = '1'
193 
194         if options.exists_action:
195             os.environ['PIP_EXISTS_ACTION'] = ' '.join(options.exists_action)
196 
197         if options.require_venv:
198             # If a venv is required check if it can really be found
199             if not running_under_virtualenv():
200                 logger.critical(
201                     'Could not find an activated virtualenv (required).'
202                 )
203                 sys.exit(VIRTUALENV_NOT_FOUND)
204 
205         try:
206             status = self.run(options, args)
207             # FIXME: all commands should return an exit status
208             # and when it is done, isinstance is not needed anymore
209             if isinstance(status, int):
210                 return status
211         except PreviousBuildDirError as exc:
212             logger.critical(str(exc))
213             logger.debug('Exception information:', exc_info=True)
214 
215             return PREVIOUS_BUILD_DIR_ERROR
216         except (InstallationError, UninstallationError, BadCommand) as exc:
217             logger.critical(str(exc))
218             logger.debug('Exception information:', exc_info=True)
219 
220             return ERROR
221         except CommandError as exc:
222             logger.critical('ERROR: %s', exc)
223             logger.debug('Exception information:', exc_info=True)
224 
225             return ERROR
226         except KeyboardInterrupt:
227             logger.critical('Operation cancelled by user')
228             logger.debug('Exception information:', exc_info=True)
229 
230             return ERROR
231         except:
232             logger.critical('Exception:', exc_info=True)
233 
234             return UNKNOWN_ERROR
235         finally:
236             # Check if we're using the latest version of pip available
237             if (not options.disable_pip_version_check and not
238                     getattr(options, "no_index", False)):
239                 with self._build_session(
240                         options,
241                         retries=0,
242                         timeout=min(5, options.timeout)) as session:
243                     pip_version_check(session)
244 
245         return SUCCESS
246 
247 
248 class RequirementCommand(Command):
249 
250     @staticmethod
251     def populate_requirement_set(requirement_set, args, options, finder,
252                                  session, name, wheel_cache):
253         """
254         Marshal cmd line args into a requirement set.
255         """
256         for filename in options.constraints:
257             for req in parse_requirements(
258                     filename,
259                     constraint=True, finder=finder, options=options,
260                     session=session, wheel_cache=wheel_cache):
261                 requirement_set.add_requirement(req)
262 
263         for req in args:
264             requirement_set.add_requirement(
265                 InstallRequirement.from_line(
266                     req, None, isolated=options.isolated_mode,
267                     wheel_cache=wheel_cache
268                 )
269             )
270 
271         for req in options.editables:
272             requirement_set.add_requirement(
273                 InstallRequirement.from_editable(
274                     req,
275                     isolated=options.isolated_mode,
276                     wheel_cache=wheel_cache
277                 )
278             )
279 
280         for filename in options.requirements:
281             for req in parse_requirements(
282                     filename,
283                     finder=finder, options=options, session=session,
284                     wheel_cache=wheel_cache):
285                 requirement_set.add_requirement(req)
286         # If --require-hashes was a line in a requirements file, tell
287         # RequirementSet about it:
288         requirement_set.require_hashes = options.require_hashes
289 
290         if not (args or options.editables or options.requirements):
291             opts = {'name': name}
292             if options.find_links:
293                 raise CommandError(
294                     'You must give at least one requirement to %(name)s '
295                     '(maybe you meant "pip %(name)s %(links)s"?)' %
296                     dict(opts, links=' '.join(options.find_links)))
297             else:
298                 raise CommandError(
299                     'You must give at least one requirement to %(name)s '
300                     '(see "pip help %(name)s")' % opts)
301 
302     def _build_package_finder(self, options, session,
303                               platform=None, python_versions=None,
304                               abi=None, implementation=None):
305         """
306         Create a package finder appropriate to this requirement command.
307         """
308         index_urls = [options.index_url] + options.extra_index_urls
309         if options.no_index:
310             logger.debug('Ignoring indexes: %s', ','.join(index_urls))
311             index_urls = []
312 
313         return PackageFinder(
314             find_links=options.find_links,
315             format_control=options.format_control,
316             index_urls=index_urls,
317             trusted_hosts=options.trusted_hosts,
318             allow_all_prereleases=options.pre,
319             process_dependency_links=options.process_dependency_links,
320             session=session,
321             platform=platform,
322             versions=python_versions,
323             abi=abi,
324             implementation=implementation,
325         )
326
```
--- 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/basecommand.py b/pip/basecommand.py
--- a/pip/basecommand.py
+++ b/pip/basecommand.py
@@ -6,6 +6,7 @@
 import os
 import sys
 import optparse
+import warnings
 
 from pip import cmdoptions
 from pip.index import PackageFinder
@@ -20,7 +21,7 @@
     SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,
     PREVIOUS_BUILD_DIR_ERROR,
 )
-from pip.utils import get_prog, normalize_path
+from pip.utils import deprecation, get_prog, normalize_path
 from pip.utils.logging import IndentingFormatter
 from pip.utils.outdated import pip_version_check
 
@@ -185,6 +186,13 @@
             ),
         })
 
+        if sys.version_info[:2] == (3, 3):
+            warnings.warn(
+                "Python 3.3 supported has been deprecated and support for it "
+                "will be dropped in the future. Please upgrade your Python.",
+                deprecation.RemovedInPip11Warning,
+            )
+
         # TODO: try to get these passing down from the command?
         #      without resorting to os.environ to hold these.

{"golden_diff": "diff --git a/pip/basecommand.py b/pip/basecommand.py\n--- a/pip/basecommand.py\n+++ b/pip/basecommand.py\n@@ -6,6 +6,7 @@\n import os\n import sys\n import optparse\n+import warnings\n \n from pip import cmdoptions\n from pip.index import PackageFinder\n@@ -20,7 +21,7 @@\n     SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,\n     PREVIOUS_BUILD_DIR_ERROR,\n )\n-from pip.utils import get_prog, normalize_path\n+from pip.utils import deprecation, get_prog, normalize_path\n from pip.utils.logging import IndentingFormatter\n from pip.utils.outdated import pip_version_check\n \n@@ -185,6 +186,13 @@\n             ),\n         })\n \n+        if sys.version_info[:2] == (3, 3):\n+            warnings.warn(\n+                \"Python 3.3 supported has been deprecated and support for it \"\n+                \"will be dropped in the future. Please upgrade your Python.\",\n+                deprecation.RemovedInPip11Warning,\n+            )\n+\n         # TODO: try to get these passing down from the command?\n         #      without resorting to os.environ to hold these.\n", "issue": "Deprecate/Drop Support for Python 3.3?\nCurrently Python 3.3 support is not a major headache for support (unlike 3.2) because we're largely being limited by Python 2.6 and 2.7 in terms of what features we can support. However, I think it's important to periodically look at the usage and make sure that we're not supporting Python versions that are not really being used as no matter what, each version of Python we support incurs a cost in terms of overhead for support (more build matrix items, minor incompatibilities, etc).\n\nWith that in mind, I took a look at what % of the pip initiated traffic that PyPI received in the last month to see what our usage numbers look like.\n\nOnly pip 8 initiated traffic:\n\n```\n2.7 83.8%\n3.5  6.3%\n3.4  5.5%\n2.6  3.8%\n3.3  0.3%\n3.6  0.1%\n3.2  0.03%\n```\n\nAll pip initiated traffic:\n\n```\n2.7 86.8%\n3.4  5.2%\n3.5  3.9%\n2.6  3.4%\n3.3  0.4%\n3.2  0.07%\n3.6  0.04%\n```\n\nGiven that 3.3 support is well under 1%, do we want to deprecate support for Python 3.3 with intent to drop support for it in either pip 9 or pip 10? For myself, I say yes-- either as a pip 9 or a pip 10 deprecation.\n\n@pypa/pip-committers ?\n\n", "before_files": [{"content": "\"\"\"Base Command class, and related routines\"\"\"\nfrom __future__ import absolute_import\n\nimport logging\nimport logging.config\nimport os\nimport sys\nimport optparse\n\nfrom pip import cmdoptions\nfrom pip.index import PackageFinder\nfrom pip.locations import running_under_virtualenv\nfrom pip.download import PipSession\nfrom pip.exceptions import (BadCommand, InstallationError, UninstallationError,\n                            CommandError, PreviousBuildDirError)\n\nfrom pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter\nfrom pip.req import InstallRequirement, parse_requirements\nfrom pip.status_codes import (\n    SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,\n    PREVIOUS_BUILD_DIR_ERROR,\n)\nfrom pip.utils import get_prog, normalize_path\nfrom pip.utils.logging import IndentingFormatter\nfrom pip.utils.outdated import pip_version_check\n\n\n__all__ = ['Command']\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass Command(object):\n    name = None\n    usage = None\n    hidden = False\n    log_streams = (\"ext://sys.stdout\", \"ext://sys.stderr\")\n\n    def __init__(self, isolated=False):\n        parser_kw = {\n            'usage': self.usage,\n            'prog': '%s %s' % (get_prog(), self.name),\n            'formatter': UpdatingDefaultsHelpFormatter(),\n            'add_help_option': False,\n            'name': self.name,\n            'description': self.__doc__,\n            'isolated': isolated,\n        }\n\n        self.parser = ConfigOptionParser(**parser_kw)\n\n        # Commands should add options to this option group\n        optgroup_name = '%s Options' % self.name.capitalize()\n        self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)\n\n        # Add the general options\n        gen_opts = cmdoptions.make_option_group(\n            cmdoptions.general_group,\n            self.parser,\n        )\n        self.parser.add_option_group(gen_opts)\n\n    def _build_session(self, options, retries=None, timeout=None):\n        session = PipSession(\n            cache=(\n                normalize_path(os.path.join(options.cache_dir, \"http\"))\n                if options.cache_dir else None\n            ),\n            retries=retries if retries is not None else options.retries,\n            insecure_hosts=options.trusted_hosts,\n        )\n\n        # Handle custom ca-bundles from the user\n        if options.cert:\n            session.verify = options.cert\n\n        # Handle SSL client certificate\n        if options.client_cert:\n            session.cert = options.client_cert\n\n        # Handle timeouts\n        if options.timeout or timeout:\n            session.timeout = (\n                timeout if timeout is not None else options.timeout\n            )\n\n        # Handle configured proxies\n        if options.proxy:\n            session.proxies = {\n                \"http\": options.proxy,\n                \"https\": options.proxy,\n            }\n\n        # Determine if we can prompt the user for authentication or not\n        session.auth.prompting = not options.no_input\n\n        return session\n\n    def parse_args(self, args):\n        # factored out for testability\n        return self.parser.parse_args(args)\n\n    def main(self, args):\n        options, args = self.parse_args(args)\n\n        if options.quiet:\n            if options.quiet == 1:\n                level = \"WARNING\"\n            if options.quiet == 2:\n                level = \"ERROR\"\n            else:\n                level = \"CRITICAL\"\n        elif options.verbose:\n            level = \"DEBUG\"\n        else:\n            level = \"INFO\"\n\n        # The root logger should match the \"console\" level *unless* we\n        # specified \"--log\" to send debug logs to a file.\n        root_level = level\n        if options.log:\n            root_level = \"DEBUG\"\n\n        logging.config.dictConfig({\n            \"version\": 1,\n            \"disable_existing_loggers\": False,\n            \"filters\": {\n                \"exclude_warnings\": {\n                    \"()\": \"pip.utils.logging.MaxLevelFilter\",\n                    \"level\": logging.WARNING,\n                },\n            },\n            \"formatters\": {\n                \"indent\": {\n                    \"()\": IndentingFormatter,\n                    \"format\": \"%(message)s\",\n                },\n            },\n            \"handlers\": {\n                \"console\": {\n                    \"level\": level,\n                    \"class\": \"pip.utils.logging.ColorizedStreamHandler\",\n                    \"stream\": self.log_streams[0],\n                    \"filters\": [\"exclude_warnings\"],\n                    \"formatter\": \"indent\",\n                },\n                \"console_errors\": {\n                    \"level\": \"WARNING\",\n                    \"class\": \"pip.utils.logging.ColorizedStreamHandler\",\n                    \"stream\": self.log_streams[1],\n                    \"formatter\": \"indent\",\n                },\n                \"user_log\": {\n                    \"level\": \"DEBUG\",\n                    \"class\": \"pip.utils.logging.BetterRotatingFileHandler\",\n                    \"filename\": options.log or \"/dev/null\",\n                    \"delay\": True,\n                    \"formatter\": \"indent\",\n                },\n            },\n            \"root\": {\n                \"level\": root_level,\n                \"handlers\": list(filter(None, [\n                    \"console\",\n                    \"console_errors\",\n                    \"user_log\" if options.log else None,\n                ])),\n            },\n            # Disable any logging besides WARNING unless we have DEBUG level\n            # logging enabled. These use both pip._vendor and the bare names\n            # for the case where someone unbundles our libraries.\n            \"loggers\": dict(\n                (\n                    name,\n                    {\n                        \"level\": (\n                            \"WARNING\"\n                            if level in [\"INFO\", \"ERROR\"]\n                            else \"DEBUG\"\n                        ),\n                    },\n                )\n                for name in [\"pip._vendor\", \"distlib\", \"requests\", \"urllib3\"]\n            ),\n        })\n\n        # TODO: try to get these passing down from the command?\n        #      without resorting to os.environ to hold these.\n\n        if options.no_input:\n            os.environ['PIP_NO_INPUT'] = '1'\n\n        if options.exists_action:\n            os.environ['PIP_EXISTS_ACTION'] = ' '.join(options.exists_action)\n\n        if options.require_venv:\n            # If a venv is required check if it can really be found\n            if not running_under_virtualenv():\n                logger.critical(\n                    'Could not find an activated virtualenv (required).'\n                )\n                sys.exit(VIRTUALENV_NOT_FOUND)\n\n        try:\n            status = self.run(options, args)\n            # FIXME: all commands should return an exit status\n            # and when it is done, isinstance is not needed anymore\n            if isinstance(status, int):\n                return status\n        except PreviousBuildDirError as exc:\n            logger.critical(str(exc))\n            logger.debug('Exception information:', exc_info=True)\n\n            return PREVIOUS_BUILD_DIR_ERROR\n        except (InstallationError, UninstallationError, BadCommand) as exc:\n            logger.critical(str(exc))\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except CommandError as exc:\n            logger.critical('ERROR: %s', exc)\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except KeyboardInterrupt:\n            logger.critical('Operation cancelled by user')\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except:\n            logger.critical('Exception:', exc_info=True)\n\n            return UNKNOWN_ERROR\n        finally:\n            # Check if we're using the latest version of pip available\n            if (not options.disable_pip_version_check and not\n                    getattr(options, \"no_index\", False)):\n                with self._build_session(\n                        options,\n                        retries=0,\n                        timeout=min(5, options.timeout)) as session:\n                    pip_version_check(session)\n\n        return SUCCESS\n\n\nclass RequirementCommand(Command):\n\n    @staticmethod\n    def populate_requirement_set(requirement_set, args, options, finder,\n                                 session, name, wheel_cache):\n        \"\"\"\n        Marshal cmd line args into a requirement set.\n        \"\"\"\n        for filename in options.constraints:\n            for req in parse_requirements(\n                    filename,\n                    constraint=True, finder=finder, options=options,\n                    session=session, wheel_cache=wheel_cache):\n                requirement_set.add_requirement(req)\n\n        for req in args:\n            requirement_set.add_requirement(\n                InstallRequirement.from_line(\n                    req, None, isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache\n                )\n            )\n\n        for req in options.editables:\n            requirement_set.add_requirement(\n                InstallRequirement.from_editable(\n                    req,\n                    isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache\n                )\n            )\n\n        for filename in options.requirements:\n            for req in parse_requirements(\n                    filename,\n                    finder=finder, options=options, session=session,\n                    wheel_cache=wheel_cache):\n                requirement_set.add_requirement(req)\n        # If --require-hashes was a line in a requirements file, tell\n        # RequirementSet about it:\n        requirement_set.require_hashes = options.require_hashes\n\n        if not (args or options.editables or options.requirements):\n            opts = {'name': name}\n            if options.find_links:\n                raise CommandError(\n                    'You must give at least one requirement to %(name)s '\n                    '(maybe you meant \"pip %(name)s %(links)s\"?)' %\n                    dict(opts, links=' '.join(options.find_links)))\n            else:\n                raise CommandError(\n                    'You must give at least one requirement to %(name)s '\n                    '(see \"pip help %(name)s\")' % opts)\n\n    def _build_package_finder(self, options, session,\n                              platform=None, python_versions=None,\n                              abi=None, implementation=None):\n        \"\"\"\n        Create a package finder appropriate to this requirement command.\n        \"\"\"\n        index_urls = [options.index_url] + options.extra_index_urls\n        if options.no_index:\n            logger.debug('Ignoring indexes: %s', ','.join(index_urls))\n            index_urls = []\n\n        return PackageFinder(\n            find_links=options.find_links,\n            format_control=options.format_control,\n            index_urls=index_urls,\n            trusted_hosts=options.trusted_hosts,\n            allow_all_prereleases=options.pre,\n            process_dependency_links=options.process_dependency_links,\n            session=session,\n            platform=platform,\n            versions=python_versions,\n            abi=abi,\n            implementation=implementation,\n        )\n", "path": "pip/basecommand.py"}], "after_files": [{"content": "\"\"\"Base Command class, and related routines\"\"\"\nfrom __future__ import absolute_import\n\nimport logging\nimport logging.config\nimport os\nimport sys\nimport optparse\nimport warnings\n\nfrom pip import cmdoptions\nfrom pip.index import PackageFinder\nfrom pip.locations import running_under_virtualenv\nfrom pip.download import PipSession\nfrom pip.exceptions import (BadCommand, InstallationError, UninstallationError,\n                            CommandError, PreviousBuildDirError)\n\nfrom pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter\nfrom pip.req import InstallRequirement, parse_requirements\nfrom pip.status_codes import (\n    SUCCESS, ERROR, UNKNOWN_ERROR, VIRTUALENV_NOT_FOUND,\n    PREVIOUS_BUILD_DIR_ERROR,\n)\nfrom pip.utils import deprecation, get_prog, normalize_path\nfrom pip.utils.logging import IndentingFormatter\nfrom pip.utils.outdated import pip_version_check\n\n\n__all__ = ['Command']\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass Command(object):\n    name = None\n    usage = None\n    hidden = False\n    log_streams = (\"ext://sys.stdout\", \"ext://sys.stderr\")\n\n    def __init__(self, isolated=False):\n        parser_kw = {\n            'usage': self.usage,\n            'prog': '%s %s' % (get_prog(), self.name),\n            'formatter': UpdatingDefaultsHelpFormatter(),\n            'add_help_option': False,\n            'name': self.name,\n            'description': self.__doc__,\n            'isolated': isolated,\n        }\n\n        self.parser = ConfigOptionParser(**parser_kw)\n\n        # Commands should add options to this option group\n        optgroup_name = '%s Options' % self.name.capitalize()\n        self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)\n\n        # Add the general options\n        gen_opts = cmdoptions.make_option_group(\n            cmdoptions.general_group,\n            self.parser,\n        )\n        self.parser.add_option_group(gen_opts)\n\n    def _build_session(self, options, retries=None, timeout=None):\n        session = PipSession(\n            cache=(\n                normalize_path(os.path.join(options.cache_dir, \"http\"))\n                if options.cache_dir else None\n            ),\n            retries=retries if retries is not None else options.retries,\n            insecure_hosts=options.trusted_hosts,\n        )\n\n        # Handle custom ca-bundles from the user\n        if options.cert:\n            session.verify = options.cert\n\n        # Handle SSL client certificate\n        if options.client_cert:\n            session.cert = options.client_cert\n\n        # Handle timeouts\n        if options.timeout or timeout:\n            session.timeout = (\n                timeout if timeout is not None else options.timeout\n            )\n\n        # Handle configured proxies\n        if options.proxy:\n            session.proxies = {\n                \"http\": options.proxy,\n                \"https\": options.proxy,\n            }\n\n        # Determine if we can prompt the user for authentication or not\n        session.auth.prompting = not options.no_input\n\n        return session\n\n    def parse_args(self, args):\n        # factored out for testability\n        return self.parser.parse_args(args)\n\n    def main(self, args):\n        options, args = self.parse_args(args)\n\n        if options.quiet:\n            if options.quiet == 1:\n                level = \"WARNING\"\n            if options.quiet == 2:\n                level = \"ERROR\"\n            else:\n                level = \"CRITICAL\"\n        elif options.verbose:\n            level = \"DEBUG\"\n        else:\n            level = \"INFO\"\n\n        # The root logger should match the \"console\" level *unless* we\n        # specified \"--log\" to send debug logs to a file.\n        root_level = level\n        if options.log:\n            root_level = \"DEBUG\"\n\n        logging.config.dictConfig({\n            \"version\": 1,\n            \"disable_existing_loggers\": False,\n            \"filters\": {\n                \"exclude_warnings\": {\n                    \"()\": \"pip.utils.logging.MaxLevelFilter\",\n                    \"level\": logging.WARNING,\n                },\n            },\n            \"formatters\": {\n                \"indent\": {\n                    \"()\": IndentingFormatter,\n                    \"format\": \"%(message)s\",\n                },\n            },\n            \"handlers\": {\n                \"console\": {\n                    \"level\": level,\n                    \"class\": \"pip.utils.logging.ColorizedStreamHandler\",\n                    \"stream\": self.log_streams[0],\n                    \"filters\": [\"exclude_warnings\"],\n                    \"formatter\": \"indent\",\n                },\n                \"console_errors\": {\n                    \"level\": \"WARNING\",\n                    \"class\": \"pip.utils.logging.ColorizedStreamHandler\",\n                    \"stream\": self.log_streams[1],\n                    \"formatter\": \"indent\",\n                },\n                \"user_log\": {\n                    \"level\": \"DEBUG\",\n                    \"class\": \"pip.utils.logging.BetterRotatingFileHandler\",\n                    \"filename\": options.log or \"/dev/null\",\n                    \"delay\": True,\n                    \"formatter\": \"indent\",\n                },\n            },\n            \"root\": {\n                \"level\": root_level,\n                \"handlers\": list(filter(None, [\n                    \"console\",\n                    \"console_errors\",\n                    \"user_log\" if options.log else None,\n                ])),\n            },\n            # Disable any logging besides WARNING unless we have DEBUG level\n            # logging enabled. These use both pip._vendor and the bare names\n            # for the case where someone unbundles our libraries.\n            \"loggers\": dict(\n                (\n                    name,\n                    {\n                        \"level\": (\n                            \"WARNING\"\n                            if level in [\"INFO\", \"ERROR\"]\n                            else \"DEBUG\"\n                        ),\n                    },\n                )\n                for name in [\"pip._vendor\", \"distlib\", \"requests\", \"urllib3\"]\n            ),\n        })\n\n        if sys.version_info[:2] == (3, 3):\n            warnings.warn(\n                \"Python 3.3 supported has been deprecated and support for it \"\n                \"will be dropped in the future. Please upgrade your Python.\",\n                deprecation.RemovedInPip11Warning,\n            )\n\n        # TODO: try to get these passing down from the command?\n        #      without resorting to os.environ to hold these.\n\n        if options.no_input:\n            os.environ['PIP_NO_INPUT'] = '1'\n\n        if options.exists_action:\n            os.environ['PIP_EXISTS_ACTION'] = ' '.join(options.exists_action)\n\n        if options.require_venv:\n            # If a venv is required check if it can really be found\n            if not running_under_virtualenv():\n                logger.critical(\n                    'Could not find an activated virtualenv (required).'\n                )\n                sys.exit(VIRTUALENV_NOT_FOUND)\n\n        try:\n            status = self.run(options, args)\n            # FIXME: all commands should return an exit status\n            # and when it is done, isinstance is not needed anymore\n            if isinstance(status, int):\n                return status\n        except PreviousBuildDirError as exc:\n            logger.critical(str(exc))\n            logger.debug('Exception information:', exc_info=True)\n\n            return PREVIOUS_BUILD_DIR_ERROR\n        except (InstallationError, UninstallationError, BadCommand) as exc:\n            logger.critical(str(exc))\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except CommandError as exc:\n            logger.critical('ERROR: %s', exc)\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except KeyboardInterrupt:\n            logger.critical('Operation cancelled by user')\n            logger.debug('Exception information:', exc_info=True)\n\n            return ERROR\n        except:\n            logger.critical('Exception:', exc_info=True)\n\n            return UNKNOWN_ERROR\n        finally:\n            # Check if we're using the latest version of pip available\n            if (not options.disable_pip_version_check and not\n                    getattr(options, \"no_index\", False)):\n                with self._build_session(\n                        options,\n                        retries=0,\n                        timeout=min(5, options.timeout)) as session:\n                    pip_version_check(session)\n\n        return SUCCESS\n\n\nclass RequirementCommand(Command):\n\n    @staticmethod\n    def populate_requirement_set(requirement_set, args, options, finder,\n                                 session, name, wheel_cache):\n        \"\"\"\n        Marshal cmd line args into a requirement set.\n        \"\"\"\n        for filename in options.constraints:\n            for req in parse_requirements(\n                    filename,\n                    constraint=True, finder=finder, options=options,\n                    session=session, wheel_cache=wheel_cache):\n                requirement_set.add_requirement(req)\n\n        for req in args:\n            requirement_set.add_requirement(\n                InstallRequirement.from_line(\n                    req, None, isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache\n                )\n            )\n\n        for req in options.editables:\n            requirement_set.add_requirement(\n                InstallRequirement.from_editable(\n                    req,\n                    isolated=options.isolated_mode,\n                    wheel_cache=wheel_cache\n                )\n            )\n\n        for filename in options.requirements:\n            for req in parse_requirements(\n                    filename,\n                    finder=finder, options=options, session=session,\n                    wheel_cache=wheel_cache):\n                requirement_set.add_requirement(req)\n        # If --require-hashes was a line in a requirements file, tell\n        # RequirementSet about it:\n        requirement_set.require_hashes = options.require_hashes\n\n        if not (args or options.editables or options.requirements):\n            opts = {'name': name}\n            if options.find_links:\n                raise CommandError(\n                    'You must give at least one requirement to %(name)s '\n                    '(maybe you meant \"pip %(name)s %(links)s\"?)' %\n                    dict(opts, links=' '.join(options.find_links)))\n            else:\n                raise CommandError(\n                    'You must give at least one requirement to %(name)s '\n                    '(see \"pip help %(name)s\")' % opts)\n\n    def _build_package_finder(self, options, session,\n                              platform=None, python_versions=None,\n                              abi=None, implementation=None):\n        \"\"\"\n        Create a package finder appropriate to this requirement command.\n        \"\"\"\n        index_urls = [options.index_url] + options.extra_index_urls\n        if options.no_index:\n            logger.debug('Ignoring indexes: %s', ','.join(index_urls))\n            index_urls = []\n\n        return PackageFinder(\n            find_links=options.find_links,\n            format_control=options.format_control,\n            index_urls=index_urls,\n            trusted_hosts=options.trusted_hosts,\n            allow_all_prereleases=options.pre,\n            process_dependency_links=options.process_dependency_links,\n            session=session,\n            platform=platform,\n            versions=python_versions,\n            abi=abi,\n            implementation=implementation,\n        )\n", "path": "pip/basecommand.py"}]}