We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'and plat'"
Originally reported by: **Anonymous**

---

../ve/bin/python setup.py --quiet develop
Traceback (most recent call last):
  File "setup.py", line 92, in <module>
    setup(**config)
  File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/develop.py", line 34, in run
  File "build/bdist.linux-x86_64/egg/setuptools/command/develop.py", line 133, in install_for_development
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 720, in process_distribution

  File "build/bdist.linux-x86_64/egg/pkg_resources/**init**.py", line 838, in resolve
  File "build/bdist.linux-x86_64/egg/pkg_resources/**init**.py", line 2462, in requires
  File "build/bdist.linux-x86_64/egg/pkg_resources/**init**.py", line 2686, in _dep_map
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2696, in _compute_dependencies
  File "build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/requirements.py", line 94, in __init__
pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'and plat'"

Version 20.1 works fine, 20.2 breaks.

---
- Bitbucket: https://bitbucket.org/pypa/setuptools/issue/503


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pkg_resources/_vendor/packaging/__about__.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 from __future__ import absolute_import, division, print_function
5 
6 __all__ = [
7     "__title__", "__summary__", "__uri__", "__version__", "__author__",
8     "__email__", "__license__", "__copyright__",
9 ]
10 
11 __title__ = "packaging"
12 __summary__ = "Core utilities for Python packages"
13 __uri__ = "https://github.com/pypa/packaging"
14 
15 __version__ = "16.5"
16 
17 __author__ = "Donald Stufft and individual contributors"
18 __email__ = "donald@stufft.io"
19 
20 __license__ = "BSD or Apache License, Version 2.0"
21 __copyright__ = "Copyright 2014-2016 %s" % __author__
22
```

Path: `pkg_resources/_vendor/packaging/markers.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 from __future__ import absolute_import, division, print_function
5 
6 import operator
7 import os
8 import platform
9 import sys
10 
11 from pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd
12 from pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString
13 from pkg_resources.extern.pyparsing import Literal as L  # noqa
14 
15 from ._compat import string_types
16 from .specifiers import Specifier, InvalidSpecifier
17 
18 
19 __all__ = [
20     "InvalidMarker", "UndefinedComparison", "UndefinedEnvironmentName",
21     "Marker", "default_environment",
22 ]
23 
24 
25 class InvalidMarker(ValueError):
26     """
27     An invalid marker was found, users should refer to PEP 508.
28     """
29 
30 
31 class UndefinedComparison(ValueError):
32     """
33     An invalid operation was attempted on a value that doesn't support it.
34     """
35 
36 
37 class UndefinedEnvironmentName(ValueError):
38     """
39     A name was attempted to be used that does not exist inside of the
40     environment.
41     """
42 
43 
44 class Node(object):
45 
46     def __init__(self, value):
47         self.value = value
48 
49     def __str__(self):
50         return str(self.value)
51 
52     def __repr__(self):
53         return "<{0}({1!r})>".format(self.__class__.__name__, str(self))
54 
55 
56 class Variable(Node):
57     pass
58 
59 
60 class Value(Node):
61     pass
62 
63 
64 VARIABLE = (
65     L("implementation_version") |
66     L("platform_python_implementation") |
67     L("implementation_name") |
68     L("python_full_version") |
69     L("platform_release") |
70     L("platform_version") |
71     L("platform_machine") |
72     L("platform_system") |
73     L("python_version") |
74     L("sys_platform") |
75     L("os_name") |
76     L("extra")
77 )
78 VARIABLE.setParseAction(lambda s, l, t: Variable(t[0]))
79 
80 VERSION_CMP = (
81     L("===") |
82     L("==") |
83     L(">=") |
84     L("<=") |
85     L("!=") |
86     L("~=") |
87     L(">") |
88     L("<")
89 )
90 
91 MARKER_OP = VERSION_CMP | L("not in") | L("in")
92 
93 MARKER_VALUE = QuotedString("'") | QuotedString('"')
94 MARKER_VALUE.setParseAction(lambda s, l, t: Value(t[0]))
95 
96 BOOLOP = L("and") | L("or")
97 
98 MARKER_VAR = VARIABLE | MARKER_VALUE
99 
100 MARKER_ITEM = Group(MARKER_VAR + MARKER_OP + MARKER_VAR)
101 MARKER_ITEM.setParseAction(lambda s, l, t: tuple(t[0]))
102 
103 LPAREN = L("(").suppress()
104 RPAREN = L(")").suppress()
105 
106 MARKER_EXPR = Forward()
107 MARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN)
108 MARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR)
109 
110 MARKER = stringStart + MARKER_EXPR + stringEnd
111 
112 
113 def _coerce_parse_result(results):
114     if isinstance(results, ParseResults):
115         return [_coerce_parse_result(i) for i in results]
116     else:
117         return results
118 
119 
120 def _format_marker(marker, first=True):
121     assert isinstance(marker, (list, tuple, string_types))
122 
123     # Sometimes we have a structure like [[...]] which is a single item list
124     # where the single item is itself it's own list. In that case we want skip
125     # the rest of this function so that we don't get extraneous () on the
126     # outside.
127     if (isinstance(marker, list) and len(marker) == 1 and
128             isinstance(marker[0], (list, tuple))):
129         return _format_marker(marker[0])
130 
131     if isinstance(marker, list):
132         inner = (_format_marker(m, first=False) for m in marker)
133         if first:
134             return " ".join(inner)
135         else:
136             return "(" + " ".join(inner) + ")"
137     elif isinstance(marker, tuple):
138         return '{0} {1} "{2}"'.format(*marker)
139     else:
140         return marker
141 
142 
143 _operators = {
144     "in": lambda lhs, rhs: lhs in rhs,
145     "not in": lambda lhs, rhs: lhs not in rhs,
146     "<": operator.lt,
147     "<=": operator.le,
148     "==": operator.eq,
149     "!=": operator.ne,
150     ">=": operator.ge,
151     ">": operator.gt,
152 }
153 
154 
155 def _eval_op(lhs, op, rhs):
156     try:
157         spec = Specifier("".join([op, rhs]))
158     except InvalidSpecifier:
159         pass
160     else:
161         return spec.contains(lhs)
162 
163     oper = _operators.get(op)
164     if oper is None:
165         raise UndefinedComparison(
166             "Undefined {0!r} on {1!r} and {2!r}.".format(op, lhs, rhs)
167         )
168 
169     return oper(lhs, rhs)
170 
171 
172 _undefined = object()
173 
174 
175 def _get_env(environment, name):
176     value = environment.get(name, _undefined)
177 
178     if value is _undefined:
179         raise UndefinedEnvironmentName(
180             "{0!r} does not exist in evaluation environment.".format(name)
181         )
182 
183     return value
184 
185 
186 def _evaluate_markers(markers, environment):
187     groups = [[]]
188 
189     for marker in markers:
190         assert isinstance(marker, (list, tuple, string_types))
191 
192         if isinstance(marker, list):
193             groups[-1].append(_evaluate_markers(marker, environment))
194         elif isinstance(marker, tuple):
195             lhs, op, rhs = marker
196 
197             if isinstance(lhs, Variable):
198                 lhs_value = _get_env(environment, lhs.value)
199                 rhs_value = rhs.value
200             else:
201                 lhs_value = lhs.value
202                 rhs_value = _get_env(environment, rhs.value)
203 
204             groups[-1].append(_eval_op(lhs_value, op, rhs_value))
205         else:
206             assert marker in ["and", "or"]
207             if marker == "or":
208                 groups.append([])
209 
210     return any(all(item) for item in groups)
211 
212 
213 def format_full_version(info):
214     version = '{0.major}.{0.minor}.{0.micro}'.format(info)
215     kind = info.releaselevel
216     if kind != 'final':
217         version += kind[0] + str(info.serial)
218     return version
219 
220 
221 def default_environment():
222     if hasattr(sys, 'implementation'):
223         iver = format_full_version(sys.implementation.version)
224         implementation_name = sys.implementation.name
225     else:
226         iver = '0'
227         implementation_name = ''
228 
229     return {
230         "implementation_name": implementation_name,
231         "implementation_version": iver,
232         "os_name": os.name,
233         "platform_machine": platform.machine(),
234         "platform_release": platform.release(),
235         "platform_system": platform.system(),
236         "platform_version": platform.version(),
237         "python_full_version": platform.python_version(),
238         "platform_python_implementation": platform.python_implementation(),
239         "python_version": platform.python_version()[:3],
240         "sys_platform": sys.platform,
241     }
242 
243 
244 class Marker(object):
245 
246     def __init__(self, marker):
247         try:
248             self._markers = _coerce_parse_result(MARKER.parseString(marker))
249         except ParseException as e:
250             err_str = "Invalid marker: {0!r}, parse error at {1!r}".format(
251                 marker, marker[e.loc:e.loc + 8])
252             raise InvalidMarker(err_str)
253 
254     def __str__(self):
255         return _format_marker(self._markers)
256 
257     def __repr__(self):
258         return "<Marker({0!r})>".format(str(self))
259 
260     def evaluate(self, environment=None):
261         """Evaluate a marker.
262 
263         Return the boolean from evaluating the given marker against the
264         environment. environment is an optional argument to override all or
265         part of the determined environment.
266 
267         The environment is determined from the current Python process.
268         """
269         current_environment = default_environment()
270         if environment is not None:
271             current_environment.update(environment)
272 
273         return _evaluate_markers(self._markers, current_environment)
274
```
--- 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/pkg_resources/_vendor/packaging/__about__.py b/pkg_resources/_vendor/packaging/__about__.py
--- a/pkg_resources/_vendor/packaging/__about__.py
+++ b/pkg_resources/_vendor/packaging/__about__.py
@@ -12,7 +12,7 @@
 __summary__ = "Core utilities for Python packages"
 __uri__ = "https://github.com/pypa/packaging"
 
-__version__ = "16.5"
+__version__ = "16.6"
 
 __author__ = "Donald Stufft and individual contributors"
 __email__ = "donald@stufft.io"
diff --git a/pkg_resources/_vendor/packaging/markers.py b/pkg_resources/_vendor/packaging/markers.py
--- a/pkg_resources/_vendor/packaging/markers.py
+++ b/pkg_resources/_vendor/packaging/markers.py
@@ -73,9 +73,14 @@
     L("python_version") |
     L("sys_platform") |
     L("os_name") |
+    L("os.name") |  # PEP-345
+    L("sys.platform") |  # PEP-345
+    L("platform.version") |  # PEP-345
+    L("platform.machine") |  # PEP-345
+    L("platform.python_implementation") |  # PEP-345
     L("extra")
 )
-VARIABLE.setParseAction(lambda s, l, t: Variable(t[0]))
+VARIABLE.setParseAction(lambda s, l, t: Variable(t[0].replace('.', '_')))
 
 VERSION_CMP = (
     L("===") |

{"golden_diff": "diff --git a/pkg_resources/_vendor/packaging/__about__.py b/pkg_resources/_vendor/packaging/__about__.py\n--- a/pkg_resources/_vendor/packaging/__about__.py\n+++ b/pkg_resources/_vendor/packaging/__about__.py\n@@ -12,7 +12,7 @@\n __summary__ = \"Core utilities for Python packages\"\n __uri__ = \"https://github.com/pypa/packaging\"\n \n-__version__ = \"16.5\"\n+__version__ = \"16.6\"\n \n __author__ = \"Donald Stufft and individual contributors\"\n __email__ = \"donald@stufft.io\"\ndiff --git a/pkg_resources/_vendor/packaging/markers.py b/pkg_resources/_vendor/packaging/markers.py\n--- a/pkg_resources/_vendor/packaging/markers.py\n+++ b/pkg_resources/_vendor/packaging/markers.py\n@@ -73,9 +73,14 @@\n     L(\"python_version\") |\n     L(\"sys_platform\") |\n     L(\"os_name\") |\n+    L(\"os.name\") |  # PEP-345\n+    L(\"sys.platform\") |  # PEP-345\n+    L(\"platform.version\") |  # PEP-345\n+    L(\"platform.machine\") |  # PEP-345\n+    L(\"platform.python_implementation\") |  # PEP-345\n     L(\"extra\")\n )\n-VARIABLE.setParseAction(lambda s, l, t: Variable(t[0]))\n+VARIABLE.setParseAction(lambda s, l, t: Variable(t[0].replace('.', '_')))\n \n VERSION_CMP = (\n     L(\"===\") |\n", "issue": "pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at \"'and plat'\"\nOriginally reported by: **Anonymous**\n\n---\n\n../ve/bin/python setup.py --quiet develop\nTraceback (most recent call last):\n  File \"setup.py\", line 92, in <module>\n    setup(**config)\n  File \"/usr/lib64/python2.7/distutils/core.py\", line 152, in setup\n    dist.run_commands()\n  File \"/usr/lib64/python2.7/distutils/dist.py\", line 953, in run_commands\n    self.run_command(cmd)\n  File \"/usr/lib64/python2.7/distutils/dist.py\", line 972, in run_command\n    cmd_obj.run()\n  File \"build/bdist.linux-x86_64/egg/setuptools/command/develop.py\", line 34, in run\n  File \"build/bdist.linux-x86_64/egg/setuptools/command/develop.py\", line 133, in install_for_development\n  File \"build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py\", line 720, in process_distribution\n\n  File \"build/bdist.linux-x86_64/egg/pkg_resources/**init**.py\", line 838, in resolve\n  File \"build/bdist.linux-x86_64/egg/pkg_resources/**init**.py\", line 2462, in requires\n  File \"build/bdist.linux-x86_64/egg/pkg_resources/**init**.py\", line 2686, in _dep_map\n  File \"build/bdist.linux-x86_64/egg/pkg_resources/__init__.py\", line 2696, in _compute_dependencies\n  File \"build/bdist.linux-x86_64/egg/pkg_resources/_vendor/packaging/requirements.py\", line 94, in __init__\npkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at \"'and plat'\"\n\nVersion 20.1 works fine, 20.2 breaks.\n\n---\n- Bitbucket: https://bitbucket.org/pypa/setuptools/issue/503\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.\nfrom __future__ import absolute_import, division, print_function\n\n__all__ = [\n    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__author__\",\n    \"__email__\", \"__license__\", \"__copyright__\",\n]\n\n__title__ = \"packaging\"\n__summary__ = \"Core utilities for Python packages\"\n__uri__ = \"https://github.com/pypa/packaging\"\n\n__version__ = \"16.5\"\n\n__author__ = \"Donald Stufft and individual contributors\"\n__email__ = \"donald@stufft.io\"\n\n__license__ = \"BSD or Apache License, Version 2.0\"\n__copyright__ = \"Copyright 2014-2016 %s\" % __author__\n", "path": "pkg_resources/_vendor/packaging/__about__.py"}, {"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.\nfrom __future__ import absolute_import, division, print_function\n\nimport operator\nimport os\nimport platform\nimport sys\n\nfrom pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd\nfrom pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString\nfrom pkg_resources.extern.pyparsing import Literal as L  # noqa\n\nfrom ._compat import string_types\nfrom .specifiers import Specifier, InvalidSpecifier\n\n\n__all__ = [\n    \"InvalidMarker\", \"UndefinedComparison\", \"UndefinedEnvironmentName\",\n    \"Marker\", \"default_environment\",\n]\n\n\nclass InvalidMarker(ValueError):\n    \"\"\"\n    An invalid marker was found, users should refer to PEP 508.\n    \"\"\"\n\n\nclass UndefinedComparison(ValueError):\n    \"\"\"\n    An invalid operation was attempted on a value that doesn't support it.\n    \"\"\"\n\n\nclass UndefinedEnvironmentName(ValueError):\n    \"\"\"\n    A name was attempted to be used that does not exist inside of the\n    environment.\n    \"\"\"\n\n\nclass Node(object):\n\n    def __init__(self, value):\n        self.value = value\n\n    def __str__(self):\n        return str(self.value)\n\n    def __repr__(self):\n        return \"<{0}({1!r})>\".format(self.__class__.__name__, str(self))\n\n\nclass Variable(Node):\n    pass\n\n\nclass Value(Node):\n    pass\n\n\nVARIABLE = (\n    L(\"implementation_version\") |\n    L(\"platform_python_implementation\") |\n    L(\"implementation_name\") |\n    L(\"python_full_version\") |\n    L(\"platform_release\") |\n    L(\"platform_version\") |\n    L(\"platform_machine\") |\n    L(\"platform_system\") |\n    L(\"python_version\") |\n    L(\"sys_platform\") |\n    L(\"os_name\") |\n    L(\"extra\")\n)\nVARIABLE.setParseAction(lambda s, l, t: Variable(t[0]))\n\nVERSION_CMP = (\n    L(\"===\") |\n    L(\"==\") |\n    L(\">=\") |\n    L(\"<=\") |\n    L(\"!=\") |\n    L(\"~=\") |\n    L(\">\") |\n    L(\"<\")\n)\n\nMARKER_OP = VERSION_CMP | L(\"not in\") | L(\"in\")\n\nMARKER_VALUE = QuotedString(\"'\") | QuotedString('\"')\nMARKER_VALUE.setParseAction(lambda s, l, t: Value(t[0]))\n\nBOOLOP = L(\"and\") | L(\"or\")\n\nMARKER_VAR = VARIABLE | MARKER_VALUE\n\nMARKER_ITEM = Group(MARKER_VAR + MARKER_OP + MARKER_VAR)\nMARKER_ITEM.setParseAction(lambda s, l, t: tuple(t[0]))\n\nLPAREN = L(\"(\").suppress()\nRPAREN = L(\")\").suppress()\n\nMARKER_EXPR = Forward()\nMARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN)\nMARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR)\n\nMARKER = stringStart + MARKER_EXPR + stringEnd\n\n\ndef _coerce_parse_result(results):\n    if isinstance(results, ParseResults):\n        return [_coerce_parse_result(i) for i in results]\n    else:\n        return results\n\n\ndef _format_marker(marker, first=True):\n    assert isinstance(marker, (list, tuple, string_types))\n\n    # Sometimes we have a structure like [[...]] which is a single item list\n    # where the single item is itself it's own list. In that case we want skip\n    # the rest of this function so that we don't get extraneous () on the\n    # outside.\n    if (isinstance(marker, list) and len(marker) == 1 and\n            isinstance(marker[0], (list, tuple))):\n        return _format_marker(marker[0])\n\n    if isinstance(marker, list):\n        inner = (_format_marker(m, first=False) for m in marker)\n        if first:\n            return \" \".join(inner)\n        else:\n            return \"(\" + \" \".join(inner) + \")\"\n    elif isinstance(marker, tuple):\n        return '{0} {1} \"{2}\"'.format(*marker)\n    else:\n        return marker\n\n\n_operators = {\n    \"in\": lambda lhs, rhs: lhs in rhs,\n    \"not in\": lambda lhs, rhs: lhs not in rhs,\n    \"<\": operator.lt,\n    \"<=\": operator.le,\n    \"==\": operator.eq,\n    \"!=\": operator.ne,\n    \">=\": operator.ge,\n    \">\": operator.gt,\n}\n\n\ndef _eval_op(lhs, op, rhs):\n    try:\n        spec = Specifier(\"\".join([op, rhs]))\n    except InvalidSpecifier:\n        pass\n    else:\n        return spec.contains(lhs)\n\n    oper = _operators.get(op)\n    if oper is None:\n        raise UndefinedComparison(\n            \"Undefined {0!r} on {1!r} and {2!r}.\".format(op, lhs, rhs)\n        )\n\n    return oper(lhs, rhs)\n\n\n_undefined = object()\n\n\ndef _get_env(environment, name):\n    value = environment.get(name, _undefined)\n\n    if value is _undefined:\n        raise UndefinedEnvironmentName(\n            \"{0!r} does not exist in evaluation environment.\".format(name)\n        )\n\n    return value\n\n\ndef _evaluate_markers(markers, environment):\n    groups = [[]]\n\n    for marker in markers:\n        assert isinstance(marker, (list, tuple, string_types))\n\n        if isinstance(marker, list):\n            groups[-1].append(_evaluate_markers(marker, environment))\n        elif isinstance(marker, tuple):\n            lhs, op, rhs = marker\n\n            if isinstance(lhs, Variable):\n                lhs_value = _get_env(environment, lhs.value)\n                rhs_value = rhs.value\n            else:\n                lhs_value = lhs.value\n                rhs_value = _get_env(environment, rhs.value)\n\n            groups[-1].append(_eval_op(lhs_value, op, rhs_value))\n        else:\n            assert marker in [\"and\", \"or\"]\n            if marker == \"or\":\n                groups.append([])\n\n    return any(all(item) for item in groups)\n\n\ndef format_full_version(info):\n    version = '{0.major}.{0.minor}.{0.micro}'.format(info)\n    kind = info.releaselevel\n    if kind != 'final':\n        version += kind[0] + str(info.serial)\n    return version\n\n\ndef default_environment():\n    if hasattr(sys, 'implementation'):\n        iver = format_full_version(sys.implementation.version)\n        implementation_name = sys.implementation.name\n    else:\n        iver = '0'\n        implementation_name = ''\n\n    return {\n        \"implementation_name\": implementation_name,\n        \"implementation_version\": iver,\n        \"os_name\": os.name,\n        \"platform_machine\": platform.machine(),\n        \"platform_release\": platform.release(),\n        \"platform_system\": platform.system(),\n        \"platform_version\": platform.version(),\n        \"python_full_version\": platform.python_version(),\n        \"platform_python_implementation\": platform.python_implementation(),\n        \"python_version\": platform.python_version()[:3],\n        \"sys_platform\": sys.platform,\n    }\n\n\nclass Marker(object):\n\n    def __init__(self, marker):\n        try:\n            self._markers = _coerce_parse_result(MARKER.parseString(marker))\n        except ParseException as e:\n            err_str = \"Invalid marker: {0!r}, parse error at {1!r}\".format(\n                marker, marker[e.loc:e.loc + 8])\n            raise InvalidMarker(err_str)\n\n    def __str__(self):\n        return _format_marker(self._markers)\n\n    def __repr__(self):\n        return \"<Marker({0!r})>\".format(str(self))\n\n    def evaluate(self, environment=None):\n        \"\"\"Evaluate a marker.\n\n        Return the boolean from evaluating the given marker against the\n        environment. environment is an optional argument to override all or\n        part of the determined environment.\n\n        The environment is determined from the current Python process.\n        \"\"\"\n        current_environment = default_environment()\n        if environment is not None:\n            current_environment.update(environment)\n\n        return _evaluate_markers(self._markers, current_environment)\n", "path": "pkg_resources/_vendor/packaging/markers.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.\nfrom __future__ import absolute_import, division, print_function\n\n__all__ = [\n    \"__title__\", \"__summary__\", \"__uri__\", \"__version__\", \"__author__\",\n    \"__email__\", \"__license__\", \"__copyright__\",\n]\n\n__title__ = \"packaging\"\n__summary__ = \"Core utilities for Python packages\"\n__uri__ = \"https://github.com/pypa/packaging\"\n\n__version__ = \"16.6\"\n\n__author__ = \"Donald Stufft and individual contributors\"\n__email__ = \"donald@stufft.io\"\n\n__license__ = \"BSD or Apache License, Version 2.0\"\n__copyright__ = \"Copyright 2014-2016 %s\" % __author__\n", "path": "pkg_resources/_vendor/packaging/__about__.py"}, {"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.\nfrom __future__ import absolute_import, division, print_function\n\nimport operator\nimport os\nimport platform\nimport sys\n\nfrom pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd\nfrom pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString\nfrom pkg_resources.extern.pyparsing import Literal as L  # noqa\n\nfrom ._compat import string_types\nfrom .specifiers import Specifier, InvalidSpecifier\n\n\n__all__ = [\n    \"InvalidMarker\", \"UndefinedComparison\", \"UndefinedEnvironmentName\",\n    \"Marker\", \"default_environment\",\n]\n\n\nclass InvalidMarker(ValueError):\n    \"\"\"\n    An invalid marker was found, users should refer to PEP 508.\n    \"\"\"\n\n\nclass UndefinedComparison(ValueError):\n    \"\"\"\n    An invalid operation was attempted on a value that doesn't support it.\n    \"\"\"\n\n\nclass UndefinedEnvironmentName(ValueError):\n    \"\"\"\n    A name was attempted to be used that does not exist inside of the\n    environment.\n    \"\"\"\n\n\nclass Node(object):\n\n    def __init__(self, value):\n        self.value = value\n\n    def __str__(self):\n        return str(self.value)\n\n    def __repr__(self):\n        return \"<{0}({1!r})>\".format(self.__class__.__name__, str(self))\n\n\nclass Variable(Node):\n    pass\n\n\nclass Value(Node):\n    pass\n\n\nVARIABLE = (\n    L(\"implementation_version\") |\n    L(\"platform_python_implementation\") |\n    L(\"implementation_name\") |\n    L(\"python_full_version\") |\n    L(\"platform_release\") |\n    L(\"platform_version\") |\n    L(\"platform_machine\") |\n    L(\"platform_system\") |\n    L(\"python_version\") |\n    L(\"sys_platform\") |\n    L(\"os_name\") |\n    L(\"os.name\") |  # PEP-345\n    L(\"sys.platform\") |  # PEP-345\n    L(\"platform.version\") |  # PEP-345\n    L(\"platform.machine\") |  # PEP-345\n    L(\"platform.python_implementation\") |  # PEP-345\n    L(\"extra\")\n)\nVARIABLE.setParseAction(lambda s, l, t: Variable(t[0].replace('.', '_')))\n\nVERSION_CMP = (\n    L(\"===\") |\n    L(\"==\") |\n    L(\">=\") |\n    L(\"<=\") |\n    L(\"!=\") |\n    L(\"~=\") |\n    L(\">\") |\n    L(\"<\")\n)\n\nMARKER_OP = VERSION_CMP | L(\"not in\") | L(\"in\")\n\nMARKER_VALUE = QuotedString(\"'\") | QuotedString('\"')\nMARKER_VALUE.setParseAction(lambda s, l, t: Value(t[0]))\n\nBOOLOP = L(\"and\") | L(\"or\")\n\nMARKER_VAR = VARIABLE | MARKER_VALUE\n\nMARKER_ITEM = Group(MARKER_VAR + MARKER_OP + MARKER_VAR)\nMARKER_ITEM.setParseAction(lambda s, l, t: tuple(t[0]))\n\nLPAREN = L(\"(\").suppress()\nRPAREN = L(\")\").suppress()\n\nMARKER_EXPR = Forward()\nMARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN)\nMARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR)\n\nMARKER = stringStart + MARKER_EXPR + stringEnd\n\n\ndef _coerce_parse_result(results):\n    if isinstance(results, ParseResults):\n        return [_coerce_parse_result(i) for i in results]\n    else:\n        return results\n\n\ndef _format_marker(marker, first=True):\n    assert isinstance(marker, (list, tuple, string_types))\n\n    # Sometimes we have a structure like [[...]] which is a single item list\n    # where the single item is itself it's own list. In that case we want skip\n    # the rest of this function so that we don't get extraneous () on the\n    # outside.\n    if (isinstance(marker, list) and len(marker) == 1 and\n            isinstance(marker[0], (list, tuple))):\n        return _format_marker(marker[0])\n\n    if isinstance(marker, list):\n        inner = (_format_marker(m, first=False) for m in marker)\n        if first:\n            return \" \".join(inner)\n        else:\n            return \"(\" + \" \".join(inner) + \")\"\n    elif isinstance(marker, tuple):\n        return '{0} {1} \"{2}\"'.format(*marker)\n    else:\n        return marker\n\n\n_operators = {\n    \"in\": lambda lhs, rhs: lhs in rhs,\n    \"not in\": lambda lhs, rhs: lhs not in rhs,\n    \"<\": operator.lt,\n    \"<=\": operator.le,\n    \"==\": operator.eq,\n    \"!=\": operator.ne,\n    \">=\": operator.ge,\n    \">\": operator.gt,\n}\n\n\ndef _eval_op(lhs, op, rhs):\n    try:\n        spec = Specifier(\"\".join([op, rhs]))\n    except InvalidSpecifier:\n        pass\n    else:\n        return spec.contains(lhs)\n\n    oper = _operators.get(op)\n    if oper is None:\n        raise UndefinedComparison(\n            \"Undefined {0!r} on {1!r} and {2!r}.\".format(op, lhs, rhs)\n        )\n\n    return oper(lhs, rhs)\n\n\n_undefined = object()\n\n\ndef _get_env(environment, name):\n    value = environment.get(name, _undefined)\n\n    if value is _undefined:\n        raise UndefinedEnvironmentName(\n            \"{0!r} does not exist in evaluation environment.\".format(name)\n        )\n\n    return value\n\n\ndef _evaluate_markers(markers, environment):\n    groups = [[]]\n\n    for marker in markers:\n        assert isinstance(marker, (list, tuple, string_types))\n\n        if isinstance(marker, list):\n            groups[-1].append(_evaluate_markers(marker, environment))\n        elif isinstance(marker, tuple):\n            lhs, op, rhs = marker\n\n            if isinstance(lhs, Variable):\n                lhs_value = _get_env(environment, lhs.value)\n                rhs_value = rhs.value\n            else:\n                lhs_value = lhs.value\n                rhs_value = _get_env(environment, rhs.value)\n\n            groups[-1].append(_eval_op(lhs_value, op, rhs_value))\n        else:\n            assert marker in [\"and\", \"or\"]\n            if marker == \"or\":\n                groups.append([])\n\n    return any(all(item) for item in groups)\n\n\ndef format_full_version(info):\n    version = '{0.major}.{0.minor}.{0.micro}'.format(info)\n    kind = info.releaselevel\n    if kind != 'final':\n        version += kind[0] + str(info.serial)\n    return version\n\n\ndef default_environment():\n    if hasattr(sys, 'implementation'):\n        iver = format_full_version(sys.implementation.version)\n        implementation_name = sys.implementation.name\n    else:\n        iver = '0'\n        implementation_name = ''\n\n    return {\n        \"implementation_name\": implementation_name,\n        \"implementation_version\": iver,\n        \"os_name\": os.name,\n        \"platform_machine\": platform.machine(),\n        \"platform_release\": platform.release(),\n        \"platform_system\": platform.system(),\n        \"platform_version\": platform.version(),\n        \"python_full_version\": platform.python_version(),\n        \"platform_python_implementation\": platform.python_implementation(),\n        \"python_version\": platform.python_version()[:3],\n        \"sys_platform\": sys.platform,\n    }\n\n\nclass Marker(object):\n\n    def __init__(self, marker):\n        try:\n            self._markers = _coerce_parse_result(MARKER.parseString(marker))\n        except ParseException as e:\n            err_str = \"Invalid marker: {0!r}, parse error at {1!r}\".format(\n                marker, marker[e.loc:e.loc + 8])\n            raise InvalidMarker(err_str)\n\n    def __str__(self):\n        return _format_marker(self._markers)\n\n    def __repr__(self):\n        return \"<Marker({0!r})>\".format(str(self))\n\n    def evaluate(self, environment=None):\n        \"\"\"Evaluate a marker.\n\n        Return the boolean from evaluating the given marker against the\n        environment. environment is an optional argument to override all or\n        part of the determined environment.\n\n        The environment is determined from the current Python process.\n        \"\"\"\n        current_environment = default_environment()\n        if environment is not None:\n            current_environment.update(environment)\n\n        return _evaluate_markers(self._markers, current_environment)\n", "path": "pkg_resources/_vendor/packaging/markers.py"}]}