~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Doc/library/curses.ascii.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
:mod:`curses.ascii` --- Utilities for ASCII characters
 
3
======================================================
 
4
 
 
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>
 
9
 
 
10
 
 
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:
 
14
 
 
15
+--------------+----------------------------------------------+
 
16
| Name         | Meaning                                      |
 
17
+==============+==============================================+
 
18
| :const:`NUL` |                                              |
 
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
+--------------+----------------------------------------------+
 
90
 
 
91
Note that many of these have little practical significance in modern usage.  The
 
92
mnemonics derive from teleprinter conventions that predate digital computers.
 
93
 
 
94
The module supplies the following functions, patterned on those in the standard
 
95
C library:
 
96
 
 
97
 
 
98
.. function:: isalnum(c)
 
99
 
 
100
   Checks for an ASCII alphanumeric character; it is equivalent to ``isalpha(c) or
 
101
   isdigit(c)``.
 
102
 
 
103
 
 
104
.. function:: isalpha(c)
 
105
 
 
106
   Checks for an ASCII alphabetic character; it is equivalent to ``isupper(c) or
 
107
   islower(c)``.
 
108
 
 
109
 
 
110
.. function:: isascii(c)
 
111
 
 
112
   Checks for a character value that fits in the 7-bit ASCII set.
 
113
 
 
114
 
 
115
.. function:: isblank(c)
 
116
 
 
117
   Checks for an ASCII whitespace character.
 
118
 
 
119
 
 
120
.. function:: iscntrl(c)
 
121
 
 
122
   Checks for an ASCII control character (in the range 0x00 to 0x1f).
 
123
 
 
124
 
 
125
.. function:: isdigit(c)
 
126
 
 
127
   Checks for an ASCII decimal digit, ``'0'`` through ``'9'``.  This is equivalent
 
128
   to ``c in string.digits``.
 
129
 
 
130
 
 
131
.. function:: isgraph(c)
 
132
 
 
133
   Checks for ASCII any printable character except space.
 
134
 
 
135
 
 
136
.. function:: islower(c)
 
137
 
 
138
   Checks for an ASCII lower-case character.
 
139
 
 
140
 
 
141
.. function:: isprint(c)
 
142
 
 
143
   Checks for any ASCII printable character including space.
 
144
 
 
145
 
 
146
.. function:: ispunct(c)
 
147
 
 
148
   Checks for any printable ASCII character which is not a space or an alphanumeric
 
149
   character.
 
150
 
 
151
 
 
152
.. function:: isspace(c)
 
153
 
 
154
   Checks for ASCII white-space characters; space, line feed, carriage return, form
 
155
   feed, horizontal tab, vertical tab.
 
156
 
 
157
 
 
158
.. function:: isupper(c)
 
159
 
 
160
   Checks for an ASCII uppercase letter.
 
161
 
 
162
 
 
163
.. function:: isxdigit(c)
 
164
 
 
165
   Checks for an ASCII hexadecimal digit.  This is equivalent to ``c in
 
166
   string.hexdigits``.
 
167
 
 
168
 
 
169
.. function:: isctrl(c)
 
170
 
 
171
   Checks for an ASCII control character (ordinal values 0 to 31).
 
172
 
 
173
 
 
174
.. function:: ismeta(c)
 
175
 
 
176
   Checks for a non-ASCII character (ordinal values 0x80 and above).
 
177
 
 
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`.
 
180
 
 
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.
 
186
 
 
187
The following two functions take either a single-character string or integer
 
188
byte value; they return a value of the same type.
 
189
 
 
190
 
 
191
.. function:: ascii(c)
 
192
 
 
193
   Return the ASCII value corresponding to the low 7 bits of *c*.
 
194
 
 
195
 
 
196
.. function:: ctrl(c)
 
197
 
 
198
   Return the control character corresponding to the given character (the character
 
199
   bit value is bitwise-anded with 0x1f).
 
200
 
 
201
 
 
202
.. function:: alt(c)
 
203
 
 
204
   Return the 8-bit character corresponding to the given ASCII character (the
 
205
   character bit value is bitwise-ored with 0x80).
 
206
 
 
207
The following function takes either a single-character string or integer value;
 
208
it returns a string.
 
209
 
 
210
 
 
211
.. function:: unctrl(c)
 
212
 
 
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.
 
219
 
 
220
 
 
221
.. data:: controlnames
 
222
 
 
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.
 
226