[Python-checkins] r46380 - in python/trunk: Doc/lib/libstdtypes.tex Lib/test/string_tests.py Objects/unicodeobject.c

fredrik.lundh python-checkins at python.org
Fri May 26 20:24:17 CEST 2006


Author: fredrik.lundh
Date: Fri May 26 20:24:15 2006
New Revision: 46380

Modified:
   python/trunk/Doc/lib/libstdtypes.tex
   python/trunk/Lib/test/string_tests.py
   python/trunk/Objects/unicodeobject.c
Log:
needspeed: rpartition documentation, tests, and a bug fixes.

feel free to add more tests and improve the documentation.



Modified: python/trunk/Doc/lib/libstdtypes.tex
==============================================================================
--- python/trunk/Doc/lib/libstdtypes.tex	(original)
+++ python/trunk/Doc/lib/libstdtypes.tex	Fri May 26 20:24:15 2006
@@ -763,6 +763,15 @@
 \versionchanged[Support for the \var{fillchar} argument]{2.4}
 \end{methoddesc}
 
+\begin{methoddesc}[string]{rpartition}{sep}
+Split the string at the last occurrence of \var{sep}, and return
+a 3-tuple containing the part before the separator, the separator
+itself, and the part after the separator.  If the separator is not
+found, return a 3-tuple containing the string itself, followed by
+two empty strings.
+\versionadded{2.5}
+\end{methoddesc}
+
 \begin{methoddesc}[string]{rsplit}{\optional{sep \optional{,maxsplit}}}
 Return a list of the words in the string, using \var{sep} as the
 delimiter string.  If \var{maxsplit} is given, at most \var{maxsplit}

Modified: python/trunk/Lib/test/string_tests.py
==============================================================================
--- python/trunk/Lib/test/string_tests.py	(original)
+++ python/trunk/Lib/test/string_tests.py	Fri May 26 20:24:15 2006
@@ -999,8 +999,8 @@
 
     def test_partition(self):
 
-        self.checkequal(('this', ' is ', 'the partition method'),
-            'this is the partition method', 'partition', ' is ')
+        self.checkequal(('this is the par', 'ti', 'tion method'),
+            'this is the partition method', 'partition', 'ti')
 
         # from raymond's original specification
         S = 'http://www.python.org'
@@ -1012,6 +1012,21 @@
         self.checkraises(ValueError, S, 'partition', '')
         self.checkraises(TypeError, S, 'partition', None)
 
+    def test_rpartition(self):
+
+        self.checkequal(('this is the rparti', 'ti', 'on method'),
+            'this is the rpartition method', 'rpartition', 'ti')
+
+        # from raymond's original specification
+        S = 'http://www.python.org'
+        self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://')
+        self.checkequal(('http://www.python.org', '', ''), S, 'rpartition', '?')
+        self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://')
+        self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org')
+
+        self.checkraises(ValueError, S, 'rpartition', '')
+        self.checkraises(TypeError, S, 'rpartition', None)
+
 
 class MixinStrStringUserStringTest:
     # Additional tests for 8bit strings, i.e. str, UserString and

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Fri May 26 20:24:15 2006
@@ -3861,8 +3861,8 @@
 Py_LOCAL(int)
 STRINGLIB_CMP(const Py_UNICODE* str, const Py_UNICODE* other, Py_ssize_t len)
 {
-    if (str[0] == other[0])
-        return 0;
+    if (str[0] != other[0])
+        return 1;
     return memcmp((void*) str, (void*) other, len * sizeof(Py_UNICODE));
 }
 


More information about the Python-checkins mailing list