File: data_test_script.py

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (78 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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 == "print_python_executable_path":
    import psutil  # not stdlib, put already part of our virtualenv.

    # This returns the final executable that launched this script.
    # We cannot use sys.executable because on Windows that would point to the
    # python.exe parent that spawns this process.
    # See getRealPythonExecutable in test_subprocess.js.
    output(psutil.Process().exe())
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 == "close_stdin_and_wait_forever":
    # Do NOT use non-stdlib modules here; this runs outside our virtualenv,
    # via the program identified by print_python_executable_path.
    os.close(sys.stdin.fileno())
    output("stdin_closed")
    while True:
        pass  # Test should kill the program
elif cmd == "close_pipes_and_wait_for_stdin":
    os.close(sys.stdout.fileno())
    os.close(sys.stderr.fileno())
    sys.stdin.buffer.read(1)
elif cmd == "print":
    output(sys.argv[2], stream=sys.stdout, print_only=True)
    output(sys.argv[3], stream=sys.stderr, print_only=True)