From 130a57a39030c48dcfb9bb6d35199e8f6ee35a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 29 Apr 2009 06:26:43 +0000 Subject: [PATCH] Clarify that byte-oriented interfaces are not touched. Add example showing script-level usage of the error handler. --- pep-0383.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pep-0383.txt b/pep-0383.txt index dae9d7b5c..f8144fe46 100644 --- a/pep-0383.txt +++ b/pep-0383.txt @@ -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 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 ========== @@ -106,7 +110,15 @@ open(), which then encodes them back into their original byte representation. Applications that need to process the original byte strings can obtain them by encoding the character strings with the 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 =========