我们从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, msg, *args, **kwargs): self._log(ADDITION, BEERS_EMOJI + ' ' + Fore.LIGHTWHITE_EX + msg + Fore.RESET, args, **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, Style.RESET_ALL, rb, new_text) elif print_type == 'alert': return '{0}{1}!{2}{3} {4}'.format(lb, Fore.LIGHTRED_EX, Style.RESET_ALL, rb, new_text) elif print_type == 'sleep': return '{0}-{1} {2}'.format(lb, rb, 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","to":"now","label":"Last day"},{"from":"now-7d","to":"now","label":"Last week"},{"from":"now-30d","to":"now","label":"Last 30 days"},{"from":"now-90d","to":"now","label":"Last 90 days"}]},{"name":"status","min_doc_count":0,"size":5,"type":"terms","field":"status"},{"name":"severity","min_doc_count":0,"size":5,"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","min_doc_count":0,"size":0,"type":"terms","field":"behaviors.scenario"},{"name":"assigned_to_uid","min_doc_count":1,"size":5,"type":"terms","field":"assigned_to_uid","missing":"Unassigned"},{"name":"host","min_doc_count":1,"size":5,"type":"terms","field":"device.hostname.raw","missing":"Unknown"},{"name":"triggering_file","min_doc_count":1,"size":5,"type":"terms","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