We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[v2] Detect unsupported Python versions and raise a helpful ImportError
We'll need to ensure our `urllib3/__init__.py` is still Python 2.x compatible for early urllib3 v2.x releases. If we detect an unsupported Python version we raise a helpful error message recommending pinning to `urllib3<2`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `noxfile.py`
Content:
```
1 import os
2 import shutil
3 import subprocess
4 
5 import nox
6 
7 # Whenever type-hints are completed on a file it should be added here so that
8 # this file will continue to be checked by mypy. Errors from other files are
9 # ignored.
10 TYPED_FILES = {
11     "src/urllib3/contrib/__init__.py",
12     "src/urllib3/exceptions.py",
13     "src/urllib3/fields.py",
14     "src/urllib3/filepost.py",
15     "src/urllib3/packages/__init__.py",
16     "src/urllib3/packages/six.py",
17     "src/urllib3/packages/ssl_match_hostname/__init__.py",
18     "src/urllib3/packages/ssl_match_hostname/_implementation.py",
19     "src/urllib3/util/queue.py",
20     "src/urllib3/util/url.py",
21 }
22 SOURCE_FILES = [
23     "docs/",
24     "dummyserver/",
25     "src/",
26     "test/",
27     "noxfile.py",
28     "setup.py",
29 ]
30 
31 
32 def tests_impl(session, extras="socks,secure,brotli"):
33     # Install deps and the package itself.
34     session.install("-r", "dev-requirements.txt")
35     session.install(f".[{extras}]")
36 
37     # Show the pip version.
38     session.run("pip", "--version")
39     # Print the Python version and bytesize.
40     session.run("python", "--version")
41     session.run("python", "-c", "import struct; print(struct.calcsize('P') * 8)")
42     # Print OpenSSL information.
43     session.run("python", "-m", "OpenSSL.debug")
44 
45     # Inspired from https://github.com/pyca/cryptography
46     # We use parallel mode and then combine here so that coverage.py will take
47     # the paths like .tox/pyXY/lib/pythonX.Y/site-packages/urllib3/__init__.py
48     # and collapse them into src/urllib3/__init__.py.
49 
50     session.run(
51         "coverage",
52         "run",
53         "--parallel-mode",
54         "-m",
55         "pytest",
56         "-r",
57         "a",
58         "--tb=native",
59         "--no-success-flaky-report",
60         *(session.posargs or ("test/",)),
61         env={"PYTHONWARNINGS": "always::DeprecationWarning"},
62     )
63     session.run("coverage", "combine")
64     session.run("coverage", "report", "-m")
65     session.run("coverage", "xml")
66 
67 
68 @nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "pypy"])
69 def test(session):
70     tests_impl(session)
71 
72 
73 @nox.session(python=["3"])
74 def google_brotli(session):
75     # https://pypi.org/project/Brotli/ is the Google version of brotli, so
76     # install it separately and don't install our brotli extra (which installs
77     # brotlipy).
78     session.install("brotli")
79     tests_impl(session, extras="socks,secure")
80 
81 
82 @nox.session()
83 def format(session):
84     """Run code formatters."""
85     session.install("black", "isort")
86     session.run("black", *SOURCE_FILES)
87     session.run("isort", *SOURCE_FILES)
88 
89     lint(session)
90 
91 
92 @nox.session
93 def lint(session):
94     session.install("flake8", "flake8-2020", "black", "isort", "mypy")
95     session.run("flake8", "--version")
96     session.run("black", "--version")
97     session.run("isort", "--version")
98     session.run("mypy", "--version")
99     session.run("black", "--check", *SOURCE_FILES)
100     session.run("isort", "--check", *SOURCE_FILES)
101     session.run("flake8", *SOURCE_FILES)
102 
103     session.log("mypy --strict src/urllib3")
104     all_errors, errors = [], []
105     process = subprocess.run(
106         ["mypy", "--strict", "src/urllib3"],
107         env=session.env,
108         text=True,
109         stdout=subprocess.PIPE,
110         stderr=subprocess.STDOUT,
111     )
112     # Ensure that mypy itself ran successfully
113     assert process.returncode in (0, 1)
114 
115     for line in process.stdout.split("\n"):
116         all_errors.append(line)
117         filepath = line.partition(":")[0]
118         if filepath.replace(".pyi", ".py") in TYPED_FILES:
119             errors.append(line)
120     session.log(f"all errors count: {len(all_errors)}")
121     if errors:
122         session.error("\n" + "\n".join(sorted(set(errors))))
123 
124 
125 @nox.session
126 def docs(session):
127     session.install("-r", "docs/requirements.txt")
128     session.install(".[socks,secure,brotli]")
129 
130     session.chdir("docs")
131     if os.path.exists("_build"):
132         shutil.rmtree("_build")
133     session.run("sphinx-build", "-b", "html", "-W", ".", "_build/html")
134
```

