]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 11 Apr 2003 18:21:22 +0000 (18:21 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 11 Apr 2003 18:21:22 +0000 (18:21 +0000)
Fix SF bug #697220, string.strip implementation/doc mismatch

Attempt to make all the various string/unicode *strip methods the same.
 * Doc - add doc for when functions were added
 * UserString
 * string/unicode object methods
 * string module functions
'chars' is used for the last parameter everywhere.

Doc/lib/libstring.tex
Lib/UserString.py
Lib/string.py
Misc/NEWS
Objects/stringobject.c
Objects/unicodeobject.c

index d84226c5f2348d2997cf09783cc4144dae6fd588..7be55c2933a335129943c95ed00f5718ca02be01 100644 (file)
@@ -243,6 +243,8 @@ Return a copy of the string with leading characters removed.  If
 removed.  If given and not \code{None}, \var{chars} must be a string;
 the characters in the string will be stripped from the beginning of
 the string this method is called on.
+\versionchanged[The \var{chars} parameter was added.  The \var{chars} 
+parameter cannot be passed in earlier 2.2 versions]{2.2.3}
 \end{funcdesc}
 
 \begin{funcdesc}{rstrip}{s\optional{, chars}}
@@ -251,6 +253,8 @@ Return a copy of the string with trailing characters removed.  If
 removed.  If given and not \code{None}, \var{chars} must be a string;
 the characters in the string will be stripped from the end of the
 string this method is called on.
+\versionchanged[The \var{chars} parameter was added.  The \var{chars} 
+parameter cannot be passed in earlier 2.2 versions]{2.2.3}
 \end{funcdesc}
 
 \begin{funcdesc}{strip}{s\optional{, chars}}
@@ -260,7 +264,7 @@ characters are removed.  If given and not \code{None}, \var{chars}
 must be a string; the characters in the string will be stripped from
 the both ends of the string this method is called on.
 \versionchanged[The \var{chars} parameter was added.  The \var{chars} 
-parameter cannot be passed in 2.2 or 2.2.1]{2.2.2}
+parameter cannot be passed in earlier 2.2 versions]{2.2.3}
 \end{funcdesc}
 
 \begin{funcdesc}{swapcase}{s}
index 292e85242d8a8424fa276ffa79bf5e14542dc2ee..2d8feb29a77046fb4f3c1f462ba42231f9012c24 100755 (executable)
@@ -108,7 +108,7 @@ class UserString:
     def join(self, seq): return self.data.join(seq)
     def ljust(self, width): return self.__class__(self.data.ljust(width))
     def lower(self): return self.__class__(self.data.lower())
-    def lstrip(self, sep=None): return self.__class__(self.data.lstrip(sep))
+    def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars))
     def replace(self, old, new, maxsplit=-1):
         return self.__class__(self.data.replace(old, new, maxsplit))
     def rfind(self, sub, start=0, end=sys.maxint):
@@ -116,13 +116,13 @@ class UserString:
     def rindex(self, sub, start=0, end=sys.maxint):
         return self.data.rindex(sub, start, end)
     def rjust(self, width): return self.__class__(self.data.rjust(width))
-    def rstrip(self, sep=None): return self.__class__(self.data.rstrip(sep))
+    def rstrip(self, chars=None): return self.__class__(self.data.rstrip(chars))
     def split(self, sep=None, maxsplit=-1):
         return self.data.split(sep, maxsplit)
     def splitlines(self, keepends=0): return self.data.splitlines(keepends)
     def startswith(self, prefix, start=0, end=sys.maxint):
         return self.data.startswith(prefix, start, end)
-    def strip(self, sep=None): return self.__class__(self.data.strip(sep))
+    def strip(self, chars=None): return self.__class__(self.data.strip(chars))
     def swapcase(self): return self.__class__(self.data.swapcase())
     def title(self): return self.__class__(self.data.title())
     def translate(self, *args):
index 5aec4d5571e7a67824e402eab5911dbf2bfa1bb7..c9d86a23a179f41e272cce02bb207157fb14e26a 100644 (file)
@@ -78,30 +78,33 @@ def strip(s, chars=None):
 
     Return a copy of the string s with leading and trailing
     whitespace removed.
-    If chars is given and not None, remove characters in sep instead.
+    If chars is given and not None, remove characters in chars instead.
     If chars is unicode, S will be converted to unicode before stripping.
 
     """
     return s.strip(chars)
 
 # Strip leading tabs and spaces
-def lstrip(s):
-    """lstrip(s) -> string
+def lstrip(s, chars=None):
+    """lstrip(s [,chars]) -> string
 
     Return a copy of the string s with leading whitespace removed.
+    If chars is given and not None, remove characters in chars instead.
+    If chars is unicode, S will be converted to unicode before stripping.
 
     """
