本文整理匯總了Python中django.utils.termcolors.colorize方法的典型用法代碼示例。如果您正苦於以下問題:Python termcolors.colorize方法的具體用法?Python termcolors.colorize怎麽用?Python termcolors.colorize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.termcolors
的用法示例。
在下文中一共展示了termcolors.colorize方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compile
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def compile(self):
lines = []
def write(text, **kwargs):
lines.append(colorize(text=text, **kwargs))
if self._reports:
write('{space}Reports{space}'.format(space=' '*32), bg='blue',
fg='white')
for level, reports in self._reports.items():
if reports:
write(self.LEVEL_LABEL[level].title())
for msg, data in reports.items():
write('- {} ({})'.format(msg, len(data)))
if self.verbosity >= level:
for item in data:
fg = 'red' if level == self.ERROR else 'white'
write(' . {}'.format(item), fg=fg)
return lines
示例2: get_raw_data
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def get_raw_data(self, datum):
"""Returns the raw data for this column, before any filters or
formatting are applied to it. This is useful when doing calculations
on data in the table.
"""
# Callable transformations
if callable(self.transform):
data = self.transform(datum)
# Dict lookups
elif isinstance(datum, collections.Mapping) and \
self.transform in datum:
data = datum.get(self.transform)
else:
# Basic object lookups
try:
data = getattr(datum, self.transform)
except AttributeError:
msg = _("The attribute %(attr)s doesn't exist on "
"%(obj)s.") % {'attr': self.transform, 'obj': datum}
msg = termcolors.colorize(msg, **PALETTE['ERROR'])
LOG.warning(msg)
data = None
return data
示例3: log
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def log(s):
sys.stdout.write(colorize(s, fg='cyan') + '\n')
# The normal scenario is that we use the hostname, but let's make it
# overridable, this is useful for dev and debugging.
示例4: log
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def log(text, **kwargs):
sys.stdout.write(colorize(str(text), **kwargs) + '\n')
示例5: debug
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def debug(key, value):
from django.utils.termcolors import colorize
if value:
sys.stdout.write(colorize(key, fg='green'))
sys.stdout.write(": ")
sys.stdout.write(colorize(repr(value), fg='white'))
sys.stdout.write("\n")
示例6: _log
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def _log(self, level, msg, colour, logging_context):
args = logging_context['args']
kwargs = logging_context['kwargs']
for line in re.split(r'\r?\n', str(msg)):
line = colorize(line, fg=colour)
request_logger.log(level, line, *args, **kwargs)
示例7: __init__
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def __init__(self, get_response=None):
self.get_response = get_response
self.log_level = getattr(settings, SETTING_NAMES['log_level'], DEFAULT_LOG_LEVEL)
self.http_4xx_log_level = getattr(settings, SETTING_NAMES['http_4xx_log_level'], DEFAULT_HTTP_4XX_LOG_LEVEL)
self.sensitive_headers = getattr(settings, SETTING_NAMES['sensitive_headers'], DEFAULT_SENSITIVE_HEADERS)
if not isinstance(self.sensitive_headers, list):
raise ValueError(
"{} should be list. {} is not list.".format(SETTING_NAMES['sensitive_headers'], self.sensitive_headers)
)
for log_attr in ('log_level', 'http_4xx_log_level'):
level = getattr(self, log_attr)
if level not in [logging.NOTSET, logging.DEBUG, logging.INFO,
logging.WARNING, logging.ERROR, logging.CRITICAL]:
raise ValueError("Unknown log level({}) in setting({})".format(level, SETTING_NAMES[log_attr]))
# TODO: remove deprecated legacy settings
enable_colorize = getattr(settings, SETTING_NAMES['legacy_colorize'], None)
if enable_colorize is None:
enable_colorize = getattr(settings, SETTING_NAMES['colorize'], DEFAULT_COLORIZE)
if not isinstance(enable_colorize, bool):
raise ValueError(
"{} should be boolean. {} is not boolean.".format(SETTING_NAMES['colorize'], enable_colorize)
)
self.max_body_length = getattr(settings, SETTING_NAMES['max_body_length'], DEFAULT_MAX_BODY_LENGTH)
if not isinstance(self.max_body_length, int):
raise ValueError(
"{} should be int. {} is not int.".format(SETTING_NAMES['max_body_length'], self.max_body_length)
)
self.logger = ColourLogger("cyan", "magenta") if enable_colorize else Logger()
self.boundary = ''
示例8: header
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def header(self, string):
self.stdout.write(colorize(string, fg="cyan", opts=("bold",)))
開發者ID:california-civic-data-coalition,項目名稱:django-calaccess-campaign-browser,代碼行數:4,代碼來源:__init__.py
示例9: log
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def log(self, string):
self.stdout.write(colorize("%s" % string, fg="white"))
開發者ID:california-civic-data-coalition,項目名稱:django-calaccess-campaign-browser,代碼行數:4,代碼來源:__init__.py
示例10: success
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def success(self, string):
self.stdout.write(colorize(string, fg="green"))
開發者ID:california-civic-data-coalition,項目名稱:django-calaccess-campaign-browser,代碼行數:4,代碼來源:__init__.py
示例11: failure
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def failure(self, string):
self.stdout.write(colorize(string, fg="red"))
開發者ID:california-civic-data-coalition,項目名稱:django-calaccess-campaign-browser,代碼行數:4,代碼來源:__init__.py
示例12: warn
# 需要導入模塊: from django.utils import termcolors [as 別名]
# 或者: from django.utils.termcolors import colorize [as 別名]
def warn(self, string):
self.stdout.write(colorize(string, fg="yellow"))
開發者ID:california-civic-data-coalition,項目名稱:django-calaccess-campaign-browser,代碼行數:4,代碼來源:__init__.py