Skip to content

Commit 72b853d

Browse files
committed
No more gibberish log from https request to mess up the current terminal
1 parent 21359e8 commit 72b853d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

oauth2cli/authcode.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ def _escape(key_value_pairs):
102102
return {k: escape(v) for k, v in key_value_pairs.items()}
103103

104104

105+
def _printify(text):
106+
# If an https request is sent to an http server, the text needs to be repr-ed
107+
return repr(text) if isinstance(text, str) and not text.isprintable() else text
108+
109+
105110
class _AuthCodeHandler(BaseHTTPRequestHandler):
106111
def do_GET(self):
107112
# For flexibility, we choose to not check self.path matching redirect_uri
@@ -135,7 +140,8 @@ def _send_full_response(self, body, is_ok=True):
135140
self.wfile.write(body.encode("utf-8"))
136141

137142
def log_message(self, format, *args):
138-
logger.debug(format, *args) # To override the default log-to-stderr behavior
143+
# To override the default log-to-stderr behavior
144+
logger.debug(format, *map(_printify, args))
139145

140146

141147
class _AuthCodeHttpServer(HTTPServer, object):

0 commit comments

Comments
 (0)