ยปCore Development>Code coverage>Lib/curses/ascii.py

Python code coverage for Lib/curses/ascii.py

#countcontent
1n/a"""Constants and membership tests for ASCII characters"""
2n/a
3n/aNUL = 0x00 # ^@
4n/aSOH = 0x01 # ^A
5n/aSTX = 0x02 # ^B
6n/aETX = 0x03 # ^C
7n/aEOT = 0x04 # ^D
8n/aENQ = 0x05 # ^E
9n/aACK = 0x06 # ^F
10n/aBEL = 0x07 # ^G
11n/aBS = 0x08 # ^H
12n/aTAB = 0x09 # ^I
13n/aHT = 0x09 # ^I
14n/aLF = 0x0a # ^J
15n/aNL = 0x0a # ^J
16n/aVT = 0x0b # ^K
17n/aFF = 0x0c # ^L
18n/aCR = 0x0d # ^M
19n/aSO = 0x0e # ^N
20n/aSI = 0x0f # ^O
21n/aDLE = 0x10 # ^P
22n/aDC1 = 0x11 # ^Q
23n/aDC2 = 0x12 # ^R
24n/aDC3 = 0x13 # ^S
25n/aDC4 = 0x14 # ^T
26n/aNAK = 0x15 # ^U
27n/aSYN = 0x16 # ^V
28n/aETB = 0x17 # ^W
29n/aCAN = 0x18 # ^X
30n/aEM = 0x19 # ^Y
31n/aSUB = 0x1a # ^Z
32n/aESC = 0x1b # ^[
33n/aFS = 0x1c # ^\
34n/aGS = 0x1d # ^]
35n/aRS = 0x1e # ^^
36n/aUS = 0x1f # ^_
37n/aSP = 0x20 # space
38n/aDEL = 0x7f # delete
39n/a
40n/acontrolnames = [
41n/a"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
42n/a"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
43n/a"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
44n/a"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US",
45n/a"SP"
46n/a]
47n/a
48n/adef _ctoi(c):
49n/a if type(c) == type(""):
50n/a return ord(c)
51n/a else:
52n/a return c
53n/a
54n/adef isalnum(c): return isalpha(c) or isdigit(c)
55n/adef isalpha(c): return isupper(c) or islower(c)
56n/adef isascii(c): return 0 <= _ctoi(c) <= 127 # ?
57n/adef isblank(c): return _ctoi(c) in (9, 32)
58n/adef iscntrl(c): return 0 <= _ctoi(c) <= 31 or _ctoi(c) == 127
59n/adef isdigit(c): return 48 <= _ctoi(c) <= 57
60n/adef isgraph(c): return 33 <= _ctoi(c) <= 126
61n/adef islower(c): return 97 <= _ctoi(c) <= 122
62n/adef isprint(c): return 32 <= _ctoi(c) <= 126
63n/adef ispunct(c): return isgraph(c) and not isalnum(c)
64n/adef isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)
65n/adef isupper(c): return 65 <= _ctoi(c) <= 90
66n/adef isxdigit(c): return isdigit(c) or \
67n/a (65 <= _ctoi(c) <= 70) or (97 <= _ctoi(c) <= 102)
68n/adef isctrl(c): return 0 <= _ctoi(c) < 32
69n/adef ismeta(c): return _ctoi(c) > 127
70n/a
71n/adef ascii(c):
72n/a if type(c) == type(""):
73n/a return chr(_ctoi(c) & 0x7f)
74n/a else:
75n/a return _ctoi(c) & 0x7f
76n/a
77n/adef ctrl(c):
78n/a if type(c) == type(""):
79n/a return chr(_ctoi(c) & 0x1f)
80n/a else:
81n/a return _ctoi(c) & 0x1f
82n/a
83n/adef alt(c):
84n/a if type(c) == type(""):
85n/a return chr(_ctoi(c) | 0x80)
86n/a else:
87n/a return _ctoi(c) | 0x80
88n/a
89n/adef unctrl(c):
90n/a bits = _ctoi(c)
91n/a if bits == 0x7f:
92n/a rep = "^?"
93n/a elif isprint(bits & 0x7f):
94n/a rep = chr(bits & 0x7f)
95n/a else:
96n/a rep = "^" + chr(((bits & 0x7f) | 0x20) + 0x20)
97n/a if bits & 0x80:
98n/a return "!" + rep
99n/a return rep