We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Don't install enum34 on Python3.4+


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4 
5 from __future__ import absolute_import, division, print_function
6 
7 import os
8 import platform
9 import subprocess
10 import sys
11 from distutils.command.build import build
12 
13 import pkg_resources
14 
15 from setuptools import find_packages, setup
16 from setuptools.command.install import install
17 from setuptools.command.test import test
18 
19 
20 base_dir = os.path.dirname(__file__)
21 src_dir = os.path.join(base_dir, "src")
22 
23 # When executing the setup.py, we need to be able to import ourselves, this
24 # means that we need to add the src/ directory to the sys.path.
25 sys.path.insert(0, src_dir)
26 
27 about = {}
28 with open(os.path.join(src_dir, "cryptography", "__about__.py")) as f:
29     exec(f.read(), about)
30 
31 
32 SETUPTOOLS_DEPENDENCY = "setuptools"
33 CFFI_DEPENDENCY = "cffi>=0.8"
34 SIX_DEPENDENCY = "six>=1.4.1"
35 VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__'])
36 
37 requirements = [
38     CFFI_DEPENDENCY,
39     "enum34",
40     "pyasn1",
41     SIX_DEPENDENCY,
42     SETUPTOOLS_DEPENDENCY
43 ]
44 
45 # If you add a new dep here you probably need to add it in the tox.ini as well
46 test_requirements = [
47     "pytest",
48     "pretend",
49     "iso8601",
50 ]
51 
52 # If there's no vectors locally that probably means we are in a tarball and
53 # need to go and get the matching vectors package from PyPi
54 if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")):
55     test_requirements.append(VECTORS_DEPENDENCY)
56 
57 
58 def cc_is_available():
59     return sys.platform == "darwin" and list(map(
60         int, platform.mac_ver()[0].split("."))) >= [10, 8, 0]
61 
62 
63 backends = [
64     "openssl = cryptography.hazmat.backends.openssl:backend"
65 ]
66 
67 if cc_is_available():
68     backends.append(
69         "commoncrypto = cryptography.hazmat.backends.commoncrypto:backend",
70     )
71 
72 
73 def get_ext_modules():
74     from cryptography.hazmat.bindings.commoncrypto.binding import (
75         Binding as CommonCryptoBinding
76     )
77     from cryptography.hazmat.bindings.openssl.binding import (
78         Binding as OpenSSLBinding
79     )
80     from cryptography.hazmat.primitives import constant_time, padding
81 
82     ext_modules = [
83         OpenSSLBinding.ffi.verifier.get_extension(),
84         constant_time._ffi.verifier.get_extension(),
85         padding._ffi.verifier.get_extension()
86     ]
87     if cc_is_available():
88         ext_modules.append(CommonCryptoBinding.ffi.verifier.get_extension())
89     return ext_modules
90 
91 
92 class CFFIBuild(build):
93     """
94     This class exists, instead of just providing ``ext_modules=[...]`` directly
95     in ``setup()`` because importing cryptography requires we have several
96     packages installed first.
97 
98     By doing the imports here we ensure that packages listed in
99     ``setup_requires`` are already installed.
100     """
101 
102     def finalize_options(self):
103         self.distribution.ext_modules = get_ext_modules()
104         build.finalize_options(self)
105 
106 
107 class CFFIInstall(install):
108     """
109     As a consequence of CFFIBuild and it's late addition of ext_modules, we
110     need the equivalent for the ``install`` command to install into platlib
111     install-dir rather than purelib.
112     """
113 
114     def finalize_options(self):
115         self.distribution.ext_modules = get_ext_modules()
116         install.finalize_options(self)
117 
118 
119 class PyTest(test):
120     def finalize_options(self):
121         test.finalize_options(self)
122         self.test_args = []
123         self.test_suite = True
124 
125         # This means there's a vectors/ folder with the package in here.
126         # cd into it, install the vectors package and then refresh sys.path
127         if VECTORS_DEPENDENCY not in test_requirements:
128             subprocess.check_call(
129                 [sys.executable, "setup.py", "install"], cwd="vectors"
130             )
131             pkg_resources.get_distribution("cryptography_vectors").activate()
132 
133     def run_tests(self):
134         # Import here because in module scope the eggs are not loaded.
135         import pytest
136         errno = pytest.main(self.test_args)
137         sys.exit(errno)
138 
139 
140 def keywords_with_side_effects(argv):
141     """
142     Get a dictionary with setup keywords that (can) have side effects.
143 
144     :param argv: A list of strings with command line arguments.
145     :returns: A dictionary with keyword arguments for the ``setup()`` function.
146 
147     This setup.py script uses the setuptools 'setup_requires' feature because
148     this is required by the cffi package to compile extension modules. The
149     purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi
150     build process as a result of setup.py invocations that don't need the cffi
151     module to be built (setup.py serves the dual purpose of exposing package
152     metadata).
153 
154     All of the options listed by ``python setup.py --help`` that print
155     information should be recognized here. The commands ``clean``,
156     ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.
157     Any combination of these options and commands is also supported.
158 
159     This function was originally based on the `setup.py script`_ of SciPy (see
160     also the discussion in `pip issue #25`_).
161 
162     .. _pip issue #25: https://github.com/pypa/pip/issues/25
163     .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py
164     """
165     no_setup_requires_arguments = (
166         '-h', '--help',
167         '-n', '--dry-run',
168         '-q', '--quiet',
169         '-v', '--verbose',
170         '-V', '--version',
171         '--author',
172         '--author-email',
173         '--classifiers',
174         '--contact',
175         '--contact-email',
176         '--description',
177         '--egg-base',
178         '--fullname',
179         '--help-commands',
180         '--keywords',
181         '--licence',
182         '--license',
183         '--long-description',
184         '--maintainer',
185         '--maintainer-email',
186         '--name',
187         '--no-user-cfg',
188         '--obsoletes',
189         '--platforms',
190         '--provides',
191         '--requires',
192         '--url',
193         'clean',
194         'egg_info',
195         'register',
196         'sdist',
197         'upload',
198     )
199 
200     def is_short_option(argument):
201         """Check whether a command line argument is a short option."""
202         return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'
203 
204     def expand_short_options(argument):
205         """Expand combined short options into canonical short options."""
206         return ('-' + char for char in argument[1:])
207 
208     def argument_without_setup_requirements(argv, i):
209         """Check whether a command line argument needs setup requirements."""
210         if argv[i] in no_setup_requires_arguments:
211             # Simple case: An argument which is either an option or a command
212             # which doesn't need setup requirements.
213             return True
214         elif (is_short_option(argv[i]) and
215               all(option in no_setup_requires_arguments
216                   for option in expand_short_options(argv[i]))):
217             # Not so simple case: Combined short options none of which need
218             # setup requirements.
219             return True
220         elif argv[i - 1:i] == ['--egg-base']:
221             # Tricky case: --egg-info takes an argument which should not make
222             # us use setup_requires (defeating the purpose of this code).
223             return True
224         else:
225             return False
226 
227     if all(argument_without_setup_requirements(argv, i)
228            for i in range(1, len(argv))):
229         return {
230             "cmdclass": {
231                 "build": DummyCFFIBuild,
232                 "install": DummyCFFIInstall,
233                 "test": DummyPyTest,
234             }
235         }
236     else:
237         return {
238             "setup_requires": requirements,
239             "cmdclass": {
240                 "build": CFFIBuild,
241                 "install": CFFIInstall,
242                 "test": PyTest,
243             }
244         }
245 
246 
247 setup_requires_error = ("Requested setup command that needs 'setup_requires' "
248                         "while command line arguments implied a side effect "
249                         "free command or option.")
250 
251 
252 class DummyCFFIBuild(build):
253     """
254     This class makes it very obvious when ``keywords_with_side_effects()`` has
255     incorrectly interpreted the command line arguments to ``setup.py build`` as
256     one of the 'side effect free' commands or options.
257     """
258 
259     def run(self):
260         raise RuntimeError(setup_requires_error)
261 
262 
263 class DummyCFFIInstall(install):
264     """
265     This class makes it very obvious when ``keywords_with_side_effects()`` has
266     incorrectly interpreted the command line arguments to ``setup.py install``
267     as one of the 'side effect free' commands or options.
268     """
269 
270     def run(self):
271         raise RuntimeError(setup_requires_error)
272 
273 
274 class DummyPyTest(test):
275     """
276     This class makes it very obvious when ``keywords_with_side_effects()`` has
277     incorrectly interpreted the command line arguments to ``setup.py test`` as
278     one of the 'side effect free' commands or options.
279     """
280 
281     def run_tests(self):
282         raise RuntimeError(setup_requires_error)
283 
284 
285 with open(os.path.join(base_dir, "README.rst")) as f:
286     long_description = f.read()
287 
288 
289 setup(
290     name=about["__title__"],
291     version=about["__version__"],
292 
293     description=about["__summary__"],
294     long_description=long_description,
295     license=about["__license__"],
296     url=about["__uri__"],
297 
298     author=about["__author__"],
299     author_email=about["__email__"],
300 
301     classifiers=[
302         "Intended Audience :: Developers",
303         "License :: OSI Approved :: Apache Software License",
304         "License :: OSI Approved :: BSD License",
305         "Natural Language :: English",
306         "Operating System :: MacOS :: MacOS X",
307         "Operating System :: POSIX",
308         "Operating System :: POSIX :: BSD",
309         "Operating System :: POSIX :: Linux",
310         "Operating System :: Microsoft :: Windows",
311         "Programming Language :: Python",
312         "Programming Language :: Python :: 2",
313         "Programming Language :: Python :: 2.6",
314         "Programming Language :: Python :: 2.7",
315         "Programming Language :: Python :: 3",
316         "Programming Language :: Python :: 3.2",
317         "Programming Language :: Python :: 3.3",
318         "Programming Language :: Python :: 3.4",
319         "Programming Language :: Python :: Implementation :: CPython",
320         "Programming Language :: Python :: Implementation :: PyPy",
321         "Topic :: Security :: Cryptography",
322     ],
323 
324     package_dir={"": "src"},
325     packages=find_packages(where="src", exclude=["tests", "tests.*"]),
326     include_package_data=True,
327 
328     install_requires=requirements,
329     tests_require=test_requirements,
330 
331     # for cffi
332     zip_safe=False,
333     ext_package="cryptography",
334     entry_points={
335         "cryptography.backends": backends,
336     },
337     **keywords_with_side_effects(sys.argv)
338 )
339
```
--- 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/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -36,12 +36,14 @@
 
 requirements = [
     CFFI_DEPENDENCY,
-    "enum34",
     "pyasn1",
     SIX_DEPENDENCY,
     SETUPTOOLS_DEPENDENCY
 ]
 
+if sys.version_info < (3, 4):
+    requirements.append("enum34")
+
 # If you add a new dep here you probably need to add it in the tox.ini as well
 test_requirements = [
     "pytest",

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -36,12 +36,14 @@\n \n requirements = [\n     CFFI_DEPENDENCY,\n-    \"enum34\",\n     \"pyasn1\",\n     SIX_DEPENDENCY,\n     SETUPTOOLS_DEPENDENCY\n ]\n \n+if sys.version_info < (3, 4):\n+    requirements.append(\"enum34\")\n+\n # If you add a new dep here you probably need to add it in the tox.ini as well\n test_requirements = [\n     \"pytest\",\n", "issue": "Don't install enum34 on Python3.4+\n\n", "before_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport os\nimport platform\nimport subprocess\nimport sys\nfrom distutils.command.build import build\n\nimport pkg_resources\n\nfrom setuptools import find_packages, setup\nfrom setuptools.command.install import install\nfrom setuptools.command.test import test\n\n\nbase_dir = os.path.dirname(__file__)\nsrc_dir = os.path.join(base_dir, \"src\")\n\n# When executing the setup.py, we need to be able to import ourselves, this\n# means that we need to add the src/ directory to the sys.path.\nsys.path.insert(0, src_dir)\n\nabout = {}\nwith open(os.path.join(src_dir, \"cryptography\", \"__about__.py\")) as f:\n    exec(f.read(), about)\n\n\nSETUPTOOLS_DEPENDENCY = \"setuptools\"\nCFFI_DEPENDENCY = \"cffi>=0.8\"\nSIX_DEPENDENCY = \"six>=1.4.1\"\nVECTORS_DEPENDENCY = \"cryptography_vectors=={0}\".format(about['__version__'])\n\nrequirements = [\n    CFFI_DEPENDENCY,\n    \"enum34\",\n    \"pyasn1\",\n    SIX_DEPENDENCY,\n    SETUPTOOLS_DEPENDENCY\n]\n\n# If you add a new dep here you probably need to add it in the tox.ini as well\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n]\n\n# If there's no vectors locally that probably means we are in a tarball and\n# need to go and get the matching vectors package from PyPi\nif not os.path.exists(os.path.join(base_dir, \"vectors/setup.py\")):\n    test_requirements.append(VECTORS_DEPENDENCY)\n\n\ndef cc_is_available():\n    return sys.platform == \"darwin\" and list(map(\n        int, platform.mac_ver()[0].split(\".\"))) >= [10, 8, 0]\n\n\nbackends = [\n    \"openssl = cryptography.hazmat.backends.openssl:backend\"\n]\n\nif cc_is_available():\n    backends.append(\n        \"commoncrypto = cryptography.hazmat.backends.commoncrypto:backend\",\n    )\n\n\ndef get_ext_modules():\n    from cryptography.hazmat.bindings.commoncrypto.binding import (\n        Binding as CommonCryptoBinding\n    )\n    from cryptography.hazmat.bindings.openssl.binding import (\n        Binding as OpenSSLBinding\n    )\n    from cryptography.hazmat.primitives import constant_time, padding\n\n    ext_modules = [\n        OpenSSLBinding.ffi.verifier.get_extension(),\n        constant_time._ffi.verifier.get_extension(),\n        padding._ffi.verifier.get_extension()\n    ]\n    if cc_is_available():\n        ext_modules.append(CommonCryptoBinding.ffi.verifier.get_extension())\n    return ext_modules\n\n\nclass CFFIBuild(build):\n    \"\"\"\n    This class exists, instead of just providing ``ext_modules=[...]`` directly\n    in ``setup()`` because importing cryptography requires we have several\n    packages installed first.\n\n    By doing the imports here we ensure that packages listed in\n    ``setup_requires`` are already installed.\n    \"\"\"\n\n    def finalize_options(self):\n        self.distribution.ext_modules = get_ext_modules()\n        build.finalize_options(self)\n\n\nclass CFFIInstall(install):\n    \"\"\"\n    As a consequence of CFFIBuild and it's late addition of ext_modules, we\n    need the equivalent for the ``install`` command to install into platlib\n    install-dir rather than purelib.\n    \"\"\"\n\n    def finalize_options(self):\n        self.distribution.ext_modules = get_ext_modules()\n        install.finalize_options(self)\n\n\nclass PyTest(test):\n    def finalize_options(self):\n        test.finalize_options(self)\n        self.test_args = []\n        self.test_suite = True\n\n        # This means there's a vectors/ folder with the package in here.\n        # cd into it, install the vectors package and then refresh sys.path\n        if VECTORS_DEPENDENCY not in test_requirements:\n            subprocess.check_call(\n                [sys.executable, \"setup.py\", \"install\"], cwd=\"vectors\"\n            )\n            pkg_resources.get_distribution(\"cryptography_vectors\").activate()\n\n    def run_tests(self):\n        # Import here because in module scope the eggs are not loaded.\n        import pytest\n        errno = pytest.main(self.test_args)\n        sys.exit(errno)\n\n\ndef keywords_with_side_effects(argv):\n    \"\"\"\n    Get a dictionary with setup keywords that (can) have side effects.\n\n    :param argv: A list of strings with command line arguments.\n    :returns: A dictionary with keyword arguments for the ``setup()`` function.\n\n    This setup.py script uses the setuptools 'setup_requires' feature because\n    this is required by the cffi package to compile extension modules. The\n    purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi\n    build process as a result of setup.py invocations that don't need the cffi\n    module to be built (setup.py serves the dual purpose of exposing package\n    metadata).\n\n    All of the options listed by ``python setup.py --help`` that print\n    information should be recognized here. The commands ``clean``,\n    ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.\n    Any combination of these options and commands is also supported.\n\n    This function was originally based on the `setup.py script`_ of SciPy (see\n    also the discussion in `pip issue #25`_).\n\n    .. _pip issue #25: https://github.com/pypa/pip/issues/25\n    .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py\n    \"\"\"\n    no_setup_requires_arguments = (\n        '-h', '--help',\n        '-n', '--dry-run',\n        '-q', '--quiet',\n        '-v', '--verbose',\n        '-V', '--version',\n        '--author',\n        '--author-email',\n        '--classifiers',\n        '--contact',\n        '--contact-email',\n        '--description',\n        '--egg-base',\n        '--fullname',\n        '--help-commands',\n        '--keywords',\n        '--licence',\n        '--license',\n        '--long-description',\n        '--maintainer',\n        '--maintainer-email',\n        '--name',\n        '--no-user-cfg',\n        '--obsoletes',\n        '--platforms',\n        '--provides',\n        '--requires',\n        '--url',\n        'clean',\n        'egg_info',\n        'register',\n        'sdist',\n        'upload',\n    )\n\n    def is_short_option(argument):\n        \"\"\"Check whether a command line argument is a short option.\"\"\"\n        return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'\n\n    def expand_short_options(argument):\n        \"\"\"Expand combined short options into canonical short options.\"\"\"\n        return ('-' + char for char in argument[1:])\n\n    def argument_without_setup_requirements(argv, i):\n        \"\"\"Check whether a command line argument needs setup requirements.\"\"\"\n        if argv[i] in no_setup_requires_arguments:\n            # Simple case: An argument which is either an option or a command\n            # which doesn't need setup requirements.\n            return True\n        elif (is_short_option(argv[i]) and\n              all(option in no_setup_requires_arguments\n                  for option in expand_short_options(argv[i]))):\n            # Not so simple case: Combined short options none of which need\n            # setup requirements.\n            return True\n        elif argv[i - 1:i] == ['--egg-base']:\n            # Tricky case: --egg-info takes an argument which should not make\n            # us use setup_requires (defeating the purpose of this code).\n            return True\n        else:\n            return False\n\n    if all(argument_without_setup_requirements(argv, i)\n           for i in range(1, len(argv))):\n        return {\n            \"cmdclass\": {\n                \"build\": DummyCFFIBuild,\n                \"install\": DummyCFFIInstall,\n                \"test\": DummyPyTest,\n            }\n        }\n    else:\n        return {\n            \"setup_requires\": requirements,\n            \"cmdclass\": {\n                \"build\": CFFIBuild,\n                \"install\": CFFIInstall,\n                \"test\": PyTest,\n            }\n        }\n\n\nsetup_requires_error = (\"Requested setup command that needs 'setup_requires' \"\n                        \"while command line arguments implied a side effect \"\n                        \"free command or option.\")\n\n\nclass DummyCFFIBuild(build):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py build`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyCFFIInstall(install):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py install``\n    as one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyPyTest(test):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py test`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run_tests(self):\n        raise RuntimeError(setup_requires_error)\n\n\nwith open(os.path.join(base_dir, \"README.rst\")) as f:\n    long_description = f.read()\n\n\nsetup(\n    name=about[\"__title__\"],\n    version=about[\"__version__\"],\n\n    description=about[\"__summary__\"],\n    long_description=long_description,\n    license=about[\"__license__\"],\n    url=about[\"__uri__\"],\n\n    author=about[\"__author__\"],\n    author_email=about[\"__email__\"],\n\n    classifiers=[\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: Apache Software License\",\n        \"License :: OSI Approved :: BSD License\",\n        \"Natural Language :: English\",\n        \"Operating System :: MacOS :: MacOS X\",\n        \"Operating System :: POSIX\",\n        \"Operating System :: POSIX :: BSD\",\n        \"Operating System :: POSIX :: Linux\",\n        \"Operating System :: Microsoft :: Windows\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 2.6\",\n        \"Programming Language :: Python :: 2.7\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.2\",\n        \"Programming Language :: Python :: 3.3\",\n        \"Programming Language :: Python :: 3.4\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Security :: Cryptography\",\n    ],\n\n    package_dir={\"\": \"src\"},\n    packages=find_packages(where=\"src\", exclude=[\"tests\", \"tests.*\"]),\n    include_package_data=True,\n\n    install_requires=requirements,\n    tests_require=test_requirements,\n\n    # for cffi\n    zip_safe=False,\n    ext_package=\"cryptography\",\n    entry_points={\n        \"cryptography.backends\": backends,\n    },\n    **keywords_with_side_effects(sys.argv)\n)\n", "path": "setup.py"}], "after_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport os\nimport platform\nimport subprocess\nimport sys\nfrom distutils.command.build import build\n\nimport pkg_resources\n\nfrom setuptools import find_packages, setup\nfrom setuptools.command.install import install\nfrom setuptools.command.test import test\n\n\nbase_dir = os.path.dirname(__file__)\nsrc_dir = os.path.join(base_dir, \"src\")\n\n# When executing the setup.py, we need to be able to import ourselves, this\n# means that we need to add the src/ directory to the sys.path.\nsys.path.insert(0, src_dir)\n\nabout = {}\nwith open(os.path.join(src_dir, \"cryptography\", \"__about__.py\")) as f:\n    exec(f.read(), about)\n\n\nSETUPTOOLS_DEPENDENCY = \"setuptools\"\nCFFI_DEPENDENCY = \"cffi>=0.8\"\nSIX_DEPENDENCY = \"six>=1.4.1\"\nVECTORS_DEPENDENCY = \"cryptography_vectors=={0}\".format(about['__version__'])\n\nrequirements = [\n    CFFI_DEPENDENCY,\n    \"pyasn1\",\n    SIX_DEPENDENCY,\n    SETUPTOOLS_DEPENDENCY\n]\n\nif sys.version_info < (3, 4):\n    requirements.append(\"enum34\")\n\n# If you add a new dep here you probably need to add it in the tox.ini as well\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n]\n\n# If there's no vectors locally that probably means we are in a tarball and\n# need to go and get the matching vectors package from PyPi\nif not os.path.exists(os.path.join(base_dir, \"vectors/setup.py\")):\n    test_requirements.append(VECTORS_DEPENDENCY)\n\n\ndef cc_is_available():\n    return sys.platform == \"darwin\" and list(map(\n        int, platform.mac_ver()[0].split(\".\"))) >= [10, 8, 0]\n\n\nbackends = [\n    \"openssl = cryptography.hazmat.backends.openssl:backend\"\n]\n\nif cc_is_available():\n    backends.append(\n        \"commoncrypto = cryptography.hazmat.backends.commoncrypto:backend\",\n    )\n\n\ndef get_ext_modules():\n    from cryptography.hazmat.bindings.commoncrypto.binding import (\n        Binding as CommonCryptoBinding\n    )\n    from cryptography.hazmat.bindings.openssl.binding import (\n        Binding as OpenSSLBinding\n    )\n    from cryptography.hazmat.primitives import constant_time, padding\n\n    ext_modules = [\n        OpenSSLBinding.ffi.verifier.get_extension(),\n        constant_time._ffi.verifier.get_extension(),\n        padding._ffi.verifier.get_extension()\n    ]\n    if cc_is_available():\n        ext_modules.append(CommonCryptoBinding.ffi.verifier.get_extension())\n    return ext_modules\n\n\nclass CFFIBuild(build):\n    \"\"\"\n    This class exists, instead of just providing ``ext_modules=[...]`` directly\n    in ``setup()`` because importing cryptography requires we have several\n    packages installed first.\n\n    By doing the imports here we ensure that packages listed in\n    ``setup_requires`` are already installed.\n    \"\"\"\n\n    def finalize_options(self):\n        self.distribution.ext_modules = get_ext_modules()\n        build.finalize_options(self)\n\n\nclass CFFIInstall(install):\n    \"\"\"\n    As a consequence of CFFIBuild and it's late addition of ext_modules, we\n    need the equivalent for the ``install`` command to install into platlib\n    install-dir rather than purelib.\n    \"\"\"\n\n    def finalize_options(self):\n        self.distribution.ext_modules = get_ext_modules()\n        install.finalize_options(self)\n\n\nclass PyTest(test):\n    def finalize_options(self):\n        test.finalize_options(self)\n        self.test_args = []\n        self.test_suite = True\n\n        # This means there's a vectors/ folder with the package in here.\n        # cd into it, install the vectors package and then refresh sys.path\n        if VECTORS_DEPENDENCY not in test_requirements:\n            subprocess.check_call(\n                [sys.executable, \"setup.py\", \"install\"], cwd=\"vectors\"\n            )\n            pkg_resources.get_distribution(\"cryptography_vectors\").activate()\n\n    def run_tests(self):\n        # Import here because in module scope the eggs are not loaded.\n        import pytest\n        errno = pytest.main(self.test_args)\n        sys.exit(errno)\n\n\ndef keywords_with_side_effects(argv):\n    \"\"\"\n    Get a dictionary with setup keywords that (can) have side effects.\n\n    :param argv: A list of strings with command line arguments.\n    :returns: A dictionary with keyword arguments for the ``setup()`` function.\n\n    This setup.py script uses the setuptools 'setup_requires' feature because\n    this is required by the cffi package to compile extension modules. The\n    purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi\n    build process as a result of setup.py invocations that don't need the cffi\n    module to be built (setup.py serves the dual purpose of exposing package\n    metadata).\n\n    All of the options listed by ``python setup.py --help`` that print\n    information should be recognized here. The commands ``clean``,\n    ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.\n    Any combination of these options and commands is also supported.\n\n    This function was originally based on the `setup.py script`_ of SciPy (see\n    also the discussion in `pip issue #25`_).\n\n    .. _pip issue #25: https://github.com/pypa/pip/issues/25\n    .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py\n    \"\"\"\n    no_setup_requires_arguments = (\n        '-h', '--help',\n        '-n', '--dry-run',\n        '-q', '--quiet',\n        '-v', '--verbose',\n        '-V', '--version',\n        '--author',\n        '--author-email',\n        '--classifiers',\n        '--contact',\n        '--contact-email',\n        '--description',\n        '--egg-base',\n        '--fullname',\n        '--help-commands',\n        '--keywords',\n        '--licence',\n        '--license',\n        '--long-description',\n        '--maintainer',\n        '--maintainer-email',\n        '--name',\n        '--no-user-cfg',\n        '--obsoletes',\n        '--platforms',\n        '--provides',\n        '--requires',\n        '--url',\n        'clean',\n        'egg_info',\n        'register',\n        'sdist',\n        'upload',\n    )\n\n    def is_short_option(argument):\n        \"\"\"Check whether a command line argument is a short option.\"\"\"\n        return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'\n\n    def expand_short_options(argument):\n        \"\"\"Expand combined short options into canonical short options.\"\"\"\n        return ('-' + char for char in argument[1:])\n\n    def argument_without_setup_requirements(argv, i):\n        \"\"\"Check whether a command line argument needs setup requirements.\"\"\"\n        if argv[i] in no_setup_requires_arguments:\n            # Simple case: An argument which is either an option or a command\n            # which doesn't need setup requirements.\n            return True\n        elif (is_short_option(argv[i]) and\n              all(option in no_setup_requires_arguments\n                  for option in expand_short_options(argv[i]))):\n            # Not so simple case: Combined short options none of which need\n            # setup requirements.\n            return True\n        elif argv[i - 1:i] == ['--egg-base']:\n            # Tricky case: --egg-info takes an argument which should not make\n            # us use setup_requires (defeating the purpose of this code).\n            return True\n        else:\n            return False\n\n    if all(argument_without_setup_requirements(argv, i)\n           for i in range(1, len(argv))):\n        return {\n            \"cmdclass\": {\n                \"build\": DummyCFFIBuild,\n                \"install\": DummyCFFIInstall,\n                \"test\": DummyPyTest,\n            }\n        }\n    else:\n        return {\n            \"setup_requires\": requirements,\n            \"cmdclass\": {\n                \"build\": CFFIBuild,\n                \"install\": CFFIInstall,\n                \"test\": PyTest,\n            }\n        }\n\n\nsetup_requires_error = (\"Requested setup command that needs 'setup_requires' \"\n                        \"while command line arguments implied a side effect \"\n                        \"free command or option.\")\n\n\nclass DummyCFFIBuild(build):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py build`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyCFFIInstall(install):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py install``\n    as one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyPyTest(test):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py test`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run_tests(self):\n        raise RuntimeError(setup_requires_error)\n\n\nwith open(os.path.join(base_dir, \"README.rst\")) as f:\n    long_description = f.read()\n\n\nsetup(\n    name=about[\"__title__\"],\n    version=about[\"__version__\"],\n\n    description=about[\"__summary__\"],\n    long_description=long_description,\n    license=about[\"__license__\"],\n    url=about[\"__uri__\"],\n\n    author=about[\"__author__\"],\n    author_email=about[\"__email__\"],\n\n    classifiers=[\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: Apache Software License\",\n        \"License :: OSI Approved :: BSD License\",\n        \"Natural Language :: English\",\n        \"Operating System :: MacOS :: MacOS X\",\n        \"Operating System :: POSIX\",\n        \"Operating System :: POSIX :: BSD\",\n        \"Operating System :: POSIX :: Linux\",\n        \"Operating System :: Microsoft :: Windows\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 2.6\",\n        \"Programming Language :: Python :: 2.7\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.2\",\n        \"Programming Language :: Python :: 3.3\",\n        \"Programming Language :: Python :: 3.4\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Security :: Cryptography\",\n    ],\n\n    package_dir={\"\": \"src\"},\n    packages=find_packages(where=\"src\", exclude=[\"tests\", \"tests.*\"]),\n    include_package_data=True,\n\n    install_requires=requirements,\n    tests_require=test_requirements,\n\n    # for cffi\n    zip_safe=False,\n    ext_package=\"cryptography\",\n    entry_points={\n        \"cryptography.backends\": backends,\n    },\n    **keywords_with_side_effects(sys.argv)\n)\n", "path": "setup.py"}]}