Path: `setup.py`
Content:
```
1 #!/usr/bin/env python
2 # This file is protected via CODEOWNERS
3 
4 import codecs
5 import os
6 import re
7 
8 from setuptools import setup
9 
10 base_path = os.path.dirname(__file__)
11 
12 # Get the version (borrowed from SQLAlchemy)
13 with open(os.path.join(base_path, "src", "urllib3", "_version.py")) as fp:
14     VERSION = (
15         re.compile(r""".*__version__ = ["'](.*?)['"]""", re.S).match(fp.read()).group(1)
16     )
17 
18 
19 with codecs.open("README.rst", encoding="utf-8") as fp:
20     # Remove reST raw directive from README as they're not allowed on PyPI
21     # Those blocks start with a newline and continue until the next newline
22     mode = None
23     lines = []
24     for line in fp:
25         if line.startswith(".. raw::"):
26             mode = "ignore_nl"
27         elif line == "\n":
28             mode = "wait_nl" if mode == "ignore_nl" else None
29 
30         if mode is None:
31             lines.append(line)
32     readme = "".join(lines)
33 
34 with codecs.open("CHANGES.rst", encoding="utf-8") as fp:
35     changes = fp.read()
36 
37 version = VERSION
38 
39 setup(
40     name="urllib3",
41     version=version,
42     description="HTTP library with thread-safe connection pooling, file post, and more.",
43     long_description="\n\n".join([readme, changes]),
44     long_description_content_type="text/x-rst",
45     classifiers=[
46         "Environment :: Web Environment",
47         "Intended Audience :: Developers",
48         "License :: OSI Approved :: MIT License",
49         "Operating System :: OS Independent",
50         "Programming Language :: Python",
51         "Programming Language :: Python :: 3",
52         "Programming Language :: Python :: 3.6",
53         "Programming Language :: Python :: 3.7",
54         "Programming Language :: Python :: 3.8",
55         "Programming Language :: Python :: 3.9",
56         "Programming Language :: Python :: 3 :: Only",
57         "Programming Language :: Python :: Implementation :: CPython",
58         "Programming Language :: Python :: Implementation :: PyPy",
59         "Topic :: Internet :: WWW/HTTP",
60         "Topic :: Software Development :: Libraries",
61     ],
62     keywords="urllib httplib threadsafe filepost http https ssl pooling",
63     author="Andrey Petrov",
64     author_email="andrey.petrov@shazow.net",
65     url="https://urllib3.readthedocs.io/",
66     project_urls={
67         "Documentation": "https://urllib3.readthedocs.io/",
68         "Code": "https://github.com/urllib3/urllib3",
69         "Issue tracker": "https://github.com/urllib3/urllib3/issues",
70     },
71     license="MIT",
72     packages=[
73         "urllib3",
74         "urllib3.packages",
75         "urllib3.packages.ssl_match_hostname",
76         "urllib3.packages.backports",
77         "urllib3.contrib",
78         "urllib3.contrib._securetransport",
79         "urllib3.util",
80     ],
81     package_dir={"": "src"},
82     requires=[],
83     python_requires=">=3.6, <4",
84     extras_require={
85         "brotli": ["brotlipy>=0.6.0"],
86         "secure": [
87             "pyOpenSSL>=0.14",
88             "cryptography>=1.3.4",
89             "idna>=2.0.0",
90             "certifi",
91         ],
92         "socks": ["PySocks>=1.5.6,<2.0,!=1.5.7"],
93     },
94 )
95
```
--- 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/noxfile.py b/noxfile.py
--- a/noxfile.py
+++ b/noxfile.py
@@ -70,6 +70,20 @@
     tests_impl(session)
 
 
