123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- """Constants and membership tests for ASCII characters"""
- NUL = 0x00
- SOH = 0x01
- STX = 0x02
- ETX = 0x03
- EOT = 0x04
- ENQ = 0x05
- ACK = 0x06
- BEL = 0x07
- BS = 0x08
- TAB = 0x09
- HT = 0x09
- LF = 0x0a
- NL = 0x0a
- VT = 0x0b
- FF = 0x0c
- CR = 0x0d
- SO = 0x0e
- SI = 0x0f
- DLE = 0x10
- DC1 = 0x11
- DC2 = 0x12
- DC3 = 0x13
- DC4 = 0x14
- NAK = 0x15
- SYN = 0x16
- ETB = 0x17
- CAN = 0x18
- EM = 0x19
- SUB = 0x1a
- ESC = 0x1b
- FS = 0x1c
- GS = 0x1d
- RS = 0x1e
- US = 0x1f
- SP = 0x20
- DEL = 0x7f
- controlnames = [
- "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
- "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
- "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
- "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US",
- "SP"
- ]
- def _ctoi(c):
- if type(c) == type(""):
- return ord(c)
- else:
- return c
- def isalnum(c): return isalpha(c) or isdigit(c)
- def isalpha(c): return isupper(c) or islower(c)
- def isascii(c): return _ctoi(c) <= 127
- def isblank(c): return _ctoi(c) in (8,32)
- def iscntrl(c): return _ctoi(c) <= 31
- def isdigit(c): return _ctoi(c) >= 48 and _ctoi(c) <= 57
- def isgraph(c): return _ctoi(c) >= 33 and _ctoi(c) <= 126
- def islower(c): return _ctoi(c) >= 97 and _ctoi(c) <= 122
- def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
- def ispunct(c): return _ctoi(c) != 32 and not isalnum(c)
- def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)
- def isupper(c): return _ctoi(c) >= 65 and _ctoi(c) <= 90
- def isxdigit(c): return isdigit(c) or \
- (_ctoi(c) >= 65 and _ctoi(c) <= 70) or (_ctoi(c) >= 97 and _ctoi(c) <= 102)
- def isctrl(c): return _ctoi(c) < 32
- def ismeta(c): return _ctoi(c) > 127
- def ascii(c):
- if type(c) == type(""):
- return chr(_ctoi(c) & 0x7f)
- else:
- return _ctoi(c) & 0x7f
- def ctrl(c):
- if type(c) == type(""):
- return chr(_ctoi(c) & 0x1f)
- else:
- return _ctoi(c) & 0x1f
- def alt(c):
- if type(c) == type(""):
- return chr(_ctoi(c) | 0x80)
- else:
- return _ctoi(c) | 0x80
- def unctrl(c):
- bits = _ctoi(c)
- if bits == 0x7f:
- rep = "^?"
- elif isprint(bits & 0x7f):
- rep = chr(bits & 0x7f)
- else:
- rep = "^" + chr(((bits & 0x7f) | 0x20) + 0x20)
- if bits & 0x80:
- return "!" + rep
- return rep
|