File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ def initlog(*allargs):
7676 send an error message).
7777
7878 """
79- global logfp , log
79+ global log , logfile , logfp
8080 if logfile and not logfp :
8181 try :
8282 logfp = open (logfile , "a" )
@@ -96,6 +96,15 @@ def nolog(*allargs):
9696 """Dummy function, assigned to log when logging is disabled."""
9797 pass
9898
99+ def closelog ():
100+ """Close the log file."""
101+ global log , logfile , logfp
102+ logfile = ''
103+ if logfp :
104+ logfp .close ()
105+ logfp = None
106+ log = initlog
107+
99108log = initlog # The current logging function
100109
101110
Original file line number Diff line number Diff line change @@ -155,13 +155,7 @@ def test_log(self):
155155 cgi .logfp = None
156156 cgi .logfile = "/dev/null"
157157 cgi .initlog ("%s" , "Testing log 3" )
158- def log_cleanup ():
159- """Restore the global state of the log vars."""
160- cgi .logfile = ''
161- cgi .logfp .close ()
162- cgi .logfp = None
163- cgi .log = cgi .initlog
164- self .addCleanup (log_cleanup )
158+ self .addCleanup (cgi .closelog )
165159 cgi .log ("Testing log 4" )
166160
167161 def test_fieldstorage_readline (self ):
Original file line number Diff line number Diff line change @@ -225,6 +225,8 @@ Core and Builtins
225225Library
226226-------
227227
228+ - Add cgi.closelog() function to close the log file.
229+
228230- Issue #12502: asyncore: fix polling loop with AF_UNIX sockets.
229231
230232- Issue #4376: ctypes now supports nested structures in a endian different than
You can’t perform that action at this time.
0 commit comments