+@nox.session(python=["2.7"])
+def unsupported_python2(session):
+    # Can't check both returncode and output with session.run
+    process = subprocess.run(
+        ["python", "setup.py", "install"],
+        env={**session.env},
+        text=True,
+        capture_output=True,
+    )
+    assert process.returncode == 1
+    print(process.stderr)
+    assert "Unsupported Python version" in process.stderr
+
+
 @nox.session(python=["3"])
 def google_brotli(session):
     # https://pypi.org/project/Brotli/ is the Google version of brotli, so
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -4,9 +4,38 @@
 import codecs
 import os
 import re
+import sys
 
 from setuptools import setup
 
+CURRENT_PYTHON = sys.version_info[:2]
+REQUIRED_PYTHON = (3, 6)
+
+# This check and everything above must remain compatible with Python 2.7.
+if CURRENT_PYTHON < REQUIRED_PYTHON:
+    sys.stderr.write(
+        """
+==========================
+Unsupported Python version
+==========================
+This version of urllib3 requires Python {}.{}, but you're trying to
+install it on Python {}.{}.
+This may be because you are using a version of pip that doesn't
+understand the python_requires classifier. Make sure you
+have pip >= 9.0 and setuptools >= 24.2, then try again:
+    $ python -m pip install --upgrade pip setuptools
+    $ python -m pip install urllib3
+This will install the latest version of urllib3 which works on your
+version of Python. If you can't upgrade your pip (or Python), request
+an older version of urllib3:
+    $ python -m pip install "urllib3<2"
+""".format(
+            *(REQUIRED_PYTHON + CURRENT_PYTHON)
+        )
+    )
+    sys.exit(1)
+
+
 base_path = os.path.dirname(__file__)
 
 # Get the version (borrowed from SQLAlchemy)

