[Python-checkins] CVS: python/dist/src/Doc/api api.tex,1.120,1.121

M.-A. Lemburg lemburg@users.sourceforge.net
Tue, 15 May 2001 04:58:07 -0700


Update of /cvsroot/python/python/dist/src/Doc/api
In directory usw-pr-cvs1:/tmp/cvs-serv24065/Doc/api

Modified Files:
	api.tex 
Log Message:
This patch changes the way the string .encode() method works slightly
and introduces a new method .decode(). 

The major change is that strg.encode() will no longer try to convert
Unicode returns from the codec into a string, but instead pass along
the Unicode object as-is. The same is now true for all other codec 
return types. The underlying C APIs were changed accordingly.

Note that even though this does have the potential of breaking
existing code, the chances are low since conversion from Unicode 
previously took place using the default encoding which is normally
set to ASCII rendering this auto-conversion mechanism useless for 
most Unicode encodings.

The good news is that you can now use .encode() and .decode() with
much greater ease and that the door was opened for better accessibility
of the builtin codecs.

As demonstration of the new feature, the patch includes a few new
codecs which allow string to string encoding and decoding (rot13,
hex, zip, uu, base64).

Written by Marc-Andre Lemburg. Copyright assigned to the PSF.



Index: api.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/api/api.tex,v
retrieving revision 1.120
retrieving revision 1.121
diff -C2 -r1.120 -r1.121
*** api.tex	2001/05/07 17:47:07	1.120
--- api.tex	2001/05/15 11:58:05	1.121
***************
*** 2327,2332 ****
                                                 const char *encoding,
                                                 const char *errors}
! Create a string object by decoding \var{size} bytes of the encoded
! buffer \var{s}. \var{encoding} and \var{errors} have the same meaning
  as the parameters of the same name in the unicode() builtin
  function. The codec to be used is looked up using the Python codec
--- 2327,2333 ----
                                                 const char *encoding,
                                                 const char *errors}
! Creates an object by decoding \var{size} bytes of the encoded
! buffer \var{s} using the codec registered
! for \var{encoding}. \var{encoding} and \var{errors} have the same meaning
  as the parameters of the same name in the unicode() builtin
  function. The codec to be used is looked up using the Python codec
***************
*** 2335,2344 ****
  \end{cfuncdesc}
  
! \begin{cfuncdesc}{PyObject*}{PyString_Encode}{const Py_UNICODE *s,
                                                 int size,
                                                 const char *encoding,
                                                 const char *errors}
! Encodes the \ctype{Py_UNICODE} buffer of the given size and returns a
! Python string object. \var{encoding} and \var{errors} have the same
  meaning as the parameters of the same name in the string .encode()
  method. The codec to be used is looked up using the Python codec
--- 2336,2357 ----
  \end{cfuncdesc}
  
! \begin{cfuncdesc}{PyObject*}{PyString_AsDecodedObject}{PyObject *str,
!                                                const char *encoding,
!                                                const char *errors}
! Decodes a string object by passing it to the codec registered
! for \var{encoding} and returns the result as Python 
! object. \var{encoding} and \var{errors} have the same meaning as the
! parameters of the same name in the string .encode() method. The codec
! to be used is looked up using the Python codec registry. Returns
! \NULL{} in case an exception was raised by the codec.
! \end{cfuncdesc}
! 
! \begin{cfuncdesc}{PyObject*}{PyString_Encode}{const char *s,
                                                 int size,
                                                 const char *encoding,
                                                 const char *errors}
! Encodes the \ctype{char} buffer of the given size by passing it to 
! the codec registered for \var{encoding} and returns a Python object. 
! \var{encoding} and \var{errors} have the same
  meaning as the parameters of the same name in the string .encode()
  method. The codec to be used is looked up using the Python codec
***************
*** 2347,2354 ****
  \end{cfuncdesc}
  
! \begin{cfuncdesc}{PyObject*}{PyString_AsEncodedString}{PyObject *unicode,
                                                 const char *encoding,
                                                 const char *errors}
! Encodes a string object and returns the result as Python string
  object. \var{encoding} and \var{errors} have the same meaning as the
  parameters of the same name in the string .encode() method. The codec
--- 2360,2368 ----
  \end{cfuncdesc}
  
! \begin{cfuncdesc}{PyObject*}{PyString_AsEncodedObject}{PyObject *str,
                                                 const char *encoding,
                                                 const char *errors}
! Encodes a string object using the codec registered
! for \var{encoding} and returns the result as Python 
  object. \var{encoding} and \var{errors} have the same meaning as the
  parameters of the same name in the string .encode() method. The codec