Clarify that byte-oriented interfaces are not touched.
Add example showing script-level usage of the error handler.
This commit is contained in:
parent
ad949d3d01
commit
130a57a390
14
pep-0383.txt
14
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
|
(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
|
||||||
=========
|
=========
|
||||||
|
|
Loading…
Reference in New Issue