[Python-checkins] r72088 - peps/trunk/pep-0383.txt

martin.v.loewis python-checkins at python.org
Wed Apr 29 08:26:44 CEST 2009


Author: martin.v.loewis
Date: Wed Apr 29 08:26:43 2009
New Revision: 72088

Log:
Clarify that byte-oriented interfaces are not touched.
Add example showing script-level usage of the error handler.


Modified:
   peps/trunk/pep-0383.txt

Modified: peps/trunk/pep-0383.txt
==============================================================================
--- peps/trunk/pep-0383.txt	(original)
+++ peps/trunk/pep-0383.txt	Wed Apr 29 08:26:43 2009
@@ -88,6 +88,10 @@
 (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 @@
 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
 =========


More information about the Python-checkins mailing list