diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2015-12-07 22:50:39 -0600 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2015-12-07 22:50:39 -0600 |
| commit | 5021da880c1c922626095511dfd6c848ae82d7fd (patch) | |
| tree | 437aed84b45f1708edff116230f2dc0410e57cda /flake8/engine.py | |
| parent | d5e3987a9c41ae8cd007fe21f6aeb5e972ad0d3d (diff) | |
| download | flake8-5021da880c1c922626095511dfd6c848ae82d7fd.tar.gz | |
Update stdin_get_value monkey-patching
Let's use an enclosed function to replace the stdin_get_value function
on pep8.
Closes #107
Diffstat (limited to 'flake8/engine.py')
| -rw-r--r-- | flake8/engine.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/flake8/engine.py b/flake8/engine.py index e90940e..d929f83 100644 --- a/flake8/engine.py +++ b/flake8/engine.py @@ -297,13 +297,20 @@ def get_python_version(): return '%s%s on %s' % (impl, platform.python_version(), platform.system()) -def make_stdin_get_value(): - value = pep8.stdin_get_value() - if sys.version_info < (3, 0): - stdin = io.BytesIO(value) - else: - stdin = io.StringIO(value) - return stdin.getvalue +def make_stdin_get_value(original): + def stdin_get_value(): + if not hasattr(stdin_get_value, 'cached_stdin'): + value = original() + if sys.version_info < (3, 0): + stdin = io.BytesIO(value) + else: + stdin = io.StringIO(value) + stdin_get_value.cached_stdin = stdin + else: + stdin = stdin_get_value.cached_stdin + return stdin.getvalue() + + return stdin_get_value -pep8.stdin_get_value = make_stdin_get_value() +pep8.stdin_get_value = make_stdin_get_value(pep8.stdin_get_value) |
