[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.122,2.123 fileobject.c,2.153,2.154 intobject.c,2.80,2.81 object.c,2.169,2.170 stringobject.c,2.153,2.154 unicodeobject.c,2.133,2.134

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 03 Apr 2002 14:41:53 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31419/Objects

Modified Files:
	dictobject.c fileobject.c intobject.c object.c stringobject.c 
	unicodeobject.c 
Log Message:
Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.



Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.122
retrieving revision 2.123
diff -C2 -d -r2.122 -r2.123
*** dictobject.c	29 Mar 2002 03:29:07 -0000	2.122
--- dictobject.c	3 Apr 2002 22:41:51 -0000	2.123
***************
*** 1430,1434 ****
  	}
  	ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
! 	return PyInt_FromLong(ok);
  }
  
--- 1430,1434 ----
  	}
  	ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
! 	return PyBool_FromLong(ok);
  }
  

Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.153
retrieving revision 2.154
diff -C2 -d -r2.153 -r2.154
*** fileobject.c	1 Apr 2002 00:08:59 -0000	2.153
--- fileobject.c	3 Apr 2002 22:41:51 -0000	2.154
***************
*** 1445,1449 ****
  "close() -> None or (perhaps) an integer.  Close the file.\n"
  "\n"
! "Sets data attribute .closed to true.  A closed file cannot be used for\n"
  "further I/O operations.  close() may be called more than once without\n"
  "error.  Some kinds of file objects (for example, opened by popen())\n"
--- 1445,1449 ----
  "close() -> None or (perhaps) an integer.  Close the file.\n"
  "\n"
! "Sets data attribute .closed to True.  A closed file cannot be used for\n"
  "further I/O operations.  close() may be called more than once without\n"
  "error.  Some kinds of file objects (for example, opened by popen())\n"
***************
*** 1489,1497 ****
  get_closed(PyFileObject *f, void *closure)
  {
! 	return PyInt_FromLong((long)(f->f_fp == 0));
  }
  
  static PyGetSetDef file_getsetlist[] = {
! 	{"closed", (getter)get_closed, NULL, "flag set if the file is closed"},
  	{0},
  };
--- 1489,1497 ----
  get_closed(PyFileObject *f, void *closure)
  {
! 	return PyBool_FromLong((long)(f->f_fp == 0));
  }
  
  static PyGetSetDef file_getsetlist[] = {
! 	{"closed", (getter)get_closed, NULL, "True if the file is closed"},
  	{0},
  };

Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.80
retrieving revision 2.81
diff -C2 -d -r2.80 -r2.81
*** intobject.c	1 Feb 2002 15:34:10 -0000	2.80
--- intobject.c	3 Apr 2002 22:41:51 -0000	2.81
***************
*** 11,26 ****
  }
  
- /* Standard Booleans */
- 
- PyIntObject _Py_ZeroStruct = {
- 	PyObject_HEAD_INIT(&PyInt_Type)
- 	0
- };
- 
- PyIntObject _Py_TrueStruct = {
- 	PyObject_HEAD_INIT(&PyInt_Type)
- 	1
- };
- 
  /* Return 1 if exception raised, 0 if caller should retry using longs */
  static int
--- 11,14 ----

Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.169
retrieving revision 2.170
diff -C2 -d -r2.169 -r2.170
*** object.c	29 Mar 2002 03:05:54 -0000	2.169
--- object.c	3 Apr 2002 22:41:51 -0000	2.170
***************
*** 1764,1767 ****
--- 1764,1770 ----
  		Py_FatalError("Can't initialize 'type'");
  
+ 	if (PyType_Ready(&PyBool_Type) < 0)
+ 		Py_FatalError("Can't initialize 'bool'");
+ 
  	if (PyType_Ready(&PyList_Type) < 0)
  		Py_FatalError("Can't initialize 'list'");

Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.153
retrieving revision 2.154
diff -C2 -d -r2.153 -r2.154
*** stringobject.c	30 Mar 2002 10:06:07 -0000	2.153
--- stringobject.c	3 Apr 2002 22:41:51 -0000	2.154
***************
*** 2001,2007 ****
  
  static char startswith__doc__[] =
