This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author akira
Recipients akira, bru, docs@python, ezio.melotti, georg.brandl, planet36, r.david.murray, steven.daprano, vstinner
Date 2014-12-13.15:30:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1418484605.96.0.78891909405.issue23017@psf.upfronthosting.co.za>
In-reply-to
Content
C standard defines locale-specific *printing characters* that are [ -~]
in "C" locale for implementations that use 7-bit US ASCII character set
i.e., SP (space, 0x20) is a printing character in C (isprint() returns
nonzero).

There is isgraph() function that returns zero for the space but
otherwise is equivalent to isprint().

POSIX definition is aligned with the ISO C standard.

I don't know what RFC 5822 has to do with this issue but the rfc
contradicts itself e.g., in one place it has: "printable US-ASCII
characters except SP" that imlies that SP *is* printable but in other
places it considers isprint==isgraph. The authors probably meant
characters for which isgraph() is nonzero when they use "printable
US-ASCII" (that is incorrect according to C standard).

Tests from issue9770 show the relation between C character classes and
string constants [1]:

  set(string.printable) == set(C['graph']) + set(C['space'])

where C['space'] is '\t\n\v\f\r ' (the standard C whitespace).

It is a documented behavior [2]:

  This is a combination of digits, ascii_letters, punctuation,
  and whitespace

where *whitespace* is C['space'].

In Python 2, *printable* is locale-dependent and it coincides with the
corresponding Python 3 definition in "C" locale with ASCII charset.

Unlike other string constants, *printable* differs from C['print'] on
both Python 2 and 3 because it includes whitespace characters other than
space.

str.isprintable [3] obeys C['print'] (in ASCII range) and considers SP
to be printable.

---

It might be too late to change string.printable to correspond to C
isprint() (for ASCII characters).

I've uploaded a documentation patch that mentions that string.printable
and str.isprintable differ.

[1] http://bugs.python.org/review/9770/diff/12212/Lib/test/test_curses_ascii.py
[2] https://hg.python.org/cpython/file/3.4/Doc/library/string.rst#l62
[3] https://docs.python.org/3.4/library/stdtypes.html#str.isprintable
History
Date User Action Args
2014-12-13 15:30:06akirasetrecipients: + akira, georg.brandl, vstinner, ezio.melotti, steven.daprano, r.david.murray, docs@python, planet36, bru
2014-12-13 15:30:05akirasetmessageid: <1418484605.96.0.78891909405.issue23017@psf.upfronthosting.co.za>
2014-12-13 15:30:05akiralinkissue23017 messages
2014-12-13 15:30:05akiracreate