From 064f6e1f12db07671c266738d853c7251e63aa27 Mon Sep 17 00:00:00 2001 From: Mikkel Juul Date: Fri, 20 Nov 2020 10:37:47 +0100 Subject: [PATCH] use a proxy method, so the user does not have to override the original behaviour --- Lib/http/server.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Lib/http/server.py b/Lib/http/server.py index 31c60d7996e..703492a4f8a 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -855,7 +855,10 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def directory_body(self, list_of_files, displaypath, actual_path, enc) -> str: """ - Compose and encode the list_of_files into HTML + Compose the list_of_files into body content + + This method is a proxy method, to enable using the original + method when overriding the behaviour of the Handler displaypath is a relative path str actual_path is the full actual filesystem path @@ -879,21 +882,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): print("Serving at port", PORT) httpd.serve_forever() """ - r = [] - title = 'Directory listing for %s' % displaypath - r.append('') - r.append('\n') - r.append('' % enc) - r.append('%s\n' % title) - r.append('\n

%s

' % title) - r.append('
\n\n
\n\n\n') - return '\n'.join(r) + return self.directory_body_html(list_of_files, displaypath, actual_path, enc) def send_directory_headers(self, enc, content_length): """ @@ -944,6 +933,23 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): errors='surrogatepass'), html.escape(displayname, quote=False)) + def directory_body_html(self, list_of_files, displaypath, actual_path, enc): + r = [] + title = 'Directory listing for %s' % displaypath + r.append('') + r.append('\n') + r.append('' % enc) + r.append('%s\n' % title) + r.append('\n

%s

' % title) + r.append('
\n\n
\n\n\n') + return '\n'.join(r) + # Utilities for CGIHTTPRequestHandler