Debian Codegraph @

Doc/library/curses.ascii.rst

raw
1 :mod:`!curses.ascii` --- Utilities for ASCII characters
2 =======================================================
3
4 .. module:: curses.ascii
5 :synopsis: Constants and set-membership functions for ASCII characters.
6
7 .. moduleauthor:: Eric S. Raymond <[email protected]>
8 .. sectionauthor:: Eric S. Raymond <[email protected]>
9
10 **Source code:** :source:`Lib/curses/ascii.py`
11
12 --------------
13
14 The :mod:`!curses.ascii` module supplies name constants for ASCII characters and
15 functions to test membership in various ASCII character classes. The constants
16 supplied are names for control characters as follows:
17
18 +---------------+----------------------------------------------+
19 | Name | Meaning |
20 +===============+==============================================+
21 | .. data:: NUL | |
22 +---------------+----------------------------------------------+
23 | .. data:: SOH | Start of heading, console interrupt |
24 +---------------+----------------------------------------------+
25 | .. data:: STX | Start of text |
26 +---------------+----------------------------------------------+
27 | .. data:: ETX | End of text |
28 +---------------+----------------------------------------------+
29 | .. data:: EOT | End of transmission |
30 +---------------+----------------------------------------------+
31 | .. data:: ENQ | Enquiry, goes with :const:`ACK` flow control |
32 +---------------+----------------------------------------------+
33 | .. data:: ACK | Acknowledgement |
34 +---------------+----------------------------------------------+
35 | .. data:: BEL | Bell |
36 +---------------+----------------------------------------------+
37 | .. data:: BS | Backspace |
38 +---------------+----------------------------------------------+
39 | .. data:: TAB | Tab |
40 +---------------+----------------------------------------------+
41 | .. data:: HT | Alias for :const:`TAB`: "Horizontal tab" |
42 +---------------+----------------------------------------------+
43 | .. data:: LF | Line feed |
44 +---------------+----------------------------------------------+
45 | .. data:: NL | Alias for :const:`LF`: "New line" |
46 +---------------+----------------------------------------------+
47 | .. data:: VT | Vertical tab |
48 +---------------+----------------------------------------------+
49 | .. data:: FF | Form feed |
50 +---------------+----------------------------------------------+
51 | .. data:: CR | Carriage return |
52 +---------------+----------------------------------------------+
53 | .. data:: SO | Shift-out, begin alternate character set |
54 +---------------+----------------------------------------------+
55 | .. data:: SI | Shift-in, resume default character set |
56 +---------------+----------------------------------------------+
57 | .. data:: DLE | Data-link escape |
58 +---------------+----------------------------------------------+
59 | .. data:: DC1 | XON, for flow control |
60 +---------------+----------------------------------------------+
61 | .. data:: DC2 | Device control 2, block-mode flow control |
62 +---------------+----------------------------------------------+
63 | .. data:: DC3 | XOFF, for flow control |
64 +---------------+----------------------------------------------+
65 | .. data:: DC4 | Device control 4 |
66 +---------------+----------------------------------------------+
67 | .. data:: NAK | Negative acknowledgement |
68 +---------------+----------------------------------------------+
69 | .. data:: SYN | Synchronous idle |
70 +---------------+----------------------------------------------+
71 | .. data:: ETB | End transmission block |
72 +---------------+----------------------------------------------+
73 | .. data:: CAN | Cancel |
74 +---------------+----------------------------------------------+
75 | .. data:: EM | End of medium |
76 +---------------+----------------------------------------------+
77 | .. data:: SUB | Substitute |
78 +---------------+----------------------------------------------+
79 | .. data:: ESC | Escape |
80 +---------------+----------------------------------------------+
81 | .. data:: FS | File separator |
82 +---------------+----------------------------------------------+
83 | .. data:: GS | Group separator |
84 +---------------+----------------------------------------------+
85 | .. data:: RS | Record separator, block-mode terminator |
86 +---------------+----------------------------------------------+
87 | .. data:: US | Unit separator |
88 +---------------+----------------------------------------------+
89 | .. data:: SP | Space |
90 +---------------+----------------------------------------------+
91 | .. data:: DEL | Delete |
92 +---------------+----------------------------------------------+
93
94 Note that many of these have little practical significance in modern usage. The
95 mnemonics derive from teleprinter conventions that predate digital computers.
96
97 The module supplies the following functions, patterned on those in the standard
98 C library:
99
100
101 .. function:: isalnum(c)
102
103 Checks for an ASCII alphanumeric character; it is equivalent to ``isalpha(c) or
104 isdigit(c)``.
105
106
107 .. function:: isalpha(c)
108
109 Checks for an ASCII alphabetic character; it is equivalent to ``isupper(c) or
110 islower(c)``.
111
112
113 .. function:: isascii(c)
114
115 Checks for a character value that fits in the 7-bit ASCII set.
116
117
118 .. function:: isblank(c)
119
120 Checks for an ASCII whitespace character; space or horizontal tab.
121
122
123 .. function:: iscntrl(c)
124
125 Checks for an ASCII control character (in the range 0x00 to 0x1f or 0x7f).
126
127
128 .. function:: isdigit(c)
129
130 Checks for an ASCII decimal digit, ``'0'`` through ``'9'``. This is equivalent
131 to ``c in string.digits``.
132
133
134 .. function:: isgraph(c)
135
136 Checks for ASCII any printable character except space.
137
138
139 .. function:: islower(c)
140
141 Checks for an ASCII lower-case character.
142
143
144 .. function:: isprint(c)
145
146 Checks for any ASCII printable character including space.
147
148
149 .. function:: ispunct(c)
150
151 Checks for any printable ASCII character which is not a space or an alphanumeric
152 character.
153
154
155 .. function:: isspace(c)
156
157 Checks for ASCII white-space characters; space, line feed, carriage return, form
158 feed, horizontal tab, vertical tab.
159
160
161 .. function:: isupper(c)
162
163 Checks for an ASCII uppercase letter.
164
165
166 .. function:: isxdigit(c)
167
168 Checks for an ASCII hexadecimal digit. This is equivalent to ``c in
169 string.hexdigits``.
170
171
172 .. function:: isctrl(c)
173
174 Checks for an ASCII control character (ordinal values 0 to 31).
175
176
177 .. function:: ismeta(c)
178
179 Checks for a non-ASCII character (ordinal values 0x80 and above).
180
181 These functions accept either integers or single-character strings; when the argument is a
182 string, it is first converted using the built-in function :func:`ord`.
183
184 Note that all these functions check ordinal bit values derived from the
185 character of the string you pass in; they do not actually know anything about
186 the host machine's character encoding.
187
188 The following two functions take either a single-character string or integer
189 byte value; they return a value of the same type.
190
191
192 .. function:: ascii(c)
193
194 Return the ASCII value corresponding to the low 7 bits of *c*.
195
196
197 .. function:: ctrl(c)
198
199 Return the control character corresponding to the given character (the character
200 bit value is bitwise-anded with 0x1f).
201
202
203 .. function:: alt(c)
204
205 Return the 8-bit character corresponding to the given ASCII character (the
206 character bit value is bitwise-ored with 0x80).
207
208 The following function takes either a single-character string or integer value;
209 it returns a string.
210
211
212 .. index::
213 single: ^ (caret); in curses module
214 single: ! (exclamation); in curses module
215
216 .. function:: unctrl(c)
217
218 Return a string representation of the ASCII character *c*. If *c* is printable,
219 this string is the character itself. If the character is a control character
220 (0x00--0x1f) the string consists of a caret (``'^'``) followed by the
221 corresponding uppercase letter. If the character is an ASCII delete (0x7f) the
222 string is ``'^?'``. If the character has its meta bit (0x80) set, the meta bit
223 is stripped, the preceding rules applied, and ``'!'`` prepended to the result.
224
225
226 .. data:: controlnames
227
228 A 33-element string array that contains the ASCII mnemonics for the thirty-two
229 ASCII control characters from 0 (NUL) to 0x1f (US), in order, plus the mnemonic
230 ``SP`` for the space character.
231