python: Normalize quotes with Black.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:20:45 -08:00
committed by Tim Abbott
parent 11741543da
commit 6e4c3e41dc
989 changed files with 32792 additions and 32792 deletions

View File

@@ -22,9 +22,9 @@ from zerver.lib.queue import queue_json_publish
def try_git_describe() -> Optional[str]:
try: # nocoverage
return subprocess.check_output(
['git', 'describe', '--tags', '--match=[0-9]*', '--always', '--dirty', '--long'],
["git", "describe", "--tags", "--match=[0-9]*", "--always", "--dirty", "--long"],
stderr=subprocess.PIPE,
cwd=os.path.join(os.path.dirname(__file__), '..'),
cwd=os.path.join(os.path.dirname(__file__), ".."),
universal_newlines=True,
).strip()
except (FileNotFoundError, subprocess.CalledProcessError): # nocoverage
@@ -32,13 +32,13 @@ def try_git_describe() -> Optional[str]:
def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None:
report['has_request'] = True
report["has_request"] = True
report['path'] = request.path
report['method'] = request.method
report['remote_addr'] = request.META.get('REMOTE_ADDR', None)
report['query_string'] = request.META.get('QUERY_STRING', None)
report['server_name'] = request.META.get('SERVER_NAME', None)
report["path"] = request.path
report["method"] = request.method
report["remote_addr"] = request.META.get("REMOTE_ADDR", None)
report["query_string"] = request.META.get("QUERY_STRING", None)
report["server_name"] = request.META.get("SERVER_NAME", None)
try:
from django.contrib.auth.models import AnonymousUser
@@ -61,30 +61,30 @@ def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None:
user_email = None
user_role = None
report['user'] = {
'user_email': user_email,
'user_full_name': user_full_name,
'user_role': user_role,
report["user"] = {
"user_email": user_email,
"user_full_name": user_full_name,
"user_role": user_role,
}
exception_filter = get_exception_reporter_filter(request)
try:
report['data'] = (
report["data"] = (
exception_filter.get_post_parameters(request)
if request.method == 'POST'
if request.method == "POST"
else request.GET
)
except Exception:
# exception_filter.get_post_parameters will throw
# RequestDataTooBig if there's a really big file uploaded
report['data'] = {}
report["data"] = {}
try:
report['host'] = SplitResult("", request.get_host(), "", "", "").hostname
report["host"] = SplitResult("", request.get_host(), "", "", "").hostname
except Exception:
# request.get_host() will throw a DisallowedHost
# exception if the host is invalid
report['host'] = platform.node()
report["host"] = platform.node()
@runtime_checkable
@@ -120,43 +120,43 @@ class AdminNotifyHandler(logging.Handler):
is_markdown_rendering_exception = True
try:
report['node'] = platform.node()
report['host'] = platform.node()
report["node"] = platform.node()
report["host"] = platform.node()
report['deployment_data'] = dict(
report["deployment_data"] = dict(
git=try_git_describe(),
ZULIP_VERSION=ZULIP_VERSION,
)
if record.exc_info:
stack_trace = ''.join(traceback.format_exception(*record.exc_info))
stack_trace = "".join(traceback.format_exception(*record.exc_info))
message = str(record.exc_info[1])
is_markdown_rendering_exception = record.msg.startswith(
'Exception in Markdown parser'
"Exception in Markdown parser"
)
else:
stack_trace = 'No stack trace available'
stack_trace = "No stack trace available"
message = record.getMessage()
if '\n' in message:
if "\n" in message:
# Some exception code paths in queue processors
# seem to result in super-long messages
stack_trace = message
message = message.split('\n')[0]
message = message.split("\n")[0]
is_markdown_rendering_exception = False
report['stack_trace'] = stack_trace
report['message'] = message
report["stack_trace"] = stack_trace
report["message"] = message
report['logger_name'] = record.name
report['log_module'] = find_log_caller_module(record)
report['log_lineno'] = record.lineno
report["logger_name"] = record.name
report["log_module"] = find_log_caller_module(record)
report["log_lineno"] = record.lineno
if isinstance(record, HasRequest):
add_request_metadata(report, record.request)
except Exception:
report['message'] = "Exception in preparing exception report!"
logging.warning(report['message'], exc_info=True)
report['stack_trace'] = "See /var/log/zulip/errors.log"
report["message"] = "Exception in preparing exception report!"
logging.warning(report["message"], exc_info=True)
report["stack_trace"] = "See /var/log/zulip/errors.log"
capture_exception()
if settings.DEBUG_ERROR_REPORTING: # nocoverage
@@ -164,10 +164,10 @@ class AdminNotifyHandler(logging.Handler):
logging.warning(
"Reporting an error to admins: %s %s %s %s %s",
record.levelname,
report['logger_name'],
report['log_module'],
report['message'],
report['stack_trace'],
report["logger_name"],
report["log_module"],
report["message"],
report["stack_trace"],
)
try:
@@ -179,7 +179,7 @@ class AdminNotifyHandler(logging.Handler):
notify_server_error(report, is_markdown_rendering_exception)
else:
queue_json_publish(
'error_reports',
"error_reports",
dict(
type="server",
report=report,