Clarify that byte-oriented interfaces are not touched.

Add example showing script-level usage of the error handler.
This commit is contained in:
Martin v. Löwis 2009-04-29 06:26:43 +00:00
parent ad949d3d01
commit 130a57a390
1 changed files with 13 additions and 1 deletions

View File

@ -88,6 +88,10 @@ strict definition of UTF-8 to determine what an invalid byte is
(which, among other restrictions, disallows to encode surrogate codes (which, among other restrictions, disallows to encode surrogate codes
in UTF-8). in UTF-8).
Byte-orientied interfaces that already exist in Python 3.0 are not
affected by this specification. They are neither enhanced nor
deprecated.
Discussion Discussion
========== ==========
@ -106,7 +110,15 @@ open(), which then encodes them back into their original byte
representation. Applications that need to process the original byte representation. Applications that need to process the original byte
strings can obtain them by encoding the character strings with the strings can obtain them by encoding the character strings with the
file system encoding, passing "python-escape" as the error handler file system encoding, passing "python-escape" as the error handler
name. name. For example, a function that works like os.listdir, except
for accepting and returning bytes, would be written as::
def listdir_b(dirname):
fse = sys.getfilesystemencoding()
dirname = dirname.decode(fse, "python-escape")
for fn in os.listdir(dirname):
# fn is now a str object
yield fn.encode(fse, "python-escape"
Copyright Copyright
========= =========