curses.ascii --- ASCII 字元的工具程式

原始碼:Lib/curses/ascii.py


Thecurses.ascii module supplies name constants for ASCII characters andfunctions to test membership in various ASCII character classes. The constantssupplied are names for control characters as follows:

名稱

含義

curses.ascii.NUL
curses.ascii.SOH

Start of heading, console interrupt

curses.ascii.STX

Start of text

curses.ascii.ETX

End of text

curses.ascii.EOT

End of transmission

curses.ascii.ENQ

Enquiry, goes withACK flow control

curses.ascii.ACK

Acknowledgement

curses.ascii.BEL

Bell

curses.ascii.BS

Backspace

curses.ascii.TAB

Tab

curses.ascii.HT

Alias forTAB: "Horizontal tab"

curses.ascii.LF

Line feed

curses.ascii.NL

Alias forLF: "New line"

curses.ascii.VT

Vertical tab

curses.ascii.FF

Form feed

curses.ascii.CR

Carriage return

curses.ascii.SO

Shift-out, begin alternate character set

curses.ascii.SI

Shift-in, resume default character set

curses.ascii.DLE

Data-link escape

curses.ascii.DC1

XON, for flow control

curses.ascii.DC2

Device control 2, block-mode flow control

curses.ascii.DC3

XOFF, for flow control

curses.ascii.DC4

Device control 4

curses.ascii.NAK

Negative acknowledgement

curses.ascii.SYN

Synchronous idle

curses.ascii.ETB

End transmission block

curses.ascii.CAN

Cancel

curses.ascii.EM

End of medium

curses.ascii.SUB

Substitute

curses.ascii.ESC

Escape

curses.ascii.FS

File separator

curses.ascii.GS

Group separator

curses.ascii.RS

Record separator, block-mode terminator

curses.ascii.US

Unit separator

curses.ascii.SP

Space

curses.ascii.DEL

Delete

Note that many of these have little practical significance in modern usage. Themnemonics derive from teleprinter conventions that predate digital computers.

The module supplies the following functions, patterned on those in the standardC library:

curses.ascii.isalnum(c)

Checks for an ASCII alphanumeric character; it is equivalent toisalpha(c)orisdigit(c).

curses.ascii.isalpha(c)

Checks for an ASCII alphabetic character; it is equivalent toisupper(c)orislower(c).

curses.ascii.isascii(c)

Checks for a character value that fits in the 7-bit ASCII set.

curses.ascii.isblank(c)

Checks for an ASCII whitespace character; space or horizontal tab.

curses.ascii.iscntrl(c)

Checks for an ASCII control character (in the range 0x00 to 0x1f or 0x7f).

curses.ascii.isdigit(c)

Checks for an ASCII decimal digit,'0' through'9'. This is equivalenttocinstring.digits.

curses.ascii.isgraph(c)

Checks for ASCII any printable character except space.

curses.ascii.islower(c)

Checks for an ASCII lower-case character.

curses.ascii.isprint(c)

Checks for any ASCII printable character including space.

curses.ascii.ispunct(c)

Checks for any printable ASCII character which is not a space or an alphanumericcharacter.

curses.ascii.isspace(c)

Checks for ASCII white-space characters; space, line feed, carriage return, formfeed, horizontal tab, vertical tab.

curses.ascii.isupper(c)

Checks for an ASCII uppercase letter.

curses.ascii.isxdigit(c)

Checks for an ASCII hexadecimal digit. This is equivalent tocinstring.hexdigits.

curses.ascii.isctrl(c)

Checks for an ASCII control character (ordinal values 0 to 31).

curses.ascii.ismeta(c)

Checks for a non-ASCII character (ordinal values 0x80 and above).

These functions accept either integers or single-character strings; when the argument is astring, it is first converted using the built-in functionord().

Note that all these functions check ordinal bit values derived from thecharacter of the string you pass in; they do not actually know anything aboutthe host machine's character encoding.

The following two functions take either a single-character string or integerbyte value; they return a value of the same type.

curses.ascii.ascii(c)

Return the ASCII value corresponding to the low 7 bits ofc.

curses.ascii.ctrl(c)

Return the control character corresponding to the given character (the characterbit value is bitwise-anded with 0x1f).

curses.ascii.alt(c)

Return the 8-bit character corresponding to the given ASCII character (thecharacter bit value is bitwise-ored with 0x80).

The following function takes either a single-character string or integer value;it returns a string.

curses.ascii.unctrl(c)

Return a string representation of the ASCII characterc. Ifc is printable,this string is the character itself. If the character is a control character(0x00--0x1f) the string consists of a caret ('^') followed by thecorresponding uppercase letter. If the character is an ASCII delete (0x7f) thestring is'^?'. If the character has its meta bit (0x80) set, the meta bitis stripped, the preceding rules applied, and'!' prepended to the result.

curses.ascii.controlnames

A 33-element string array that contains the ASCII mnemonics for the thirty-twoASCII control characters from 0 (NUL) to 0x1f (US), in order, plus the mnemonicSP for the space character.