Fix encode/decode method doc of str, bytes, bytearray types
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 7 Nov 2010 18:41:46 +0000 (18:41 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 7 Nov 2010 18:41:46 +0000 (18:41 +0000)
 * Specify the default encoding: write 'utf-8' instead of
   sys.getdefaultencoding(), because the default encoding is now constant
 * Specify the default errors value

Doc/library/stdtypes.rst
Objects/bytearrayobject.c
Objects/bytesobject.c
Objects/unicodeobject.c

index 9f2831a3161add041e68556a693e6d0df4003320..f2bb99d8e88d7629aee213c30378deeb52e4bad8 100644 (file)
@@ -992,12 +992,12 @@ functions based on regular expressions.
    interpreted as in slice notation.
 
 
-.. method:: str.encode(encoding=sys.getdefaultencoding(), errors="strict")
+.. method:: str.encode(encoding="utf-8", errors="strict")
 
-   Return an encoded version of the string as a bytes object.  Default encoding
-   is the current default string encoding.  *errors* may be given to set a
-   different error handling scheme.  The default for *errors* is ``'strict'``,
-   meaning that encoding errors raise a :exc:`UnicodeError`.  Other possible
+   Return an encoded version of the string as a bytes object. Default encoding
+   is ``'utf-8'``. *errors* may be given to set a different error handling scheme.
+   The default for *errors* is ``'strict'``, meaning that encoding errors raise
+   a :exc:`UnicodeError`. Other possible
    values are ``'ignore'``, ``'replace'``, ``'xmlcharrefreplace'``,
    ``'backslashreplace'`` and any other name registered via
    :func:`codecs.register_error`, see section :ref:`codec-base-classes`. For a
@@ -1765,11 +1765,11 @@ Wherever one of these methods needs to interpret the bytes as characters
       b = a.replace(b"a", b"f")
 
 
-.. method:: bytes.decode(encoding=sys.getdefaultencoding(), errors="strict")
-            bytearray.decode(encoding=sys.getdefaultencoding(), errors="strict")
+.. method:: bytes.decode(encoding="utf-8", errors="strict")
+            bytearray.decode(encoding="utf-8", errors="strict")
 
-   Return a string decoded from the given bytes.  Default encoding is the
-   current default string encoding.  *errors* may be given to set a different
+   Return a string decoded from the given bytes.  Default encoding is
+   ``'utf-8'``. *errors* may be given to set a different
    error handling scheme.  The default for *errors* is ``'strict'``, meaning
    that encoding errors raise a :exc:`UnicodeError`.  Other possible values are
    ``'ignore'``, ``'replace'`` and any other name registered via
index 283102ae6ff69ac4d39e418364ed1fc359a01cc5..1a50ce3101977691ec2cb4192dc695e2e5e31289 100644 (file)
@@ -2465,10 +2465,10 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
 }
 
 PyDoc_STRVAR(decode_doc,
-"B.decode([encoding[, errors]]) -> str\n\
+"B.decode([encoding='utf-8'[, errors='strict']]) -> str\n\
 \n\
-Decode B using the codec registered for encoding. encoding defaults\n\
-to the default encoding. errors may be given to set a different error\n\
+Decode B using the codec registered for encoding. Default encoding\n\
+is 'utf-8'. errors may be given to set a different error\n\
 handling scheme.  Default is 'strict' meaning that encoding errors raise\n\
 a UnicodeDecodeError.  Other possible values are 'ignore' and 'replace'\n\
 as well as any other name registered with codecs.register_error that is\n\
index 382e91100819591f8179e4f8d2cc2002405bb13d..b8fa8ee255e46d93ce7eb8729a120ede9340df5e 100644 (file)
@@ -2289,10 +2289,10 @@ bytes_endswith(PyBytesObject *self, PyObject *args)
 
 
 PyDoc_STRVAR(decode__doc__,
-"B.decode([encoding[, errors]]) -> str\n\
+"B.decode([encoding='utf-8'[, errors='strict']]) -> str\n\
 \n\
-Decode B using the codec registered for encoding. encoding defaults\n\
-to the default encoding. errors may be given to set a different error\n\
+Decode B using the codec registered for encoding. Default encoding\n\
+is 'utf-8'. errors may be given to set a different error\n\
 handling scheme.  Default is 'strict' meaning that encoding errors raise\n\
 a UnicodeDecodeError.  Other possible values are 'ignore' and 'replace'\n\
 as well as any other name registerd with codecs.register_error that is\n\
index 32bcb344f49ee1552ccc9d72da6ee2718ff8e331..4be0b17c3975dc00ab9e31a36228d86e891f2af0 100644 (file)
@@ -7393,10 +7393,10 @@ unicode_count(PyUnicodeObject *self, PyObject *args)
 }
 
 PyDoc_STRVAR(encode__doc__,
-             "S.encode([encoding[, errors]]) -> bytes\n\
+             "S.encode([encoding='utf-8'[, errors='strict']]) -> bytes\n\
 \n\
-Encode S using the codec registered for encoding. encoding defaults\n\
-to the default encoding. errors may be given to set a different error\n\
+Encode S using the codec registered for encoding. Default encoding\n\
+is 'utf-8'. errors may be given to set a different error\n\
 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
 a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\
 'xmlcharrefreplace' as well as any other name registered with\n\