<commit_before># coding: utf-8
#########################################
# __init__.py
#
# Author zrong(zengrong.net)
# Creation 2014-09-23
# Last Editing 2015-06-14
#########################################
"""zrong 编写的基于 python 3.4 的通用功能封装。

.. moduleauthor:: zrong(zengrong.net)

"""

import logging

__version__ = "0.4.6"
__all__ = ['base', 'git', 'lua', 'ftp', 'gettext', 'conf']

slog = logging.getLogger("system")
"""默认的系统 log。"""

__LOG_FMT = logging.Formatter("%(asctime)s %(levelname)-8s %(message)s\n")


# 可改为使用：https://github.com/limodou/uliweb/blob/master/uliweb/utils/coloredlog.py
# 和 https://github.com/tartley/colorama
class ConsoleColor():
	RESET = "\033[0m"
	BOLD = "\033[1m"
	UNDERLINE = "\033[4m"
	BLINK = "\033[5m"
	REVERSE = "\033[7m"
	FADE = "\033[8m"

	BLACK = "\033[30m"
	RED = "\033[31m"
	GREEN = "\033[32m"
	YELLOW = "\033[33m"
	BLUE = "\033[34m"
	MAGENTA = "\033[35m"
	CYAN = "\033[36m"
	WHITE = "\033[37m"

	BG_BLACK = "\033[40m"
	BG_RED = "\033[41m"
	BG_GREEN = "\033[42m"
	BG_YELLOW = "\033[43m"
	BG_BLUE = "\033[44m"
	BG_MAGENTA = "\033[45m"
	BG_CYAN = "\033[46m"
	BG_WHITE = "\033[47m"

        # 黑底彩色
	# B2_BLACK = "\033[90m"
	# B2_RED = "\033[91m"
	# B2_GREEN = "\033[92m"
	# B2_YELLOW = "\033[93m"
	# B2_BLUE = "\033[94m"
	# B2_MAGENTA = "\033[95m"
	# B2_CYAN = "\033[96m"
	# B2_WHITE = "\033[97m"


class ColoredStreamHandler(logging.StreamHandler):
    def format(self, record):
        msg = super(ColoredStreamHandler, self).format(record)
        if record.levelno >= logging.ERROR:
            msg = ConsoleColor.RED+msg+ConsoleColor.RESET
        elif record.levelno == logging.WARNING:
            msg = ConsoleColor.YELLOW+msg+ConsoleColor.RESET
        return msg

def add_log_handler(log, handler=None, debug=None, fmt=None):
    """为一个 :class:`logging.Logger` 的实例增加 handler。

    :param Logger log: 需要处理的 :class:`logging.Logger` 的实例。
    :param Handler handler: 一个 :class:`logging.Handler` 的实例。
    :param int debug: Debug 级别。
    :param str fmt: Handler 的 Formatter。

    """
    if debug:
        log.setLevel(debug)
    if handler:
        # if not fmt:
        #     fmt = __LOG_FMT
        if fmt:
            handler.setFormatter(fmt)
        log.addHandler(handler)<commit_msg>fix color console in win32<commit_after># coding: utf-8
#########################################
# __init__.py
#
# Author zrong(zengrong.net)
# Creation 2014-09-23
# Last Editing 2015-06-14
#########################################
"""zrong 编写的基于 python 3.4 的通用功能封装。

.. moduleauthor:: zrong(zengrong.net)

"""

import logging
import sys

__version__ = "0.4.7"
__all__ = ['base', 'git', 'lua', 'ftp', 'gettext', 'conf']

slog = logging.getLogger("system")
"""默认的系统 log。"""

__LOG_FMT = logging.Formatter("%(asctime)s %(levelname)-8s %(message)s\n")


# 可改为使用：https://github.com/limodou/uliweb/blob/master/uliweb/utils/coloredlog.py
# 和 https://github.com/tartley/colorama
class ConsoleColor():
	RESET = "\033[0m"
	BOLD = "\033[1m"
	UNDERLINE = "\033[4m"
	BLINK = "\033[5m"
	REVERSE = "\033[7m"
	FADE = "\033[8m"

	BLACK = "\033[30m"
	RED = "\033[31m"
	GREEN = "\033[32m"
	YELLOW = "\033[33m"
	BLUE = "\033[34m"
	MAGENTA = "\033[35m"
	CYAN = "\033[36m"
	WHITE = "\033[37m"

	BG_BLACK = "\033[40m"
	BG_RED = "\033[41m"
	BG_GREEN = "\033[42m"
	BG_YELLOW = "\033[43m"
	BG_BLUE = "\033[44m"
	BG_MAGENTA = "\033[45m"
	BG_CYAN = "\033[46m"
	BG_WHITE = "\033[47m"

        # 黑底彩色
	# B2_BLACK = "\033[90m"
	# B2_RED = "\033[91m"
	# B2_GREEN = "\033[92m"
	# B2_YELLOW = "\033[93m"
	# B2_BLUE = "\033[94m"
	# B2_MAGENTA = "\033[95m"
	# B2_CYAN = "\033[96m"
	# B2_WHITE = "\033[97m"


class ColoredStreamHandler(logging.StreamHandler):
    def format(self, record):
        msg = super(ColoredStreamHandler, self).format(record)
        if sys.platform == 'win32':
            return msg
        if record.levelno >= logging.ERROR:
            msg = ConsoleColor.RED+msg+ConsoleColor.RESET
        elif record.levelno == logging.WARNING:
            msg = ConsoleColor.YELLOW+msg+ConsoleColor.RESET
        return msg

def add_log_handler(log, handler=None, debug=None, fmt=None):
    """为一个 :class:`logging.Logger` 的实例增加 handler。

    :param Logger log: 需要处理的 :class:`logging.Logger` 的实例。
    :param Handler handler: 一个 :class:`logging.Handler` 的实例。
    :param int debug: Debug 级别。
    :param str fmt: Handler 的 Formatter。

    """
    if debug:
        log.setLevel(debug)
    if handler:
        # if not fmt:
        #     fmt = __LOG_FMT
        if fmt:
            handler.setFormatter(fmt)
        log.addHandler(handler)
{'fraction_non_alphanumeric': 0.1981981981981982, 'fraction_numerical': 0.07778510217534608, 'mean_word_length': 3.3024574669187143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5068653', 'n_tokens_mistral': 2088, 'n_tokens_neox': 1880, 'n_words': 348}