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 blank 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 any ASCII 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 ASCII printable 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). Unlike
175 :func:`iscntrl`, this does not include the delete character (0x7f).
176
177
178 .. function:: ismeta(c)
179
180 Checks for a non-ASCII character (ordinal values 0x80 and above).
181
182 These functions accept either integers or single-character strings; when the argument is a
183 string, it is first converted using the built-in function :func:`ord`.
184
185 Note that all these functions check ordinal bit values derived from the
186 character of the string you pass in; they do not actually know anything about
187 the host machine's character encoding.
188
189 The following two functions take either a single-character string or integer
190 byte value; they return a value of the same type.
191
192
193 .. function:: ascii(c)
194
195 Return the ASCII value corresponding to the low 7 bits of *c*.
196
197
198 .. function:: ctrl(c)
199
200 Return the control character corresponding to the given character (the character
201 bit value is bitwise-anded with 0x1f).
202
203
204 .. function:: alt(c)
205
206 Return the 8-bit character corresponding to the given ASCII character (the
207 character bit value is bitwise-ored with 0x80).
208
209 The following function takes either a single-character string or integer value;
210 it returns a string.
211
212
213 .. index::
214 single: ^ (caret); in curses module
215 single: ! (exclamation); in curses module
216
217 .. function:: unctrl(c)
218
219 Return a string representation of the ASCII character *c*. If *c* is printable,
220 this string is the character itself. If the character is a control character
221 (0x00--0x1f) the string consists of a caret (``'^'``) followed by the
222 corresponding uppercase letter. If the character is an ASCII delete (0x7f) the
223 string is ``'^?'``. If the character has its meta bit (0x80) set, the meta bit
224 is stripped, the preceding rules applied, and ``'!'`` prepended to the result.
225
226
227 .. data:: controlnames
228
229 A 33-element string array that contains the ASCII mnemonics for the thirty-two
230 ASCII control characters from 0 (NUL) to 0x1f (US), in order, plus the mnemonic
231 ``SP`` for the space character.
232