|
| 1 | +import sys |
1 | 2 | import logging
|
2 | 3 | import json
|
3 | 4 | import textwrap
|
4 | 5 | from json.encoder import JSONEncoder
|
5 | 6 | from logging import StreamHandler, Formatter, FileHandler
|
6 |
| -from ethereum.utils import bcolors, isnumeric |
7 | 7 |
|
8 | 8 |
|
9 | 9 | DEFAULT_LOGLEVEL = 'INFO'
|
|
20 | 20 | log_listeners = []
|
21 | 21 |
|
22 | 22 |
|
| 23 | +if sys.version_info.major == 2: |
| 24 | + integer_types = (int, long) |
| 25 | + number_types = (int, long, float, complex) |
| 26 | +else: |
| 27 | + integer_types = (int,) |
| 28 | + number_types = (int, float, complex) |
| 29 | + |
| 30 | + |
| 31 | +def is_integer(value): |
| 32 | + return isinstance(value, integer_types) |
| 33 | + |
| 34 | + |
| 35 | +def is_number(value): |
| 36 | + return isinstance(value, number_types) |
| 37 | + |
| 38 | + |
| 39 | +class bcolors: |
| 40 | + HEADER = '\033[95m' |
| 41 | + OKBLUE = '\033[94m' |
| 42 | + OKGREEN = '\033[92m' |
| 43 | + WARNING = '\033[91m' |
| 44 | + FAIL = '\033[91m' |
| 45 | + ENDC = '\033[0m' |
| 46 | + BOLD = '\033[1m' |
| 47 | + UNDERLINE = '\033[4m' |
| 48 | + |
| 49 | + |
23 | 50 | def _inject_into_logger(name, code, namespace=None):
|
24 | 51 | # This is a hack to fool the logging module into reporting correct source files.
|
25 | 52 | # It determines the actual source of a logging call by inspecting the stack frame's
|
@@ -190,7 +217,7 @@ def format_message(self, msg, kwargs, highlight, level):
|
190 | 217 | msg = json.dumps(message, cls=_LogJSONEncoder)
|
191 | 218 | except UnicodeDecodeError:
|
192 | 219 | message.update({
|
193 |
| - k: v if isnumeric(v) or isinstance(v, (float, complex)) else repr(v) |
| 220 | + k: v if is_number(v) else repr(v) |
194 | 221 | for k, v in kwargs.items()
|
195 | 222 | })
|
196 | 223 | msg = json.dumps(message, cls=_LogJSONEncoder)
|
@@ -260,7 +287,7 @@ def _stringify_dict_keys(input_):
|
260 | 287 | res = {}
|
261 | 288 | for k, v in input_.items():
|
262 | 289 | v = _stringify_dict_keys(v)
|
263 |
| - if not isinstance(k, (int, long, bool, None.__class__)): |
| 290 | + if not is_integer(k) and not isinstance(k, (bool, None.__class__)): |
264 | 291 | k = str(k)
|
265 | 292 | res[k] = v
|
266 | 293 | elif isinstance(input_, (list, tuple)):
|
|
0 commit comments