-    return s.lstrip()
+    return s.lstrip(chars)
 
 # Strip trailing tabs and spaces
-def rstrip(s):
-    """rstrip(s) -> string
+def rstrip(s, chars=None):
+    """rstrip(s [,chars]) -> string
 
-    Return a copy of the string s with trailing whitespace
-    removed.
+    Return a copy of the string s with trailing whitespace removed.
+    If chars is given and not None, remove characters in chars instead.
+    If chars is unicode, S will be converted to unicode before stripping.
 
     """
-    return s.rstrip()
+    return s.rstrip(chars)
 
 
 # Split a string into a list of space/tab-separated words
index 485b17da96bfcd7dedbfd82c00da7e97734573ac..b22a277c95052d4f743234d5455c93dc5a6494e5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,11 @@ What's New in Python 2.2.3 ?
 Release date: XX-XXX-2003
 ============================
 
+- Make all the strip, lstrip, rstrip functions/methods on
+  string/unicode/UserString consistent by adding and/or
+  documenting the chars parameter.  The chars parameter
+  specifies which characters to strip.
+
 - Some horridly obscure problems were fixed involving interaction
   between garbage collection and classes with "ambitious" getattr hooks.
   If a class instance didn't have a __del__ method, but did have a
index 3173f750c0681391514074905bdb963d027d907e..a636aab294e433c2e27b2b99c861935cfb5368dc 100644 (file)
@@ -1523,12 +1523,12 @@ do_argstrip(PyStringObject *self, int striptype, PyObject *args)
 
 
 static char strip__doc__[] =
-"S.strip([sep]) -> string or unicode\n\
+"S.strip([chars]) -> string or unicode\n\
 \n\
 Return a copy of the string S with leading and trailing\n\
 whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is unicode, S will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is unicode, S will be converted to unicode before stripping";
 
 static PyObject *
 string_strip(PyStringObject *self, PyObject *args)
@@ -1541,11 +1541,11 @@ string_strip(PyStringObject *self, PyObject *args)
 
 
 static char lstrip__doc__[] =
-"S.lstrip([sep]) -> string or unicode\n\
+"S.lstrip([chars]) -> string or unicode\n\
 \n\
 Return a copy of the string S with leading whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is unicode, S will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is unicode, S will be converted to unicode before stripping";
 
 static PyObject *
 string_lstrip(PyStringObject *self, PyObject *args)
@@ -1558,11 +1558,11 @@ string_lstrip(PyStringObject *self, PyObject *args)
 
 
 static char rstrip__doc__[] =
-"S.rstrip([sep]) -> string or unicode\n\
+"S.rstrip([chars]) -> string or unicode\n\
 \n\
 Return a copy of the string S with trailing whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is unicode, S will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is unicode, S will be converted to unicode before stripping";
 
 static PyObject *
 string_rstrip(PyStringObject *self, PyObject *args)
index 1249e0b29c3cf0ff0b744f2bd0440368abf1d688..7ebde3cb9349ad768f6f5a7c22d260759d7da219 100644 (file)
@@ -4569,12 +4569,12 @@ do_argstrip(PyUnicodeObject *self, int striptype, PyObject *args)
 
 
 static char strip__doc__[] =
-"S.strip([sep]) -> unicode\n\
+"S.strip([chars]) -> unicode\n\
 \n\
 Return a copy of the string S with leading and trailing\n\
 whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is a str, it will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is a str, it will be converted to unicode before stripping";
 
 static PyObject *
 unicode_strip(PyUnicodeObject *self, PyObject *args)
@@ -4587,11 +4587,11 @@ unicode_strip(PyUnicodeObject *self, PyObject *args)
 
 
 static char lstrip__doc__[] =
-"S.lstrip([sep]) -> unicode\n\
+"S.lstrip([chars]) -> unicode\n\
 \n\
 Return a copy of the string S with leading whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is a str, it will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is a str, it will be converted to unicode before stripping";
 
 static PyObject *
 unicode_lstrip(PyUnicodeObject *self, PyObject *args)
@@ -4604,11 +4604,11 @@ unicode_lstrip(PyUnicodeObject *self, PyObject *args)
 
 
 static char rstrip__doc__[] =
-"S.rstrip([sep]) -> unicode\n\
+"S.rstrip([chars]) -> unicode\n\
 \n\
 Return a copy of the string S with trailing whitespace removed.\n\
-If sep is given and not None, remove characters in sep instead.\n\
-If sep is a str, it will be converted to unicode before stripping";
+If chars is given and not None, remove characters in chars instead.\n\
+If chars is a str, it will be converted to unicode before stripping";
 
 static PyObject *
 unicode_rstrip(PyUnicodeObject *self, PyObject *args)