|
28 | 28 | import shlex |
29 | 29 | import shutil |
30 | 30 | import socket |
| 31 | +import socketserver |
31 | 32 | import stat |
32 | 33 | import struct |
33 | 34 | import subprocess |
34 | 35 | import sys |
35 | 36 | import tempfile |
36 | 37 | import threading |
37 | 38 | import time |
| 39 | +from http.server import HTTPServer, SimpleHTTPRequestHandler |
38 | 40 | from operator import itemgetter |
| 41 | +from urllib.parse import unquote, urlsplit |
39 | 42 |
|
40 | | -if sys.version_info.major == 2: |
41 | | - from urllib import unquote |
42 | | - |
43 | | - import SocketServer as socketserver |
44 | | - from BaseHTTPServer import HTTPServer |
45 | | - from SimpleHTTPServer import SimpleHTTPRequestHandler |
46 | | - from urlparse import urlsplit |
47 | | -else: |
48 | | - import socketserver |
49 | | - from http.server import HTTPServer, SimpleHTTPRequestHandler |
50 | | - from urllib.parse import unquote, urlsplit |
| 43 | +# We depend on python 3.8 features |
| 44 | +if sys.version_info < (3, 8): # noqa: UP036 |
| 45 | + print(f'error: emrun requires python 3.8 or above ({sys.executable} {sys.version})', file=sys.stderr) |
| 46 | + sys.exit(1) |
51 | 47 |
|
52 | 48 | # Populated from cmdline params |
53 | 49 | emrun_options = None |
|
87 | 83 | # launcher.exe that runs the actual opera browser. So killing browser_process |
88 | 84 | # would just kill launcher.exe and not the opera |
89 | 85 | # browser itself. |
90 | | -processname_killed_atexit = "" |
| 86 | +processname_killed_atexit = '' |
91 | 87 |
|
92 | 88 | # Using "0.0.0.0" means "all interfaces", which should allow connecting to this |
93 | 89 | # server via LAN addresses. Using "localhost" should allow only connecting from |
|
121 | 117 |
|
122 | 118 | # Returns wallclock time in seconds. |
123 | 119 | def tick(): |
124 | | - # Would like to return time.clock() since it's apparently better for |
125 | | - # precision, but it is broken on macOS 10.10 and Python 2.7.8. |
126 | 120 | return time.time() |
127 | 121 |
|
128 | 122 |
|
@@ -680,7 +674,7 @@ def do_POST(self): # # noqa: DC04 |
680 | 674 | global page_exit_code, have_received_messages |
681 | 675 |
|
682 | 676 | (_, _, path, query, _) = urlsplit(self.path) |
683 | | - logv('POST: "' + self.path + '" (path: "' + path + '", query: "' + query + '")') |
| 677 | + logv(f'POST: "{self.path}" (path: "{path}", query: "{query}")') |
684 | 678 | if query.startswith('file='): |
685 | 679 | # Binary file dump/upload handling. Requests to |
686 | 680 | # "stdio.html?file=filename" will write binary data to the given file. |
@@ -758,12 +752,8 @@ def do_POST(self): # # noqa: DC04 |
758 | 752 |
|
759 | 753 |
|
760 | 754 | # Returns stdout by running command with universal_newlines=True |
761 | | -def check_output(cmd, universal_newlines=True, *args, **kwargs): |
762 | | - if hasattr(subprocess, "run"): |
763 | | - return subprocess.run(cmd, universal_newlines=universal_newlines, stdout=subprocess.PIPE, check=True, *args, **kwargs).stdout |
764 | | - else: |
765 | | - # check_output is considered as an old API so prefer subprocess.run if possible |
766 | | - return subprocess.check_output(cmd, universal_newlines=universal_newlines, *args, **kwargs) |
| 755 | +def check_output(cmd, *args, **kwargs): |
| 756 | + return subprocess.run(cmd, text=True, stdout=subprocess.PIPE, check=True, *args, **kwargs).stdout |
767 | 757 |
|
768 | 758 |
|
769 | 759 | # From http://stackoverflow.com/questions/4842448/getting-processor-information-in-python |
@@ -862,7 +852,7 @@ def find_gpu_model(model): |
862 | 852 |
|
863 | 853 | try: |
864 | 854 | driverDate = winreg.QueryValueEx(hVideoCardReg, 'DriverDate')[0] |
865 | | - VideoCardDescription += ' (' + driverDate + ')' |
| 855 | + VideoCardDescription += f' ({driverDate})' |
866 | 856 | except WindowsError: |
867 | 857 | pass |
868 | 858 |
|
@@ -1896,9 +1886,9 @@ def run(cmd): |
1896 | 1886 |
|
1897 | 1887 | def main(args): |
1898 | 1888 | returncode = run(args) |
1899 | | - logv('emrun quitting with process exit code ' + str(returncode)) |
| 1889 | + logv(f'emrun quitting with process exit code {returncode}') |
1900 | 1890 | if temp_firefox_profile_dir is not None: |
1901 | | - logi('Warning: Had to leave behind a temporary Firefox profile directory ' + temp_firefox_profile_dir + ' because --safe-firefox-profile was set and the browser did not quit before emrun did.') |
| 1891 | + logi(f'Warning: Had to leave behind a temporary Firefox profile directory {temp_firefox_profile_dir} because --safe-firefox-profile was set and the browser did not quit before emrun did.') |
1902 | 1892 | return returncode |
1903 | 1893 |
|
1904 | 1894 |
|
|
0 commit comments