mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-15 16:49:52 +00:00
Add caching stdin_get_value function
This commit is contained in:
parent
1543ff8bab
commit
253211f5ad
1 changed files with 15 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
"""Utility methods for flake8."""
|
"""Utility methods for flake8."""
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def parse_comma_separated_list(value):
|
def parse_comma_separated_list(value):
|
||||||
|
|
@ -43,3 +45,16 @@ def normalize_path(path, parent=os.curdir):
|
||||||
if '/' in path:
|
if '/' in path:
|
||||||
path = os.path.abspath(os.path.join(parent, path))
|
path = os.path.abspath(os.path.join(parent, path))
|
||||||
return path.rstrip('/')
|
return path.rstrip('/')
|
||||||
|
|
||||||
|
|
||||||
|
def stdin_get_value():
|
||||||
|
"""Get and cache it so plugins can use it."""
|
||||||
|
cached_value = getattr(stdin_get_value, 'cached_stdin', None)
|
||||||
|
if cached_value is None:
|
||||||
|
stdin_value = sys.stdin.read()
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
cached_value = io.BytesIO(stdin_value)
|
||||||
|
else:
|
||||||
|
cached_value = io.StringIO(stdin_value)
|
||||||
|
stdin_get_value.cached_stdin = cached_value
|
||||||
|
return cached_value.getvalue()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue