4
4
# --- BEGIN_HEADER ---
5
5
#
6
6
# safeeval - Safe evaluation of expressions and commands
7
- # Copyright (C) 2003-2023 The MiG Project lead by Brian Vinter
7
+ # Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
8
8
#
9
9
# This file is part of MiG.
10
10
#
@@ -290,7 +290,7 @@ def math_expr_eval(expr):
290
290
291
291
292
292
def subprocess_check_output (command , stdin = None , stdout = None , stderr = None ,
293
- env = None , cwd = None ,
293
+ env = None , text = None , cwd = None ,
294
294
only_sanitized_variables = False ):
295
295
"""Safe execution of command with output returned as byte string.
296
296
The optional only_sanitized_variables option is used to override the
@@ -299,25 +299,31 @@ def subprocess_check_output(command, stdin=None, stdout=None, stderr=None,
299
299
command comes from user-provided variables or file names that may contain
300
300
control characters.
301
301
"""
302
- return subprocess .check_output (command , stdin = stdin , env = env , cwd = cwd ,
302
+ # NOTE: python3.7 added text arg previously known as universal_newlines
303
+ # TODO: rename universal_newlines to text once we drop python3.6 support
304
+ return subprocess .check_output (command , stdin = stdin , env = env ,
305
+ universal_newlines = text , cwd = cwd ,
303
306
shell = only_sanitized_variables )
304
307
305
308
306
309
def subprocess_call (command , stdin = None , stdout = None , stderr = None , env = None ,
307
- cwd = None , only_sanitized_variables = False ):
310
+ text = None , cwd = None , only_sanitized_variables = False ):
308
311
"""Safe execution of command.
309
312
The optional only_sanitized_variables option is used to override the
310
313
default execution without shell interpretation of control characters.
311
314
Please be really careful when using it especially if any parts of your
312
315
command comes from user-provided variables or file names that may contain
313
316
control characters.
314
317
"""
318
+ # NOTE: python3.7 added text arg previously known as universal_newlines
319
+ # TODO: rename universal_newlines to text once we drop python3.6 support
315
320
return subprocess .call (command , stdin = stdin , stdout = stdout , stderr = stderr ,
316
- env = env , cwd = cwd , shell = only_sanitized_variables )
321
+ env = env , universal_newlines = text , cwd = cwd ,
322
+ shell = only_sanitized_variables )
317
323
318
324
319
325
def subprocess_popen (command , stdin = None , stdout = None , stderr = None , env = None ,
320
- cwd = None , only_sanitized_variables = False ):
326
+ text = None , cwd = None , only_sanitized_variables = False ):
321
327
"""Safe execution of command with full process control.
322
328
The optional only_sanitized_variables option is used to override the
323
329
default execution without shell interpretation of control characters.
@@ -326,8 +332,11 @@ def subprocess_popen(command, stdin=None, stdout=None, stderr=None, env=None,
326
332
control characters.
327
333
Returns a subprocess Popen object with wait method, returncode and so on.
328
334
"""
335
+ # NOTE: python3.7 added text arg previously known as universal_newlines
336
+ # TODO: rename universal_newlines to text once we drop python3.6 support
329
337
return subprocess .Popen (command , stdin = stdin , stdout = stdout , stderr = stderr ,
330
- env = env , cwd = cwd , shell = only_sanitized_variables )
338
+ env = env , universal_newlines = text , cwd = cwd ,
339
+ shell = only_sanitized_variables )
331
340
332
341
333
342
def subprocess_list2cmdline (command ):
0 commit comments