{"golden_diff": "diff --git a/noxfile.py b/noxfile.py\n--- a/noxfile.py\n+++ b/noxfile.py\n@@ -70,6 +70,20 @@\n     tests_impl(session)\n \n \n+@nox.session(python=[\"2.7\"])\n+def unsupported_python2(session):\n+    # Can't check both returncode and output with session.run\n+    process = subprocess.run(\n+        [\"python\", \"setup.py\", \"install\"],\n+        env={**session.env},\n+        text=True,\n+        capture_output=True,\n+    )\n+    assert process.returncode == 1\n+    print(process.stderr)\n+    assert \"Unsupported Python version\" in process.stderr\n+\n+\n @nox.session(python=[\"3\"])\n def google_brotli(session):\n     # https://pypi.org/project/Brotli/ is the Google version of brotli, so\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -4,9 +4,38 @@\n import codecs\n import os\n import re\n+import sys\n \n from setuptools import setup\n \n+CURRENT_PYTHON = sys.version_info[:2]\n+REQUIRED_PYTHON = (3, 6)\n+\n+# This check and everything above must remain compatible with Python 2.7.\n+if CURRENT_PYTHON < REQUIRED_PYTHON:\n+    sys.stderr.write(\n+        \"\"\"\n+==========================\n+Unsupported Python version\n+==========================\n+This version of urllib3 requires Python {}.{}, but you're trying to\n+install it on Python {}.{}.\n+This may be because you are using a version of pip that doesn't\n+understand the python_requires classifier. Make sure you\n+have pip >= 9.0 and setuptools >= 24.2, then try again:\n+    $ python -m pip install --upgrade pip setuptools\n+    $ python -m pip install urllib3\n+This will install the latest version of urllib3 which works on your\n+version of Python. If you can't upgrade your pip (or Python), request\n+an older version of urllib3:\n+    $ python -m pip install \"urllib3<2\"\n+\"\"\".format(\n+            *(REQUIRED_PYTHON + CURRENT_PYTHON)\n+        )\n+    )\n+    sys.exit(1)\n+\n+\n base_path = os.path.dirname(__file__)\n \n # Get the version (borrowed from SQLAlchemy)\n", "issue": "[v2] Detect unsupported Python versions and raise a helpful ImportError\nWe'll need to ensure our `urllib3/__init__.py` is still Python 2.x compatible for early urllib3 v2.x releases. If we detect an unsupported Python version we raise a helpful error message recommending pinning to `urllib3<2`\n", "before_files": [{"content": "import os\nimport shutil\nimport subprocess\n\nimport nox\n\n# Whenever type-hints are completed on a file it should be added here so that\n# this file will continue to be checked by mypy. Errors from other files are\n# ignored.\nTYPED_FILES = {\n    \"src/urllib3/contrib/__init__.py\",\n    \"src/urllib3/exceptions.py\",\n    \"src/urllib3/fields.py\",\n    \"src/urllib3/filepost.py\",\n    \"src/urllib3/packages/__init__.py\",\n    \"src/urllib3/packages/six.py\",\n    \"src/urllib3/packages/ssl_match_hostname/__init__.py\",\n    \"src/urllib3/packages/ssl_match_hostname/_implementation.py\",\n    \"src/urllib3/util/queue.py\",\n    \"src/urllib3/util/url.py\",\n}\nSOURCE_FILES = [\n    \"docs/\",\n    \"dummyserver/\",\n    \"src/\",\n    \"test/\",\n    \"noxfile.py\",\n    \"setup.py\",\n]\n\n\ndef tests_impl(session, extras=\"socks,secure,brotli\"):\n    # Install deps and the package itself.\n    session.install(\"-r\", \"dev-requirements.txt\")\n    session.install(f\".[{extras}]\")\n\n    # Show the pip version.\n    session.run(\"pip\", \"--version\")\n    # Print the Python version and bytesize.\n    session.run(\"python\", \"--version\")\n    session.run(\"python\", \"-c\", \"import struct; print(struct.calcsize('P') * 8)\")\n    # Print OpenSSL information.\n    session.run(\"python\", \"-m\", \"OpenSSL.debug\")\n\n    # Inspired from https://github.com/pyca/cryptography\n    # We use parallel mode and then combine here so that coverage.py will take\n    # the paths like .tox/pyXY/lib/pythonX.Y/site-packages/urllib3/__init__.py\n    # and collapse them into src/urllib3/__init__.py.\n\n    session.run(\n        \"coverage\",\n        \"run\",\n        \"--parallel-mode\",\n        \"-m\",\n        \"pytest\",\n        \"-r\",\n        \"a\",\n        \"--tb=native\",\n        \"--no-success-flaky-report\",\n        *(session.posargs or (\"test/\",)),\n        env={\"PYTHONWARNINGS\": \"always::DeprecationWarning\"},\n    )\n    session.run(\"coverage\", \"combine\")\n    session.run(\"coverage\", \"report\", \"-m\")\n    session.run(\"coverage\", \"xml\")\n\n\n@nox.session(python=[\"3.6\", \"3.7\", \"3.8\", \"3.9\", \"3.10\", \"pypy\"])\ndef test(session):\n    tests_impl(session)\n\n\n@nox.session(python=[\"3\"])\ndef google_brotli(session):\n    # https://pypi.org/project/Brotli/ is the Google version of brotli, so\n    # install it separately and don't install our brotli extra (which installs\n    # brotlipy).\n    session.install(\"brotli\")\n    tests_impl(session, extras=\"socks,secure\")\n\n\n@nox.session()\ndef format(session):\n    \"\"\"Run code formatters.\"\"\"\n    session.install(\"black\", \"isort\")\n    session.run(\"black\", *SOURCE_FILES)\n    session.run(\"isort\", *SOURCE_FILES)\n\n    lint(session)\n\n\n@nox.session\ndef lint(session):\n    session.install(\"flake8\", \"flake8-2020\", \"black\", \"isort\", \"mypy\")\n    session.run(\"flake8\", \"--version\")\n    session.run(\"black\", \"--version\")\n    session.run(\"isort\", \"--version\")\n    session.run(\"mypy\", \"--version\")\n    session.run(\"black\", \"--check\", *SOURCE_FILES)\n    session.run(\"isort\", \"--check\", *SOURCE_FILES)\n    session.run(\"flake8\", *SOURCE_FILES)\n\n    session.log(\"mypy --strict src/urllib3\")\n    all_errors, errors = [], []\n    process = subprocess.run(\n        [\"mypy\", \"--strict\", \"src/urllib3\"],\n        env=session.env,\n        text=True,\n        stdout=subprocess.PIPE,\n        stderr=subprocess.STDOUT,\n    )\n    # Ensure that mypy itself ran successfully\n    assert process.returncode in (0, 1)\n\n    for line in process.stdout.split(\"\\n\"):\n        all_errors.append(line)\n        filepath = line.partition(\":\")[0]\n        if filepath.replace(\".pyi\", \".py\") in TYPED_FILES:\n            errors.append(line)\n    session.log(f\"all errors count: {len(all_errors)}\")\n    if errors:\n        session.error(\"\\n\" + \"\\n\".join(sorted(set(errors))))\n\n\n@nox.session\ndef docs(session):\n    session.install(\"-r\", \"docs/requirements.txt\")\n    session.install(\".[socks,secure,brotli]\")\n\n    session.chdir(\"docs\")\n    if os.path.exists(\"_build\"):\n        shutil.rmtree(\"_build\")\n    session.run(\"sphinx-build\", \"-b\", \"html\", \"-W\", \".\", \"_build/html\")\n", "path": "noxfile.py"}, {"content": "#!/usr/bin/env python\n# This file is protected via CODEOWNERS\n\nimport codecs\nimport os\nimport re\n\nfrom setuptools import setup\n\nbase_path = os.path.dirname(__file__)\n\n# Get the version (borrowed from SQLAlchemy)\nwith open(os.path.join(base_path, \"src\", \"urllib3\", \"_version.py\")) as fp:\n    VERSION = (\n        re.compile(r\"\"\".*__version__ = [\"'](.*?)['\"]\"\"\", re.S).match(fp.read()).group(1)\n    )\n\n\nwith codecs.open(\"README.rst\", encoding=\"utf-8\") as fp:\n    # Remove reST raw directive from README as they're not allowed on PyPI\n    # Those blocks start with a newline and continue until the next newline\n    mode = None\n    lines = []\n    for line in fp:\n        if line.startswith(\".. raw::\"):\n            mode = \"ignore_nl\"\n        elif line == \"\\n\":\n            mode = \"wait_nl\" if mode == \"ignore_nl\" else None\n\n        if mode is None:\n            lines.append(line)\n    readme = \"\".join(lines)\n\nwith codecs.open(\"CHANGES.rst\", encoding=\"utf-8\") as fp:\n    changes = fp.read()\n\nversion = VERSION\n\nsetup(\n    name=\"urllib3\",\n    version=version,\n    description=\"HTTP library with thread-safe connection pooling, file post, and more.\",\n    long_description=\"\\n\\n\".join([readme, changes]),\n    long_description_content_type=\"text/x-rst\",\n    classifiers=[\n        \"Environment :: Web Environment\",\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: MIT License\",\n        \"Operating System :: OS Independent\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.6\",\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"Programming Language :: Python :: 3.9\",\n        \"Programming Language :: Python :: 3 :: Only\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Internet :: WWW/HTTP\",\n        \"Topic :: Software Development :: Libraries\",\n    ],\n    keywords=\"urllib httplib threadsafe filepost http https ssl pooling\",\n    author=\"Andrey Petrov\",\n    author_email=\"andrey.petrov@shazow.net\",\n    url=\"https://urllib3.readthedocs.io/\",\n    project_urls={\n        \"Documentation\": \"https://urllib3.readthedocs.io/\",\n        \"Code\": \"https://github.com/urllib3/urllib3\",\n        \"Issue tracker\": \"https://github.com/urllib3/urllib3/issues\",\n    },\n    license=\"MIT\",\n    packages=[\n        \"urllib3\",\n        \"urllib3.packages\",\n        \"urllib3.packages.ssl_match_hostname\",\n        \"urllib3.packages.backports\",\n        \"urllib3.contrib\",\n        \"urllib3.contrib._securetransport\",\n        \"urllib3.util\",\n    ],\n    package_dir={\"\": \"src\"},\n    requires=[],\n    python_requires=\">=3.6, <4\",\n    extras_require={\n        \"brotli\": [\"brotlipy>=0.6.0\"],\n        \"secure\": [\n            \"pyOpenSSL>=0.14\",\n            \"cryptography>=1.3.4\",\n            \"idna>=2.0.0\",\n            \"certifi\",\n        ],\n        \"socks\": [\"PySocks>=1.5.6,<2.0,!=1.5.7\"],\n    },\n)\n", "path": "setup.py"}], "after_files": [{"content": "import os\nimport shutil\nimport subprocess\n\nimport nox\n\n# Whenever type-hints are completed on a file it should be added here so that\n# this file will continue to be checked by mypy. Errors from other files are\n# ignored.\nTYPED_FILES = {\n    \"src/urllib3/contrib/__init__.py\",\n    \"src/urllib3/exceptions.py\",\n    \"src/urllib3/fields.py\",\n    \"src/urllib3/filepost.py\",\n    \"src/urllib3/packages/__init__.py\",\n    \"src/urllib3/packages/six.py\",\n    \"src/urllib3/packages/ssl_match_hostname/__init__.py\",\n    \"src/urllib3/packages/ssl_match_hostname/_implementation.py\",\n    \"src/urllib3/util/queue.py\",\n    \"src/urllib3/util/url.py\",\n}\nSOURCE_FILES = [\n    \"docs/\",\n    \"dummyserver/\",\n    \"src/\",\n    \"test/\",\n    \"noxfile.py\",\n    \"setup.py\",\n]\n\n\ndef tests_impl(session, extras=\"socks,secure,brotli\"):\n    # Install deps and the package itself.\n    session.install(\"-r\", \"dev-requirements.txt\")\n    session.install(f\".[{extras}]\")\n\n    # Show the pip version.\n    session.run(\"pip\", \"--version\")\n    # Print the Python version and bytesize.\n    session.run(\"python\", \"--version\")\n    session.run(\"python\", \"-c\", \"import struct; print(struct.calcsize('P') * 8)\")\n    # Print OpenSSL information.\n    session.run(\"python\", \"-m\", \"OpenSSL.debug\")\n\n    # Inspired from https://github.com/pyca/cryptography\n    # We use parallel mode and then combine here so that coverage.py will take\n    # the paths like .tox/pyXY/lib/pythonX.Y/site-packages/urllib3/__init__.py\n    # and collapse them into src/urllib3/__init__.py.\n\n    session.run(\n        \"coverage\",\n        \"run\",\n        \"--parallel-mode\",\n        \"-m\",\n        \"pytest\",\n        \"-r\",\n        \"a\",\n        \"--tb=native\",\n        \"--no-success-flaky-report\",\n        *(session.posargs or (\"test/\",)),\n        env={\"PYTHONWARNINGS\": \"always::DeprecationWarning\"},\n    )\n    session.run(\"coverage\", \"combine\")\n    session.run(\"coverage\", \"report\", \"-m\")\n    session.run(\"coverage\", \"xml\")\n\n\n@nox.session(python=[\"3.6\", \"3.7\", \"3.8\", \"3.9\", \"3.10\", \"pypy\"])\ndef test(session):\n    tests_impl(session)\n\n\n@nox.session(python=[\"2.7\"])\ndef unsupported_python2(session):\n    # Can't check both returncode and output with session.run\n    process = subprocess.run(\n        [\"python\", \"setup.py\", \"install\"],\n        env={**session.env},\n        text=True,\n        capture_output=True,\n    )\n    assert process.returncode == 1\n    print(process.stderr)\n    assert \"Unsupported Python version\" in process.stderr\n\n\n@nox.session(python=[\"3\"])\ndef google_brotli(session):\n    # https://pypi.org/project/Brotli/ is the Google version of brotli, so\n    # install it separately and don't install our brotli extra (which installs\n    # brotlipy).\n    session.install(\"brotli\")\n    tests_impl(session, extras=\"socks,secure\")\n\n\n@nox.session()\ndef format(session):\n    \"\"\"Run code formatters.\"\"\"\n    session.install(\"black\", \"isort\")\n    session.run(\"black\", *SOURCE_FILES)\n    session.run(\"isort\", *SOURCE_FILES)\n\n    lint(session)\n\n\n@nox.session\ndef lint(session):\n    session.install(\"flake8\", \"flake8-2020\", \"black\", \"isort\", \"mypy\")\n    session.run(\"flake8\", \"--version\")\n    session.run(\"black\", \"--version\")\n    session.run(\"isort\", \"--version\")\n    session.run(\"mypy\", \"--version\")\n    session.run(\"black\", \"--check\", *SOURCE_FILES)\n    session.run(\"isort\", \"--check\", *SOURCE_FILES)\n    session.run(\"flake8\", *SOURCE_FILES)\n\n    session.log(\"mypy --strict src/urllib3\")\n    all_errors, errors = [], []\n    process = subprocess.run(\n        [\"mypy\", \"--strict\", \"src/urllib3\"],\n        env=session.env,\n        text=True,\n        stdout=subprocess.PIPE,\n        stderr=subprocess.STDOUT,\n    )\n    # Ensure that mypy itself ran successfully\n    assert process.returncode in (0, 1)\n\n    for line in process.stdout.split(\"\\n\"):\n        all_errors.append(line)\n        filepath = line.partition(\":\")[0]\n        if filepath.replace(\".pyi\", \".py\") in TYPED_FILES:\n            errors.append(line)\n    session.log(f\"all errors count: {len(all_errors)}\")\n    if errors:\n        session.error(\"\\n\" + \"\\n\".join(sorted(set(errors))))\n\n\n@nox.session\ndef docs(session):\n    session.install(\"-r\", \"docs/requirements.txt\")\n    session.install(\".[socks,secure,brotli]\")\n\n    session.chdir(\"docs\")\n    if os.path.exists(\"_build\"):\n        shutil.rmtree(\"_build\")\n    session.run(\"sphinx-build\", \"-b\", \"html\", \"-W\", \".\", \"_build/html\")\n", "path": "noxfile.py"}, {"content": "#!/usr/bin/env python\n# This file is protected via CODEOWNERS\n\nimport codecs\nimport os\nimport re\nimport sys\n\nfrom setuptools import setup\n\nCURRENT_PYTHON = sys.version_info[:2]\nREQUIRED_PYTHON = (3, 6)\n\n# This check and everything above must remain compatible with Python 2.7.\nif CURRENT_PYTHON < REQUIRED_PYTHON:\n    sys.stderr.write(\n        \"\"\"\n==========================\nUnsupported Python version\n==========================\nThis version of urllib3 requires Python {}.{}, but you're trying to\ninstall it on Python {}.{}.\nThis may be because you are using a version of pip that doesn't\nunderstand the python_requires classifier. Make sure you\nhave pip >= 9.0 and setuptools >= 24.2, then try again:\n    $ python -m pip install --upgrade pip setuptools\n    $ python -m pip install urllib3\nThis will install the latest version of urllib3 which works on your\nversion of Python. If you can't upgrade your pip (or Python), request\nan older version of urllib3:\n    $ python -m pip install \"urllib3<2\"\n\"\"\".format(\n            *(REQUIRED_PYTHON + CURRENT_PYTHON)\n        )\n    )\n    sys.exit(1)\n\n\nbase_path = os.path.dirname(__file__)\n\n# Get the version (borrowed from SQLAlchemy)\nwith open(os.path.join(base_path, \"src\", \"urllib3\", \"_version.py\")) as fp:\n    VERSION = (\n        re.compile(r\"\"\".*__version__ = [\"'](.*?)['\"]\"\"\", re.S).match(fp.read()).group(1)\n    )\n\n\nwith codecs.open(\"README.rst\", encoding=\"utf-8\") as fp:\n    # Remove reST raw directive from README as they're not allowed on PyPI\n    # Those blocks start with a newline and continue until the next newline\n    mode = None\n    lines = []\n    for line in fp:\n        if line.startswith(\".. raw::\"):\n            mode = \"ignore_nl\"\n        elif line == \"\\n\":\n            mode = \"wait_nl\" if mode == \"ignore_nl\" else None\n\n        if mode is None:\n            lines.append(line)\n    readme = \"\".join(lines)\n\nwith codecs.open(\"CHANGES.rst\", encoding=\"utf-8\") as fp:\n    changes = fp.read()\n\nversion = VERSION\n\nsetup(\n    name=\"urllib3\",\n    version=version,\n    description=\"HTTP library with thread-safe connection pooling, file post, and more.\",\n    long_description=\"\\n\\n\".join([readme, changes]),\n    long_description_content_type=\"text/x-rst\",\n    classifiers=[\n        \"Environment :: Web Environment\",\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: MIT License\",\n        \"Operating System :: OS Independent\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.6\",\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"Programming Language :: Python :: 3.9\",\n        \"Programming Language :: Python :: 3 :: Only\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Internet :: WWW/HTTP\",\n        \"Topic :: Software Development :: Libraries\",\n    ],\n    keywords=\"urllib httplib threadsafe filepost http https ssl pooling\",\n    author=\"Andrey Petrov\",\n    author_email=\"andrey.petrov@shazow.net\",\n    url=\"https://urllib3.readthedocs.io/\",\n    project_urls={\n        \"Documentation\": \"https://urllib3.readthedocs.io/\",\n        \"Code\": \"https://github.com/urllib3/urllib3\",\n        \"Issue tracker\": \"https://github.com/urllib3/urllib3/issues\",\n    },\n    license=\"MIT\",\n    packages=[\n        \"urllib3\",\n        \"urllib3.packages\",\n        \"urllib3.packages.ssl_match_hostname\",\n        \"urllib3.packages.backports\",\n        \"urllib3.contrib\",\n        \"urllib3.contrib._securetransport\",\n        \"urllib3.util\",\n    ],\n    package_dir={\"\": \"src\"},\n    requires=[],\n    python_requires=\">=3.6, <4\",\n    extras_require={\n        \"brotli\": [\"brotlipy>=0.6.0\"],\n        \"secure\": [\n            \"pyOpenSSL>=0.14\",\n            \"cryptography>=1.3.4\",\n            \"idna>=2.0.0\",\n            \"certifi\",\n        ],\n        \"socks\": [\"PySocks>=1.5.6,<2.0,!=1.5.7\"],\n    },\n)\n", "path": "setup.py"}]}