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