diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/modules/subprocess/test/xpcshell/data_test_script.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/modules/subprocess/test/xpcshell/data_test_script.py')
-rw-r--r-- | toolkit/modules/subprocess/test/xpcshell/data_test_script.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/toolkit/modules/subprocess/test/xpcshell/data_test_script.py b/toolkit/modules/subprocess/test/xpcshell/data_test_script.py new file mode 100644 index 0000000000..e1f5f5de93 --- /dev/null +++ b/toolkit/modules/subprocess/test/xpcshell/data_test_script.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import os +import signal +import struct +import sys + + +def output(line, stream=sys.stdout, print_only=False): + if isinstance(line, str): + line = line.encode("utf-8", "surrogateescape") + if not print_only: + stream.buffer.write(struct.pack("@I", len(line))) + stream.buffer.write(line) + stream.flush() + + +def echo_loop(): + while True: + line = sys.stdin.buffer.readline() + if not line: + break + + output(line) + + +if sys.platform == "win32": + import msvcrt + + msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) + + +cmd = sys.argv[1] +if cmd == "echo": + echo_loop() +elif cmd == "exit": + sys.exit(int(sys.argv[2])) +elif cmd == "env": + for var in sys.argv[2:]: + output(os.environ.get(var, "!")) +elif cmd == "pwd": + output(os.path.abspath(os.curdir)) +elif cmd == "print_args": + for arg in sys.argv[2:]: + output(arg) +elif cmd == "ignore_sigterm": + signal.signal(signal.SIGTERM, signal.SIG_IGN) + + output("Ready") + while True: + try: + signal.pause() + except AttributeError: + import time + + time.sleep(3600) +elif cmd == "print": + output(sys.argv[2], stream=sys.stdout, print_only=True) + output(sys.argv[3], stream=sys.stderr, print_only=True) |