! "S.startswith(prefix[, start[, end]]) -> int\n\
  \n\
! Return 1 if S starts with the specified prefix, otherwise return 0.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
--- 2001,2007 ----
  
  static char startswith__doc__[] =
! "S.startswith(prefix[, start[, end]]) -> bool\n\
  \n\
! Return True if S starts with the specified prefix, False otherwise.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
***************
*** 2033,2037 ****
  			return NULL;
  		else
! 			return PyInt_FromLong((long) rc);
  	}
  #endif
--- 2033,2037 ----
  			return NULL;
  		else
! 			return PyBool_FromLong((long) rc);
  	}
  #endif
***************
*** 2044,2066 ****
  	 */
  	if (start < 0 || start+plen > len)
! 		return PyInt_FromLong(0);
  
  	if (!memcmp(str+start, prefix, plen)) {
  		/* did the match end after the specified end? */
  		if (end < 0)
! 			return PyInt_FromLong(1);
  		else if (end - start < plen)
! 			return PyInt_FromLong(0);
  		else
! 			return PyInt_FromLong(1);
  	}
! 	else return PyInt_FromLong(0);
  }
  
  
  static char endswith__doc__[] =
! "S.endswith(suffix[, start[, end]]) -> int\n\
  \n\
! Return 1 if S ends with the specified suffix, otherwise return 0.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
--- 2044,2066 ----
  	 */
  	if (start < 0 || start+plen > len)
! 		return PyBool_FromLong(0);
  
  	if (!memcmp(str+start, prefix, plen)) {
  		/* did the match end after the specified end? */
  		if (end < 0)
! 			return PyBool_FromLong(1);
  		else if (end - start < plen)
! 			return PyBool_FromLong(0);
  		else
! 			return PyBool_FromLong(1);
  	}
! 	else return PyBool_FromLong(0);
  }
  
  
  static char endswith__doc__[] =
! "S.endswith(suffix[, start[, end]]) -> bool\n\
  \n\
! Return True if S ends with the specified suffix, False otherwise.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
***************
*** 2093,2097 ****
  			return NULL;
  		else
! 			return PyInt_FromLong((long) rc);
  	}
  #endif
--- 2093,2097 ----
  			return NULL;
  		else
! 			return PyBool_FromLong((long) rc);
  	}
  #endif
***************
*** 2100,2104 ****
  
  	if (start < 0 || start > len || slen > len)
! 		return PyInt_FromLong(0);
  
  	upper = (end >= 0 && end <= len) ? end : len;
--- 2100,2104 ----
  
  	if (start < 0 || start > len || slen > len)
! 		return PyBool_FromLong(0);
  
  	upper = (end >= 0 && end <= len) ? end : len;
***************
*** 2106,2111 ****
  
  	if (upper-lower >= slen && !memcmp(str+lower, suffix, slen))
! 		return PyInt_FromLong(1);
! 	else return PyInt_FromLong(0);
  }
  
--- 2106,2111 ----
  
  	if (upper-lower >= slen && !memcmp(str+lower, suffix, slen))
! 		return PyBool_FromLong(1);
! 	else return PyBool_FromLong(0);
  }
  
***************
*** 2312,2319 ****
  
  static char isspace__doc__[] =
! "S.isspace() -> int\n"
  "\n"
! "Return 1 if there are only whitespace characters in S,\n"
! "0 otherwise.";
  
  static PyObject*
--- 2312,2319 ----
  
  static char isspace__doc__[] =
! "S.isspace() -> bool\n"
  "\n"
! "Return True if there are only whitespace characters in S,\n"
! "False otherwise.";
  
  static PyObject*
