Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 514f973

Browse files
Issue #27294: Numerical state in the repr for Tkinter event objects is now
represented as a compination of known flags.
1 parent 56fe474 commit 514f973

4 files changed

Lines changed: 61 additions & 5 deletions

File tree

Doc/library/curses.ascii.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ C library:
115115

116116
.. function:: isblank(c)
117117

118-
Checks for an ASCII whitespace character.
118+
Checks for an ASCII whitespace character; space or horizontal tab.
119119

120120

121121
.. function:: iscntrl(c)
122122

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

125125

126126
.. function:: isdigit(c)

Lib/curses/ascii.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def _ctoi(c):
5454
def isalnum(c): return isalpha(c) or isdigit(c)
5555
def isalpha(c): return isupper(c) or islower(c)
5656
def isascii(c): return _ctoi(c) <= 127 # ?
57-
def isblank(c): return _ctoi(c) in (8,32)
58-
def iscntrl(c): return _ctoi(c) <= 31
57+
def isblank(c): return _ctoi(c) in (9, 32)
58+
def iscntrl(c): return _ctoi(c) <= 31 or _ctoi(c) == 127
5959
def isdigit(c): return _ctoi(c) >= 48 and _ctoi(c) <= 57
6060
def isgraph(c): return _ctoi(c) >= 33 and _ctoi(c) <= 126
6161
def islower(c): return _ctoi(c) >= 97 and _ctoi(c) <= 122
6262
def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
63-
def ispunct(c): return _ctoi(c) != 32 and not isalnum(c)
63+
def ispunct(c): return isgraph(c) and not isalnum(c)
6464
def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)
6565
def isupper(c): return _ctoi(c) >= 65 and _ctoi(c) <= 90
6666
def isxdigit(c): return isdigit(c) or \

Lib/test/test_curses.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111

1212
import os
13+
import string
1314
import sys
1415
import tempfile
1516
import unittest
@@ -399,6 +400,55 @@ def test_update_lines_cols(self):
399400

400401
class TestAscii(unittest.TestCase):
401402

403+
def test_controlnames(self):
404+
for name in curses.ascii.controlnames:
405+
self.assertTrue(hasattr(curses.ascii, name), name)
406+
407+
def test_ctypes(self):
408+
def check(func, expected):
409+
with self.subTest(ch=c, func=func):
410+
self.assertEqual(func(i), expected)
411+
self.assertEqual(func(c), expected)
412+
413+
for i in range(256):
414+
c = chr(i)
415+
b = bytes([i])
416+
check(curses.ascii.isalnum, b.isalnum())
417+
check(curses.ascii.isalpha, b.isalpha())
418+
check(curses.ascii.isdigit, b.isdigit())
419+
check(curses.ascii.islower, b.islower())
420+
check(curses.ascii.isspace, b.isspace())
421+
check(curses.ascii.isupper, b.isupper())
422+
423+
check(curses.ascii.isascii, i < 128)
424+
check(curses.ascii.ismeta, i >= 128)
425+
check(curses.ascii.isctrl, i < 32)
426+
check(curses.ascii.iscntrl, i < 32 or i == 127)
427+
check(curses.ascii.isblank, c in ' \t')
428+
check(curses.ascii.isgraph, 32 < i <= 126)
429+
check(curses.ascii.isprint, 32 <= i <= 126)
430+
check(curses.ascii.ispunct, c in string.punctuation)
431+
check(curses.ascii.isxdigit, c in string.hexdigits)
432+
433+
def test_ascii(self):
434+
ascii = curses.ascii.ascii
435+
self.assertEqual(ascii('\xc1'), 'A')
436+
self.assertEqual(ascii('A'), 'A')
437+
self.assertEqual(ascii(ord('\xc1')), ord('A'))
438+
439+
def test_ctrl(self):
440+
ctrl = curses.ascii.ctrl
441+
self.assertEqual(ctrl('J'), '\n')
442+
self.assertEqual(ctrl('\n'), '\n')
443+
self.assertEqual(ctrl('@'), '\0')
444+
self.assertEqual(ctrl(ord('J')), ord('\n'))
445+
446+
def test_alt(self):
447+
alt = curses.ascii.alt
448+
self.assertEqual(alt('\n'), '\x8a')
449+
self.assertEqual(alt('A'), '\xc1')
450+
self.assertEqual(alt(ord('A')), 0xc1)
451+
402452
def test_unctrl(self):
403453
unctrl = curses.ascii.unctrl
404454
self.assertEqual(unctrl('a'), 'a')
@@ -408,9 +458,13 @@ def test_unctrl(self):
408458
self.assertEqual(unctrl('\x7f'), '^?')
409459
self.assertEqual(unctrl('\n'), '^J')
410460
self.assertEqual(unctrl('\0'), '^@')
461+
self.assertEqual(unctrl(ord('A')), 'A')
462+
self.assertEqual(unctrl(ord('\n')), '^J')
411463
# Meta-bit characters
412464
self.assertEqual(unctrl('\x8a'), '!^J')
413465
self.assertEqual(unctrl('\xc1'), '!A')
466+
self.assertEqual(unctrl(ord('\x8a')), '!^J')
467+
self.assertEqual(unctrl(ord('\xc1')), '!A')
414468

415469

416470
if __name__ == '__main__':

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #27079: Fixed curses.ascii functions isblank(), iscntrl() and ispunct().
17+
1618
- Issue #26754: Some functions (compile() etc) accepted a filename argument
1719
encoded as an iterable of integers. Now only strings and byte-like objects
1820
are accepted.

0 commit comments

Comments
 (0)