text
stringlengths 0
828
|
---|
summary_width = self.summary_width()
|
label_width = self.label_width()
|
remaining = width - summary_width - label_width - 2
|
if remaining >= min_progress_width:
|
progress_width = remaining
|
else:
|
progress_width = min_progress_width
|
remaining = width - summary_width - progress_width - 2
|
if remaining >= min_label_width:
|
label_width = remaining
|
else:
|
label_width = min_label_width
|
return (label_width, progress_width, summary_width)"
|
427,"def format_table(self, width=None,
|
min_label_width=10, min_progress_width=10):
|
""""""Format the entire table of progress bars.
|
The function first computes the widths of the fields so they can be
|
aligned across lines and then returns formatted lines as a list of
|
strings.
|
""""""
|
# handle the special case of an empty table.
|
if len(self._lines) == 0:
|
return []
|
if width is None: # pragma: no cover
|
width = shutil.get_terminal_size()[0]
|
labelw, progw, summaryw = self.calculate_field_widths(
|
width=width,
|
min_label_width=min_label_width,
|
min_progress_width=min_progress_width
|
)
|
output = [
|
sb.format_status(
|
label_width=labelw,
|
progress_width=progw,
|
summary_width=summaryw
|
)
|
for sb in self._lines
|
]
|
return output"
|
428,"def create_log_dict(request, response):
|
""""""
|
Create a dictionary with logging data.
|
""""""
|
remote_addr = request.META.get('REMOTE_ADDR')
|
if remote_addr in getattr(settings, 'INTERNAL_IPS', []):
|
remote_addr = request.META.get(
|
'HTTP_X_FORWARDED_FOR') or remote_addr
|
user_email = ""-""
|
if hasattr(request, 'user'):
|
user_email = getattr(request.user, 'email', '-')
|
if response.streaming:
|
content_length = 'streaming'
|
else:
|
content_length = len(response.content)
|
return {
|
# 'event' makes event-based filtering possible in logging backends
|
# like logstash
|
'event': settings.LOGUTILS_LOGGING_MIDDLEWARE_EVENT,
|
'remote_address': remote_addr,
|
'user_email': user_email,
|
'method': request.method,
|
'url': request.get_full_path(),
|
'status': response.status_code,
|
'content_length': content_length,
|
'request_time': -1, # NA value: real value added by LoggingMiddleware
|
}"
|
429,"def create_log_message(log_dict, use_sql_info=False, fmt=True):
|
""""""
|
Create the logging message string.
|
""""""
|
log_msg = (
|
""%(remote_address)s %(user_email)s %(method)s %(url)s %(status)d ""
|
""%(content_length)d (%(request_time).2f seconds)""
|
)
|
if use_sql_info:
|
sql_time = sum(
|
float(q['time']) for q in connection.queries) * 1000
|
extra_log = {
|
'nr_queries': len(connection.queries),
|
'sql_time': sql_time}
|
log_msg += "" (%(nr_queries)d SQL queries, %(sql_time)f ms)""
|
log_dict.update(extra_log)
|
return log_msg % log_dict if fmt else log_msg"
|
430,"def process_response(self, request, response):
|
""""""
|
Create the logging message..
|
""""""
|
try:
|
log_dict = create_log_dict(request, response)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.