Fix tempfile.NamedTemporaryFile usage under Python 3
authorMichael Prokop <mika@grml.org>
Tue, 7 Jul 2020 13:40:21 +0000 (15:40 +0200)
committerMichael Prokop <mika@grml.org>
Tue, 7 Jul 2020 13:45:59 +0000 (15:45 +0200)
The mode parameter of tempfile.NamedTemporaryFile defaults to 'w+b',
see https://docs.python.org/3/library/tempfile.html

Fixes:

| TypeError: a bytes-like object is required, not 'str'

Closes: grml/grml#152

grml-x

diff --git a/grml-x b/grml-x
index b180e4d..7323991 100755 (executable)
--- a/grml-x
+++ b/grml-x
@@ -204,7 +204,7 @@ def main():
     # write new config
     if monitor or device or len(screen.data) > 0 or screen.subsect != '':
         try:
-            f = tempfile.NamedTemporaryFile(delete=False)
+            f = tempfile.NamedTemporaryFile(mode='w+', delete=False)
             f.write(XORG_CONF_HEADER + "\n")
             f.write("# DO NOT MODIFY, YOUR CHANGES WILL BE LOST - OR REMOVE ALL HEADER LINES\n")
             f.write("# See man xorg.conf or /etc/X11/xorg.conf.example for more\n")