PyXR

c:\python24\lib \ curses \ ascii.py



0001 """Constants and membership tests for ASCII characters"""
0002 
0003 NUL     = 0x00  # ^@
0004 SOH     = 0x01  # ^A
0005 STX     = 0x02  # ^B
0006 ETX     = 0x03  # ^C
0007 EOT     = 0x04  # ^D
0008 ENQ     = 0x05  # ^E
0009 ACK     = 0x06  # ^F
0010 BEL     = 0x07  # ^G
0011 BS      = 0x08  # ^H
0012 TAB     = 0x09  # ^I
0013 HT      = 0x09  # ^I
0014 LF      = 0x0a  # ^J
0015 NL      = 0x0a  # ^J
0016 VT      = 0x0b  # ^K
0017 FF      = 0x0c  # ^L
0018 CR      = 0x0d  # ^M
0019 SO      = 0x0e  # ^N
0020 SI      = 0x0f  # ^O
0021 DLE     = 0x10  # ^P
0022 DC1     = 0x11  # ^Q
0023 DC2     = 0x12  # ^R
0024 DC3     = 0x13  # ^S
0025 DC4     = 0x14  # ^T
0026 NAK     = 0x15  # ^U
0027 SYN     = 0x16  # ^V
0028 ETB     = 0x17  # ^W
0029 CAN     = 0x18  # ^X
0030 EM      = 0x19  # ^Y
0031 SUB     = 0x1a  # ^Z
0032 ESC     = 0x1b  # ^[
0033 FS      = 0x1c  # ^\
0034 GS      = 0x1d  # ^]
0035 RS      = 0x1e  # ^^
0036 US      = 0x1f  # ^_
0037 SP      = 0x20  # space
0038 DEL     = 0x7f  # delete
0039 
0040 controlnames = [
0041 "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
0042 "BS",  "HT",  "LF",  "VT",  "FF",  "CR",  "SO",  "SI",
0043 "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
0044 "CAN", "EM",  "SUB", "ESC", "FS",  "GS",  "RS",  "US",
0045 "SP"
0046 ]
0047 
0048 def _ctoi(c):
0049     if type(c) == type(""):
0050         return ord(c)
0051     else:
0052         return c
0053 
0054 def isalnum(c): return isalpha(c) or isdigit(c)
0055 def isalpha(c): return isupper(c) or islower(c)
0056 def isascii(c): return _ctoi(c) <= 127          # ?
0057 def isblank(c): return _ctoi(c) in (8,32)
0058 def iscntrl(c): return _ctoi(c) <= 31
0059 def isdigit(c): return _ctoi(c) >= 48 and _ctoi(c) <= 57
0060 def isgraph(c): return _ctoi(c) >= 33 and _ctoi(c) <= 126
0061 def islower(c): return _ctoi(c) >= 97 and _ctoi(c) <= 122
0062 def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
0063 def ispunct(c): return _ctoi(c) != 32 and not isalnum(c)
0064 def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)
0065 def isupper(c): return _ctoi(c) >= 65 and _ctoi(c) <= 90
0066 def isxdigit(c): return isdigit(c) or \
0067     (_ctoi(c) >= 65 and _ctoi(c) <= 70) or (_ctoi(c) >= 97 and _ctoi(c) <= 102)
0068 def isctrl(c): return _ctoi(c) < 32
0069 def ismeta(c): return _ctoi(c) > 127
0070 
0071 def ascii(c):
0072     if type(c) == type(""):
0073         return chr(_ctoi(c) & 0x7f)
0074     else:
0075         return _ctoi(c) & 0x7f
0076 
0077 def ctrl(c):
0078     if type(c) == type(""):
0079         return chr(_ctoi(c) & 0x1f)
0080     else:
0081         return _ctoi(c) & 0x1f
0082 
0083 def alt(c):
0084     if type(c) == type(""):
0085         return chr(_ctoi(c) | 0x80)
0086     else:
0087         return _ctoi(c) | 0x80
0088 
0089 def unctrl(c):
0090     bits = _ctoi(c)
0091     if bits == 0x7f:
0092         rep = "^?"
0093     elif isprint(bits & 0x7f):
0094         rep = chr(bits & 0x7f)
0095     else:
0096         rep = "^" + chr(((bits & 0x7f) | 0x20) + 0x20)
0097     if bits & 0x80:
0098         return "!" + rep
0099     return rep
0100 

Generated by PyXR 0.9.4
SourceForge.net Logo