File: file_stdio2.py

package info (click to toggle)
micropython 1.26.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,196 kB
  • sloc: ansic: 324,551; python: 63,215; xml: 4,241; makefile: 3,618; sh: 1,586; javascript: 754; asm: 723; cpp: 83; exp: 11; pascal: 6
file content (65 lines) | stat: -rw-r--r-- 2,123 bytes parent folder | download | duplicates (2)
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
# Test sys.std*.buffer objects.

import sys

try:
    sys.stdout.buffer
    sys.stdin.buffer
    sys.stderr.buffer
except AttributeError:
    print("SKIP")
    raise SystemExit


# force cpython to flush after every print
# this is to sequence stdout and stderr
def print_flush(*args, **kwargs):
    try:
        print(*args, **kwargs, flush=True)
    except TypeError:
        print(*args, **kwargs)


print_flush("==stdin==")
print_flush(sys.stdin.buffer.fileno())


print_flush("==stdout==")
print_flush(sys.stdout.buffer.fileno())
n_text = sys.stdout.write("The quick brown fox jumps over the lazy dog\n")
sys.stdout.flush()
n_binary = sys.stdout.buffer.write("The quick brown fox jumps over the lazy dog\n".encode("utf-8"))
sys.stdout.buffer.flush()
print_flush("n_text:{} n_binary:{}".format(n_text, n_binary))

# temporarily disabling unicode tests until future PR which fixes unicode write character count
# n_text = sys.stdout.write("🚀")
# sys.stdout.flush()
# n_binary = sys.stdout.buffer.write("🚀".encode("utf-8"))
# sys.stdout.buffer.flush()
# print_flush("")
# print_flush("n_text:{} n_binary:{}".format(n_text, n_binary))
# n_text = sys.stdout.write("1🚀2a3α4b5β6c7γ8d9δ0ぁ1🙐")
# sys.stdout.flush()
# n_binary = sys.stdout.buffer.write("1🚀2a3α4b5β6c7γ8d9δ0ぁ1🙐".encode("utf-8"))
# sys.stdout.buffer.flush()
# print_flush("")
# print_flush("n_text:{} n_binary:{}".format(n_text, n_binary))


print_flush("==stderr==")
print_flush(sys.stderr.buffer.fileno())
n_text = sys.stderr.write("The quick brown fox jumps over the lazy dog\n")
sys.stderr.flush()
n_binary = sys.stderr.buffer.write("The quick brown fox jumps over the lazy dog\n".encode("utf-8"))
sys.stderr.buffer.flush()
print_flush("n_text:{} n_binary:{}".format(n_text, n_binary))

# temporarily disabling unicode tests until future PR which fixes unicode write character count
# n_text = sys.stderr.write("🚀")
# sys.stderr.flush()
# n_binary = sys.stderr.buffer.write("🚀".encode("utf-8"))
# sys.stderr.buffer.flush()
# print_flush("")
# print_flush("n_text:{} n_binary:{}".format(n_text, n_binary))
# print_flush("")