88# suppress these upgrade warnings:
99# ruff: noqa: UP015, UP024, UP021, UP025
1010
11- """emrun: Implements machinery that allows running a .html page as if it was a
12- standard executable file.
11+ """emrun: Tool for running an .html page as if it was a standard executable file.
1312
1413Usage: emrun <options> filename.html <args to program>
1514
@@ -136,8 +135,7 @@ def tick():
136135
137136
138137def logi (msg ):
139- """Prints a log message to 'info' stdout channel. Always printed.
140- """
138+ """Prints a log message to 'info' stdout channel. Always printed."""
141139 global last_message_time
142140 with http_mutex :
143141 sys .stdout .write (msg + '\n ' )
@@ -147,6 +145,7 @@ def logi(msg):
147145
148146def logv (msg ):
149147 """Prints a verbose log message to stdout channel.
148+
150149 Only shown if run with --verbose.
151150 """
152151 global last_message_time
@@ -158,8 +157,7 @@ def logv(msg):
158157
159158
160159def loge (msg ):
161- """Prints an error message to stderr channel.
162- """
160+ """Prints an error message to stderr channel."""
163161 global last_message_time
164162 with http_mutex :
165163 sys .stderr .write (msg + '\n ' )
@@ -174,8 +172,7 @@ def format_eol(msg):
174172
175173
176174def browser_logi (msg ):
177- """Prints a message to the browser stdout output stream.
178- """
175+ """Prints a message to the browser stdout output stream."""
179176 global last_message_time
180177 msg = format_eol (msg )
181178 browser_stdout_handle .write (msg + '\n ' )
@@ -184,8 +181,7 @@ def browser_logi(msg):
184181
185182
186183def browser_loge (msg ):
187- """Prints a message to the browser stderr output stream.
188- """
184+ """Prints a message to the browser stderr output stream."""
189185 global last_message_time
190186 msg = format_eol (msg )
191187 browser_stderr_handle .write (msg + '\n ' )
@@ -195,7 +191,8 @@ def browser_loge(msg):
195191
196192def unquote_u (source ):
197193 """Unquotes a unicode string.
198- (translates ascii-encoded utf string back to utf)
194+
195+ Translates ascii-encoded utf string back to utf.
199196 """
200197 result = unquote (source )
201198 if '%u' in result :
@@ -207,7 +204,7 @@ def unquote_u(source):
207204
208205
209206def delete_emrun_safe_firefox_profile ():
210- """Deletes the temporary created Firefox profile (if one exists)"""
207+ """Delete the temporary created Firefox profile (if one exists). """
211208 global temp_firefox_profile_dir
212209 if temp_firefox_profile_dir is not None :
213210 logv ('remove_tree("' + temp_firefox_profile_dir + '")' )
@@ -329,6 +326,7 @@ def create_emrun_safe_firefox_profile():
329326
330327def is_browser_process_alive ():
331328 """Returns whether the browser page we spawned is still running.
329+
332330 (note, not perfect atm, in case we are running in detached mode)
333331 """
334332 # If navigation to the web page has not yet occurred, we behave as if the
@@ -358,8 +356,9 @@ def is_browser_process_alive():
358356
359357
360358def kill_browser_process ():
361- """Kills browser_process and processname_killed_atexit. Also removes the
362- temporary Firefox profile that was created, if one exists.
359+ """Kills browser_process and processname_killed_atexit.
360+
361+ Also removes the temporary Firefox profile that was created, if one exists.
363362 """
364363 global browser_process , processname_killed_atexit , current_browser_processes
365364 if browser_process and browser_process .poll () is None :
@@ -443,14 +442,18 @@ def pid_existed(pid):
443442 logv ('Was unable to detect the browser process that was spawned by emrun. This may occur if the target page was opened in a tab on a browser process that already existed before emrun started up.' )
444443
445444
446- # Our custom HTTP web server that will serve the target page to run via .html.
447- # This is used so that we can load the page via a http:// URL instead of a
448- # file:// URL, since those wouldn't work too well unless user allowed XHR
449- # without CORS rules. Also, the target page will route its stdout and stderr
450- # back to here via HTTP requests.
451445class HTTPWebServer (socketserver .ThreadingMixIn , HTTPServer ):
452- """Log messaging arriving via HTTP can come in out of sequence. Implement a
453- sequencing mechanism to enforce ordered transmission."""
446+ """HTTP Server used to serve the target page to run via .html.
447+
448+ This is used so that we can load the page via a http:// URL instead of a
449+ file:// URL, since those wouldn't work too well unless user allowed XHR
450+ without CORS rules. Also, the target page will route its stdout and stderr
451+ back to here via HTTP requests.
452+
453+ Log messaging arriving via HTTP can come in out of sequence. Implement a
454+ sequencing mechanism to enforce ordered transmission.
455+ """
456+
454457 expected_http_seq_num = 1
455458 # Stores messages that have arrived out of order, pending for a send as soon
456459 # as the missing message arrives. Kept in sorted order, first element is the
0 commit comments