diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-01 12:07:00 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-01 12:07:00 -0500 |
| commit | 2e236152228a7d2aec383fcecd70731f96ad4de3 (patch) | |
| tree | 61a32be2a039652feaa02d5a8c862b7e05877dac /pkg_resources | |
| parent | ff260515fc50b2aaf07558f9ded076c7450fc614 (diff) | |
| download | python-setuptools-git-2e236152228a7d2aec383fcecd70731f96ad4de3.tar.gz | |
Extract a a method to encapsulate behavior and documentation. Rewrite for loop as legacy-style dictionary comprehension.
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index df662dfe..fb8704fd 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1525,6 +1525,17 @@ class MarkerEvaluation(object): """ return cls.interpret(parser.expr(text).totuple(1)[1]) + @staticmethod + def _translate_metadata2(env): + """ + Markerlib implements Metadata 1.2 (PEP 345) environment markers. + Translate the variables to Metadata 2.0 (PEP 426). + """ + return dict( + (key.replace('.', '_'), value) + for key, value in env + ) + @classmethod def _markerlib_evaluate(cls, text): """ @@ -1533,12 +1544,8 @@ class MarkerEvaluation(object): Raise SyntaxError if marker is invalid. """ import _markerlib - # markerlib implements Metadata 1.2 (PEP 345) environment markers. - # Translate the variables to Metadata 2.0 (PEP 426). - env = _markerlib.default_environment() - for key in tuple(env.keys()): - new_key = key.replace('.', '_') - env[new_key] = env.pop(key) + + env = cls._translate_metadata2(_markerlib.default_environment()) try: result = _markerlib.interpret(text, env) except NameError as e: |
