[Python-checkins] r54772 - in python/trunk: Doc/lib/libstdtypes.tex Doc/lib/libstring.tex Lib/string.py Lib/test/string_tests.py Misc/NEWS Objects/stringobject.c (original) (raw)

raymond.hettinger python-checkins at python.org
Thu Apr 12 06:10:04 CEST 2007


Author: raymond.hettinger Date: Thu Apr 12 06:10:00 2007 New Revision: 54772

Modified: python/trunk/Doc/lib/libstdtypes.tex python/trunk/Doc/lib/libstring.tex python/trunk/Lib/string.py python/trunk/Lib/test/string_tests.py python/trunk/Misc/NEWS python/trunk/Objects/stringobject.c Log: SF 1193128: Let str.translate(None) be an identity transformation

Modified: python/trunk/Doc/lib/libstdtypes.tex

--- python/trunk/Doc/lib/libstdtypes.tex (original) +++ python/trunk/Doc/lib/libstdtypes.tex Thu Apr 12 06:10:00 2007 @@ -878,6 +878,13 @@

You can use the \function{maketrans()} helper function in the \refmodule{string} module to create a translation table. +For string objects, set the \var{table} argument to \code{None} +for translations that only delete characters: +\begin{verbatim}

+\end{verbatim} +\versionadded[Support for a \code{None} \var{table} argument]{2.6}

For Unicode objects, the \method{translate()} method does not accept the optional \var{deletechars} argument. Instead, it

Modified: python/trunk/Doc/lib/libstring.tex

--- python/trunk/Doc/lib/libstring.tex (original) +++ python/trunk/Doc/lib/libstring.tex Thu Apr 12 06:10:00 2007 @@ -419,7 +419,8 @@ Delete all characters from \var{s} that are in \var{deletechars} (if present), and then translate the characters using \var{table}, which must be a 256-character string giving the translation for each

\begin{funcdesc}{upper}{s}

Modified: python/trunk/Lib/string.py

--- python/trunk/Lib/string.py (original) +++ python/trunk/Lib/string.py Thu Apr 12 06:10:00 2007 @@ -487,7 +487,7 @@ deletions argument is not allowed for Unicode strings.

 """

Modified: python/trunk/Lib/test/string_tests.py

--- python/trunk/Lib/test/string_tests.py (original) +++ python/trunk/Lib/test/string_tests.py Thu Apr 12 06:10:00 2007 @@ -1096,6 +1096,9 @@ self.checkequal('Abc', 'abc', 'translate', table) self.checkequal('xyz', 'xyz', 'translate', table) self.checkequal('yz', 'xyz', 'translate', table, 'x')

Modified: python/trunk/Misc/NEWS

--- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Apr 12 06:10:00 2007 @@ -14,6 +14,10 @@

+- Request #1193128: str.translate() now allows a None argument for

Modified: python/trunk/Objects/stringobject.c

--- python/trunk/Objects/stringobject.c (original) +++ python/trunk/Objects/stringobject.c Thu Apr 12 06:10:00 2007 @@ -2344,10 +2344,10 @@ string_translate(PyStringObject *self, PyObject *args) { register char *input, *output; - register const char *table; + const char *table; register Py_ssize_t i, c, changed = 0; PyObject input_obj = (PyObject)self; - const char *table1, *output_start, *del_table=NULL; + const char *output_start, *del_table=NULL; Py_ssize_t inlen, tablen, dellen = 0; PyObject *result; int trans_table[256]; @@ -2358,9 +2358,13 @@ return NULL;

 if (PyString_Check(tableobj)) {

@@ -2374,7 +2378,7 @@ return PyUnicode_Translate((PyObject *)self, tableobj, NULL); } #endif - else if (PyObject_AsCharBuffer(tableobj, &table1, &tablen)) + else if (PyObject_AsCharBuffer(tableobj, &table, &tablen)) return NULL;

 if (tablen != 256) {

@@ -2403,7 +2407,6 @@ dellen = 0; }

@@ -2411,7 +2414,7 @@ output_start = output = PyString_AsString(result); input = PyString_AS_STRING(input_obj);

@@ -2425,8 +2428,13 @@ return input_obj; }



More information about the Python-checkins mailing list