***************
*** 2327,2350 ****
      if (PyString_GET_SIZE(self) == 1 &&
  	isspace(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isspace(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  
  static char isalpha__doc__[] =
! "S.isalpha() -> int\n\
  \n\
! Return 1 if  all characters in S are alphabetic\n\
! and there is at least one character in S, 0 otherwise.";
  
  static PyObject*
--- 2327,2350 ----
      if (PyString_GET_SIZE(self) == 1 &&
  	isspace(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isspace(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  
  static char isalpha__doc__[] =
! "S.isalpha() -> bool\n\
  \n\
! Return True if  all characters in S are alphabetic\n\
! and there is at least one character in S, False otherwise.";
  
  static PyObject*
***************
*** 2358,2381 ****
      if (PyString_GET_SIZE(self) == 1 &&
  	isalpha(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isalpha(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  
  static char isalnum__doc__[] =
! "S.isalnum() -> int\n\
  \n\
! Return 1 if  all characters in S are alphanumeric\n\
! and there is at least one character in S, 0 otherwise.";
  
  static PyObject*
--- 2358,2381 ----
      if (PyString_GET_SIZE(self) == 1 &&
  	isalpha(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isalpha(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  
  static char isalnum__doc__[] =
! "S.isalnum() -> bool\n\
  \n\
! Return True if  all characters in S are alphanumeric\n\
! and there is at least one character in S, False otherwise.";
  
  static PyObject*
***************
*** 2389,2412 ****
      if (PyString_GET_SIZE(self) == 1 &&
  	isalnum(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isalnum(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  
  static char isdigit__doc__[] =
! "S.isdigit() -> int\n\
  \n\
! Return 1 if there are only digit characters in S,\n\
! 0 otherwise.";
  
  static PyObject*
--- 2389,2412 ----
      if (PyString_GET_SIZE(self) == 1 &&
  	isalnum(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isalnum(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  
  static char isdigit__doc__[] =
! "S.isdigit() -> bool\n\
  \n\
! Return True if there are only digit characters in S,\n\
! False otherwise.";
  
  static PyObject*
***************
*** 2420,2443 ****
      if (PyString_GET_SIZE(self) == 1 &&
  	isdigit(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isdigit(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  
  static char islower__doc__[] =
! "S.islower() -> int\n\
  \n\
! Return 1 if  all cased characters in S are lowercase and there is\n\
! at least one cased character in S, 0 otherwise.";
  
  static PyObject*
--- 2420,2443 ----
      if (PyString_GET_SIZE(self) == 1 &&
  	isdigit(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!isdigit(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  
  static char islower__doc__[] =
! "S.islower() -> bool\n\
  \n\
! Return True if all cased characters in S are lowercase and there is\n\
! at least one cased character in S, False otherwise.";
  
  static PyObject*
***************
*** 2451,2459 ****
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyInt_FromLong(islower(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
--- 2451,2459 ----
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyBool_FromLong(islower(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
***************
*** 2461,2477 ****
      for (; p < e; p++) {
  	if (isupper(*p))
! 	    return PyInt_FromLong(0);
  	else if (!cased && islower(*p))
  	    cased = 1;
      }
!     return PyInt_FromLong(cased);
  }
  
  
  static char isupper__doc__[] =
! "S.isupper() -> int\n\
  \n\
! Return 1 if  all cased characters in S are uppercase and there is\n\
! at least one cased character in S, 0 otherwise.";
  
  static PyObject*
--- 2461,2477 ----
      for (; p < e; p++) {
  	if (isupper(*p))
! 	    return PyBool_FromLong(0);
  	else if (!cased && islower(*p))
  	    cased = 1;
      }
!     return PyBool_FromLong(cased);
  }
  
  
  static char isupper__doc__[] =
! "S.isupper() -> bool\n\
  \n\
! Return True if  all cased characters in S are uppercase and there is\n\
! at least one cased character in S, False otherwise.";
  
  static PyObject*
***************
*** 2485,2493 ****
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyInt_FromLong(isupper(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
--- 2485,2493 ----
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyBool_FromLong(isupper(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
***************
*** 2495,2512 ****
      for (; p < e; p++) {
  	if (islower(*p))
! 	    return PyInt_FromLong(0);
  	else if (!cased && isupper(*p))
  	    cased = 1;
      }
!     return PyInt_FromLong(cased);
  }
  
  
  static char istitle__doc__[] =
! "S.istitle() -> int\n\
  \n\
! Return 1 if S is a titlecased string, i.e. uppercase characters\n\
  may only follow uncased characters and lowercase characters only cased\n\
! ones. Return 0 otherwise.";
  
  static PyObject*
--- 2495,2512 ----
      for (; p < e; p++) {
  	if (islower(*p))
! 	    return PyBool_FromLong(0);
  	else if (!cased && isupper(*p))
  	    cased = 1;
      }
!     return PyBool_FromLong(cased);
  }
  
  
  static char istitle__doc__[] =
! "S.istitle() -> bool\n\
  \n\
! Return True if S is a titlecased string, i.e. uppercase characters\n\
  may only follow uncased characters and lowercase characters only cased\n\
! ones. Return False otherwise.";
  
  static PyObject*
***************
*** 2520,2528 ****
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyInt_FromLong(isupper(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
--- 2520,2528 ----
      /* Shortcut for single character strings */
      if (PyString_GET_SIZE(self) == 1)
! 	return PyBool_FromLong(isupper(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyString_GET_SIZE(self);
***************
*** 2534,2538 ****
  	if (isupper(ch)) {
  	    if (previous_is_cased)
! 		return PyInt_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
--- 2534,2538 ----
  	if (isupper(ch)) {
  	    if (previous_is_cased)
! 		return PyBool_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
***************
*** 2540,2544 ****
  	else if (islower(ch)) {
  	    if (!previous_is_cased)
! 		return PyInt_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
--- 2540,2544 ----
  	else if (islower(ch)) {
  	    if (!previous_is_cased)
! 		return PyBool_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
***************
*** 2547,2551 ****
  	    previous_is_cased = 0;
      }
!     return PyInt_FromLong(cased);
  }
  
--- 2547,2551 ----
  	    previous_is_cased = 0;
      }
!     return PyBool_FromLong(cased);
  }
  

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.133
retrieving revision 2.134
diff -C2 -d -r2.133 -r2.134
*** unicodeobject.c	25 Mar 2002 11:16:18 -0000	2.133
--- unicodeobject.c	3 Apr 2002 22:41:51 -0000	2.134
***************
*** 4110,4117 ****
  
  static char islower__doc__[] =
! "S.islower() -> int\n\
  \n\
! Return 1 if  all cased characters in S are lowercase and there is\n\
! at least one cased character in S, 0 otherwise.";
  
  static PyObject*
--- 4110,4117 ----
  
  static char islower__doc__[] =
! "S.islower() -> bool\n\
  \n\
! Return True if all cased characters in S are lowercase and there is\n\
! at least one cased character in S, False otherwise.";
  
  static PyObject*
***************
*** 4124,4132 ****
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyInt_FromLong(Py_UNICODE_ISLOWER(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
--- 4124,4132 ----
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyBool_FromLong(Py_UNICODE_ISLOWER(*p));
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
***************
*** 4136,4151 ****
  	
  	if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch))
! 	    return PyInt_FromLong(0);
  	else if (!cased && Py_UNICODE_ISLOWER(ch))
  	    cased = 1;
      }
!     return PyInt_FromLong(cased);
  }
  
  static char isupper__doc__[] =
! "S.isupper() -> int\n\
  \n\
! Return 1 if  all cased characters in S are uppercase and there is\n\
! at least one cased character in S, 0 otherwise.";
  
  static PyObject*
--- 4136,4151 ----
  	
  	if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch))
! 	    return PyBool_FromLong(0);
  	else if (!cased && Py_UNICODE_ISLOWER(ch))
  	    cased = 1;
      }
!     return PyBool_FromLong(cased);
  }
  
  static char isupper__doc__[] =
! "S.isupper() -> bool\n\
  \n\
! Return True if  all cased characters in S are uppercase and there is\n\
! at least one cased character in S, False otherwise.";
  
  static PyObject*
***************
*** 4158,4166 ****
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyInt_FromLong(Py_UNICODE_ISUPPER(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
--- 4158,4166 ----
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyBool_FromLong(Py_UNICODE_ISUPPER(*p) != 0);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
***************
*** 4170,4186 ****
  	
  	if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch))
! 	    return PyInt_FromLong(0);
  	else if (!cased && Py_UNICODE_ISUPPER(ch))
  	    cased = 1;
      }
!     return PyInt_FromLong(cased);
  }
  
  static char istitle__doc__[] =
! "S.istitle() -> int\n\
  \n\
! Return 1 if S is a titlecased string, i.e. upper- and titlecase characters\n\
! may only follow uncased characters and lowercase characters only cased\n\
! ones. Return 0 otherwise.";
  
  static PyObject*
--- 4170,4186 ----
  	
  	if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch))
! 	    return PyBool_FromLong(0);
  	else if (!cased && Py_UNICODE_ISUPPER(ch))
  	    cased = 1;
      }
!     return PyBool_FromLong(cased);
  }
  
  static char istitle__doc__[] =
! "S.istitle() -> bool\n\
  \n\
! Return True if S is a titlecased string, i.e. upper- and titlecase\n\
! characters may only follow uncased characters and lowercase characters\n\
! only cased ones. Return False otherwise.";
  
  static PyObject*
***************
*** 4193,4202 ****
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyInt_FromLong((Py_UNICODE_ISTITLE(*p) != 0) ||
! 			      (Py_UNICODE_ISUPPER(*p) != 0));
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
--- 4193,4202 ----
      /* Shortcut for single character strings */
      if (PyUnicode_GET_SIZE(self) == 1)
! 	return PyBool_FromLong((Py_UNICODE_ISTITLE(*p) != 0) ||
! 			       (Py_UNICODE_ISUPPER(*p) != 0));
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
***************
*** 4208,4212 ****
  	if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) {
  	    if (previous_is_cased)
! 		return PyInt_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
--- 4208,4212 ----
  	if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) {
  	    if (previous_is_cased)
! 		return PyBool_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
***************
*** 4214,4218 ****
  	else if (Py_UNICODE_ISLOWER(ch)) {
  	    if (!previous_is_cased)
! 		return PyInt_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
--- 4214,4218 ----
  	else if (Py_UNICODE_ISLOWER(ch)) {
  	    if (!previous_is_cased)
! 		return PyBool_FromLong(0);
  	    previous_is_cased = 1;
  	    cased = 1;
***************
*** 4221,4232 ****
  	    previous_is_cased = 0;
      }
!     return PyInt_FromLong(cased);
  }
  
  static char isspace__doc__[] =
! "S.isspace() -> int\n\
  \n\
! Return 1 if there are only whitespace characters in S,\n\
! 0 otherwise.";
  
  static PyObject*
--- 4221,4232 ----
  	    previous_is_cased = 0;
      }
!     return PyBool_FromLong(cased);
  }
  
  static char isspace__doc__[] =
! "S.isspace() -> bool\n\
  \n\
! Return True if there are only whitespace characters in S,\n\
! False otherwise.";
  
  static PyObject*
***************
*** 4239,4261 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISSPACE(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISSPACE(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  static char isalpha__doc__[] =
! "S.isalpha() -> int\n\
  \n\
! Return 1 if  all characters in S are alphabetic\n\
! and there is at least one character in S, 0 otherwise.";
  
  static PyObject*
--- 4239,4261 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISSPACE(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISSPACE(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  static char isalpha__doc__[] =
! "S.isalpha() -> bool\n\
  \n\
! Return True if  all characters in S are alphabetic\n\
! and there is at least one character in S, False otherwise.";
  
  static PyObject*
***************
*** 4268,4290 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISALPHA(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISALPHA(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  static char isalnum__doc__[] =
! "S.isalnum() -> int\n\
  \n\
! Return 1 if  all characters in S are alphanumeric\n\
! and there is at least one character in S, 0 otherwise.";
  
  static PyObject*
--- 4268,4290 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISALPHA(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISALPHA(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  static char isalnum__doc__[] =
! "S.isalnum() -> bool\n\
  \n\
! Return True if  all characters in S are alphanumeric\n\
! and there is at least one character in S, False otherwise.";
  
  static PyObject*
***************
*** 4297,4319 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISALNUM(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISALNUM(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  static char isdecimal__doc__[] =
! "S.isdecimal() -> int\n\
  \n\
! Return 1 if there are only decimal characters in S,\n\
! 0 otherwise.";
  
  static PyObject*
--- 4297,4319 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISALNUM(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISALNUM(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  static char isdecimal__doc__[] =
! "S.isdecimal() -> bool\n\
  \n\
! Return True if there are only decimal characters in S,\n\
! False otherwise.";
  
  static PyObject*
***************
*** 4326,4348 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISDECIMAL(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISDECIMAL(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  static char isdigit__doc__[] =
! "S.isdigit() -> int\n\
  \n\
! Return 1 if there are only digit characters in S,\n\
! 0 otherwise.";
  
  static PyObject*
--- 4326,4348 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISDECIMAL(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISDECIMAL(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  static char isdigit__doc__[] =
! "S.isdigit() -> bool\n\
  \n\
! Return True if there are only digit characters in S,\n\
! False otherwise.";
  
  static PyObject*
***************
*** 4355,4377 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISDIGIT(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISDIGIT(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
  static char isnumeric__doc__[] =
! "S.isnumeric() -> int\n\
  \n\
! Return 1 if there are only numeric characters in S,\n\
! 0 otherwise.";
  
  static PyObject*
--- 4355,4377 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISDIGIT(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISDIGIT(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
  static char isnumeric__doc__[] =
! "S.isnumeric() -> bool\n\
  \n\
! Return True if there are only numeric characters in S,\n\
! False otherwise.";
  
  static PyObject*
***************
*** 4384,4399 ****
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISNUMERIC(*p))
! 	return PyInt_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyInt_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISNUMERIC(*p))
! 	    return PyInt_FromLong(0);
      }
!     return PyInt_FromLong(1);
  }
  
--- 4384,4399 ----
      if (PyUnicode_GET_SIZE(self) == 1 &&
  	Py_UNICODE_ISNUMERIC(*p))
! 	return PyBool_FromLong(1);
  
      /* Special case for empty strings */
      if (PyString_GET_SIZE(self) == 0)
! 	return PyBool_FromLong(0);
  
      e = p + PyUnicode_GET_SIZE(self);
      for (; p < e; p++) {
  	if (!Py_UNICODE_ISNUMERIC(*p))
! 	    return PyBool_FromLong(0);
      }
!     return PyBool_FromLong(1);
  }
  
***************
*** 4863,4869 ****
  
  static char startswith__doc__[] =
! "S.startswith(prefix[, start[, end]]) -> int\n\
  \n\
! Return 1 if S starts with the specified prefix, otherwise return 0.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
--- 4863,4869 ----
  
  static char startswith__doc__[] =
! "S.startswith(prefix[, start[, end]]) -> bool\n\
  \n\
! Return True if S starts with the specified prefix, False otherwise.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
***************
*** 4886,4890 ****
  	return NULL;
  
!     result = PyInt_FromLong(tailmatch(self, substring, start, end, -1));
  
      Py_DECREF(substring);
--- 4886,4890 ----
  	return NULL;
  
!     result = PyBool_FromLong(tailmatch(self, substring, start, end, -1));
  
      Py_DECREF(substring);
***************
*** 4894,4900 ****
  
  static char endswith__doc__[] =
! "S.endswith(suffix[, start[, end]]) -> int\n\
  \n\
! Return 1 if S ends with the specified suffix, otherwise return 0.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
--- 4894,4900 ----
  
  static char endswith__doc__[] =
! "S.endswith(suffix[, start[, end]]) -> bool\n\
  \n\
! Return True if S ends with the specified suffix, False otherwise.  With\n\
  optional start, test S beginning at that position.  With optional end, stop\n\
  comparing S at that position.";
***************
*** 4917,4921 ****
  	return NULL;
  
!     result = PyInt_FromLong(tailmatch(self, substring, start, end, +1));
  
      Py_DECREF(substring);
--- 4917,4921 ----
  	return NULL;
  
!     result = PyBool_FromLong(tailmatch(self, substring, start, end, +1));
  
      Py_DECREF(substring);