summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
committerShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
commit227b2d30a8675b44918f9d9ca89b24144a938215 (patch)
tree9f8e6a28724514b6fdf463a9ab2067a7ef309b72 /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py
parent842a8cfbbbdb1f92889d892e4859dbd5d40c5be8 (diff)
removing venv files
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py132
1 files changed, 0 insertions, 132 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py
deleted file mode 100644
index 1fb3e8a..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/logging.py
+++ /dev/null
@@ -1,132 +0,0 @@
1from __future__ import absolute_import
2
3import contextlib
4import logging
5import logging.handlers
6import os
7
8from pip._internal.compat import WINDOWS
9from pip._internal.utils.misc import ensure_dir
10
11try:
12 import threading
13except ImportError:
14 import dummy_threading as threading # type: ignore
15
16
17try:
18 from pip._vendor import colorama
19# Lots of different errors can come from this, including SystemError and
20# ImportError.
21except Exception:
22 colorama = None
23
24
25_log_state = threading.local()
26_log_state.indentation = 0
27
28
29@contextlib.contextmanager
30def indent_log(num=2):
31 """
32 A context manager which will cause the log output to be indented for any
33 log messages emitted inside it.
34 """
35 _log_state.indentation += num
36 try:
37 yield
38 finally:
39 _log_state.indentation -= num
40
41
42def get_indentation():
43 return getattr(_log_state, 'indentation', 0)
44
45
46class IndentingFormatter(logging.Formatter):
47
48 def format(self, record):
49 """
50 Calls the standard formatter, but will indent all of the log messages
51 by our current indentation level.
52 """
53 formatted = logging.Formatter.format(self, record)
54 formatted = "".join([
55 (" " * get_indentation()) + line
56 for line in formatted.splitlines(True)
57 ])
58 return formatted
59
60
61def _color_wrap(*colors):
62 def wrapped(inp):
63 return "".join(list(colors) + [inp, colorama.Style.RESET_ALL])
64 return wrapped
65
66
67class ColorizedStreamHandler(logging.StreamHandler):
68
69 # Don't build up a list of colors if we don't have colorama
70 if colorama:
71 COLORS = [
72 # This needs to be in order from highest logging level to lowest.
73 (logging.ERROR, _color_wrap(colorama.Fore.RED)),
74 (logging.WARNING, _color_wrap(colorama.Fore.YELLOW)),
75 ]
76 else:
77 COLORS = []
78
79 def __init__(self, stream=None, no_color=None):
80 logging.StreamHandler.__init__(self, stream)
81 self._no_color = no_color
82
83 if WINDOWS and colorama:
84 self.stream = colorama.AnsiToWin32(self.stream)
85
86 def should_color(self):
87 # Don't colorize things if we do not have colorama or if told not to
88 if not colorama or self._no_color:
89 return False
90
91 real_stream = (
92 self.stream if not isinstance(self.stream, colorama.AnsiToWin32)
93 else self.stream.wrapped
94 )
95
96 # If the stream is a tty we should color it
97 if hasattr(real_stream, "isatty") and real_stream.isatty():
98 return True
99
100 # If we have an ASNI term we should color it
101 if os.environ.get("TERM") == "ANSI":
102 return True
103
104 # If anything else we should not color it
105 return False
106
107 def format(self, record):
108 msg = logging.StreamHandler.format(self, record)
109
110 if self.should_color():
111 for level, color in self.COLORS:
112 if record.levelno >= level:
113 msg = color(msg)
114 break
115
116 return msg
117
118
119class BetterRotatingFileHandler(logging.handlers.RotatingFileHandler):
120
121 def _open(self):
122 ensure_dir(os.path.dirname(self.baseFilename))
123 return logging.handlers.RotatingFileHandler._open(self)
124
125
126class MaxLevelFilter(logging.Filter):
127
128 def __init__(self, level):
129 self.level = level
130
131 def filter(self, record):
132 return record.levelno < self.level