Python colorama.Fore 模块,LIGHTWHITE_EX 实例源码
我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用colorama.Fore.LIGHTWHITE_EX。
def filter(self, record):
record.spent = record.relativeCreated // 1000
if iswindows:
record.fg = ''
elif record.levelname == 'DEBG':
record.fg = Fore.LIGHTBLACK_EX
elif record.levelname == 'INFO':
record.fg = Fore.LIGHTWHITE_EX
elif record.levelname == 'WARN':
record.fg = Fore.LIGHTYELLOW_EX
elif record.levelname == 'ERR ':
record.fg = Fore.LIGHTRED_EX
elif record.levelname == 'CRIT':
record.fg = Fore.RED
else:
record.fg = Fore.LIGHTWHITE_EX
return True
def success(self, msg, *args, **kwargs):
self._log(SUCCESS, BEERS_EMOJI + ' ' + Fore.LIGHTWHITE_EX + msg + Fore.RESET, args, **kwargs)
def addition(self, **kwargs):
self._log(ADDITION, **kwargs)
def _enable_shell_colors():
import sys
from colorama import Fore
sys.ps1 = Fore.LIGHTWHITE_EX + '?? >' + Fore.RESET + ' '
sys.ps2 = Fore.BLACK + '..' + Fore.LIGHTBLACK_EX + '.' + Fore.RESET + ' '
def info_format(print_type, text):
# info,prompt,alert,sleep
lb = '{0}[{1}'.format(Fore.LIGHTGREEN_EX, Style.RESET_ALL)
rb = '{0}]{1}'.format(Fore.LIGHTGREEN_EX, Style.RESET_ALL)
new_text = Fore.LIGHTWHITE_EX + text + Style.RESET_ALL
if print_type == 'info':
return '{0}{1}*{2}{3} {4}'.format(lb, Fore.LIGHTGREEN_EX, Style.RESET_ALL, rb, new_text)
elif print_type == 'prompt':
return '{0}{1}${2}{3} {4}'.format(lb, Fore.LIGHTYELLOW_EX, new_text)
elif print_type == 'alert':
return '{0}{1}!{2}{3} {4}'.format(lb, Fore.LIGHTRED_EX, new_text)
elif print_type == 'sleep':
return '{0}-{1} {2}'.format(lb, new_text)
def get_alerts(customer_name, status, quiet=False):
""" gets alerts """
# There are 3 other v1 posts passed per customer with varying payloads.The dictionary below is required to return
# the necessary data; modifying it can break the request (needs more testing). I know it is not pep8 (too long)
data_dict = {"name":"time","min_doc_count":0,"size":5,"type":"date_range","field":"last_behavior","date_ranges":[{"from":"now-1h","to":"now","label":"Last hour"},{"from":"now-24h","label":"Last day"},{"from":"now-7d","label":"Last week"},{"from":"now-30d","label":"Last 30 days"},{"from":"now-90d","label":"Last 90 days"}]},{"name":"status","type":"terms","field":"status"},{"name":"severity","type":"range","field":"max_severity","ranges":[{"from":80,"to":101,"label":"Critical","id":4},{"from":60,"to":80,"label":"High","id":3},{"from":40,"to":60,"label":"Medium","id":2},{"from":20,"to":40,"label":"Low","id":1},{"from":0,"to":20,"label":"Informational","id":0}]},{"name":"scenario","size":0,"field":"behaviors.scenario"},{"name":"assigned_to_uid","min_doc_count":1,"field":"assigned_to_uid","missing":"Unassigned"},{"name":"host","field":"device.hostname.raw","missing":"Unknown"},{"name":"triggering_file","field":"behaviors.filename.raw"}
s10 = falcon.post('https://falcon.crowdstrike.com/api2/detects/aggregates/detects/GET/v1', headers=header,
data=json.dumps(data_dict))
try:
if len(s10.json()['resources']) > 0:
# print(json.dumps(s10.json(),indent=4)) # full json data set!
cust_data = s10.json()
for bucket in cust_data['resources']:
if bucket['name'] == 'status':
for value in bucket['buckets']:
if value['label'] in status:
if 'count' in value and value['count'] > 0:
alert_str = info_format('alert', '{0}{1}{2} alert(s) detected!\n'.format(
Fore.LIGHTRED_EX, value['count'], Fore.LIGHTWHITE_EX))
alert_str += '----> {0}{1}{2}'.format(Fore.LIGHTGREEN_EX, customer_name, Style.RESET_ALL)
# print(json.dumps(bucket['buckets'],indent=4)) # for testing!
return alert_str
except KeyError:
if not quiet:
return info_format('alert', 'There was an issue retrieving alerts for {0}. Skipping...'.format(customer_name))
else:
return None
def create_tree(table: dict,
root: str,
mark: str,
f_pid: str="pid",
f_id: str="id",
f_label: str="item",
f_ctime: str="ctime",
v_none: str="null",
colors: bool=False) -> str:
"""
Creates the ascii checkpoint tree.
Args:
table: List of checkpoints as a table.
root: Root label of the tree.
mark: Current snapshot name. Mark the element with an '*'
f_pid: Field of the table that contains the parent id of the node.
f_id: Field of the table that contains the id of the node.
f_label: Field with the label of the node.
f_ctime: Field with the timestamp creation date.
v_none: Value to be used for empty fields.
colors: Use colors in the tree output.
Returns:
A string containing the tree of snapshots
"""
items = [(c[f_pid], c[f_id]) for c in table]
tree = {root: OD()}
inserted = []
while [x[1] for x in items if x[1] not in inserted]:
for parent, item in items:
if parent == v_none:
parent = root
inserts = walk(tree, parent, item)
inserted.extend(list(inserts))
tr = LeftAligned()
tr_tree = tr(tree)
for cell in table:
if cell[f_label] == mark:
cell[f_label] = "{}*".format(cell[f_label])
if colors:
tr_tree = tr_tree.replace(cell[f_id],
"{}{} {}({}){}".format(
Fore.LIGHTWHITE_EX,
cell[f_label],
Fore.CYAN,
convert_dt(cell[f_ctime]),
Fore.RESET))
else:
tr_tree = tr_tree.replace(cell[f_id],
"{} ({})".format(
cell[f_label],
convert_dt(cell[f_ctime])))
return tr_tree
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。