Skip to content

Commit f954c4b

Browse files
committed
Remove meaning of -ttt, but still accept -t option on cmdline for compatibility.
1 parent e5d68ac commit f954c4b

37 files changed

+1242
-1082
lines changed

Doc/c-api/unicode.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ the Python configuration.
144144

145145
Return 1 or 0 depending on whether *ch* is an alphanumeric character.
146146

147+
.. cfunction:: int Py_UNICODE_ISPRINTABLE(Py_UNICODE ch)
148+
149+
Return 1 or 0 depending on whether *ch* is a printable character.
150+
Characters defined in the Unicode character database as "Other"
151+
or "Separator" other than ASCII space(0x20) are not considered
152+
printable.
153+
147154
These APIs can be used for fast direct character conversions:
148155

149156

@@ -228,6 +235,9 @@ APIs:
228235
+===================+=====================+================================+
229236
| :attr:`%%` | *n/a* | The literal % character. |
230237
+-------------------+---------------------+--------------------------------+
238+
| :attr:`%a` | PyObject\* | The result of calling |
239+
| | | :func:`ascii`. |
240+
+-------------------+---------------------+--------------------------------+
231241
| :attr:`%c` | int | A single character, |
232242
| | | represented as an C int. |
233243
+-------------------+---------------------+--------------------------------+

Doc/library/functions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ are always available. They are listed here in alphabetical order.
9191
return False
9292

9393

94+
.. function:: ascii(object)
95+
96+
As :func:`repr`, return a string containing a printable
97+
representation of an object. But unlike :func:`repr`, the non-ASCII
98+
characters in the string returned by :func:`ascii`() are hex-escaped
99+
to generate a same string as :func:`repr` in Python 2.
100+
101+
94102
.. function:: bin(x)
95103

96104
Convert an integer number to a binary string. The result is a valid Python

Doc/library/stdtypes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ functions based on regular expressions.
774774
least one cased character, false otherwise.
775775

776776

777+
.. method:: str.isprintable()
778+
779+
Return true if all characters in the string are printable and there is at
780+
least one character, false otherwise. Characters defined in the Unicode
781+
character database as "Other" or "Separator" other than ASCII space(0x20) are
782+
not considered printable.
783+
784+
777785
.. method:: str.isspace()
778786

779787
Return true if there are only whitespace characters in the string and there is

Doc/library/sys.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ always available.
231231
+------------------------------+------------------------------------------+
232232
| :const:`ignore_environment` | -E |
233233
+------------------------------+------------------------------------------+
234-
| :const:`tabcheck` | -t or -tt |
235-
+------------------------------+------------------------------------------+
236234
| :const:`verbose` | -v |
237235
+------------------------------+------------------------------------------+
238236
| :const:`unicode` | -U |

Doc/using/cmdline.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,6 @@ Miscellaneous options
222222
manipulations of :data:`sys.path` that it entails.
223223

224224

225-
.. cmdoption:: -t
226-
227-
Issue a warning when a source file mixes tabs and spaces for indentation in a
228-
way that makes it depend on the worth of a tab expressed in spaces. Issue an
229-
error when the option is given twice (:option:`-tt`).
230-
231-
232225
.. cmdoption:: -u
233226

234227
Force stdin, stdout and stderr to be totally unbuffered. On systems where it

Include/pydebug.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ PyAPI_DATA(int) Py_NoSiteFlag;
1414
PyAPI_DATA(int) Py_BytesWarningFlag;
1515
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
1616
PyAPI_DATA(int) Py_FrozenFlag;
17-
PyAPI_DATA(int) Py_TabcheckFlag;
1817
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
1918
PyAPI_DATA(int) Py_DivisionWarningFlag;
2019
PyAPI_DATA(int) Py_DontWriteBytecodeFlag;

Include/unicodeobject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
217217
# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak
218218
# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase
219219
# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric
220+
# define _PyUnicode_IsPrintable _PyUnicodeUCS2_IsPrintable
220221
# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase
221222
# define _PyUnicode_IsXidStart _PyUnicodeUCS2_IsXidStart
222223
# define _PyUnicode_IsXidContinue _PyUnicodeUCS2_IsXidContinue
@@ -311,6 +312,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
311312
# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak
312313
# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase
313314
# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric
315+
# define _PyUnicode_IsPrintable _PyUnicodeUCS4_IsPrintable
314316
# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase
315317
# define _PyUnicode_IsXidStart _PyUnicodeUCS4_IsXidStart
316318
# define _PyUnicode_IsXidContinue _PyUnicodeUCS4_IsXidContinue
@@ -351,6 +353,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
351353
#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
352354
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
353355
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
356+
#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
354357

355358
#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
356359
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
@@ -381,6 +384,7 @@ extern const unsigned char _Py_ascii_whitespace[];
381384
#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
382385
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
383386
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
387+
#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
384388

385389
#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
386390
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
@@ -1499,6 +1503,10 @@ PyAPI_FUNC(int) _PyUnicode_IsNumeric(
14991503
Py_UNICODE ch /* Unicode character */
15001504
);
15011505

1506+
PyAPI_FUNC(int) _PyUnicode_IsPrintable(
1507+
Py_UNICODE ch /* Unicode character */
1508+
);
1509+
15021510
PyAPI_FUNC(int) _PyUnicode_IsAlpha(
15031511
Py_UNICODE ch /* Unicode character */
15041512
);

Lib/doctest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,13 @@ class OutputChecker:
14411441
and returns true if they match; and `output_difference`, which
14421442
returns a string describing the differences between two outputs.
14431443
"""
1444+
1445+
def _toAscii(self, s):
1446+
"""
1447+
Convert string to hex-escaped ASCII string.
1448+
"""
1449+
return str(s.encode('ASCII', 'backslashreplace'), "ASCII")
1450+
14441451
def check_output(self, want, got, optionflags):
14451452
"""
14461453
Return True iff the actual output from an example (`got`)
@@ -1451,6 +1458,15 @@ def check_output(self, want, got, optionflags):
14511458
documentation for `TestRunner` for more information about
14521459
option flags.
14531460
"""
1461+
1462+
# If `want` contains hex-escaped character such as "\u1234",
1463+
# then `want` is a string of six characters(e.g. [\,u,1,2,3,4]).
1464+
# On the other hand, `got` could be an another sequence of
1465+
# characters such as [\u1234], so `want` and `got` should
1466+
# be folded to hex-escaped ASCII string to compare.
1467+
got = self._toAscii(got)
1468+
want = self._toAscii(want)
1469+
14541470
# Handle the common case first, for efficiency:
14551471
# if they're string-identical, always return true.
14561472
if got == want:

Lib/test/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def test_unicode(self):
768768
a = array.array('u', s)
769769
self.assertEqual(
770770
repr(a),
771-
"array('u', '\\x00=\"\\'a\\\\b\\x80\\xff\\x00\\x01\\u1234')")
771+
"array('u', '\\x00=\"\\'a\\\\b\\x80\xff\\x00\\x01\u1234')")
772772

773773
self.assertRaises(TypeError, a.fromunicode)
774774

Lib/test/test_builtin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def test_any(self):
159159
S = [10, 20, 30]
160160
self.assertEqual(any(x > 42 for x in S), False)
161161

162+
def test_ascii(self):
163+
self.assertEqual(ascii("\u0370"), "'\\u0370'")
164+
162165
def test_neg(self):
163166
x = -sys.maxsize-1
164167
self.assert_(isinstance(x, int))

0 commit comments

Comments
 (0)