clean up some docstrings and errors in bytesobject.c

This commit is contained in:
Benjamin Peterson 2008-05-27 00:36:20 +00:00
parent 74c71f5a62
commit 4116f36967
1 changed files with 18 additions and 21 deletions

View File

@ -1,7 +1,4 @@
/* String object implementation */ /* bytes object implementation */
/* XXX This is now called 'bytes' as far as the user is concerned.
Many docstrings and error messages need to be cleaned up. */
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
@ -116,7 +113,7 @@ PyBytes_FromString(const char *str)
size = strlen(str); size = strlen(str);
if (size > PY_SSIZE_T_MAX) { if (size > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"string is too long for a Python string"); "byte string is too long");
return NULL; return NULL;
} }
if (size == 0 && (op = nullstring) != NULL) { if (size == 0 && (op = nullstring) != NULL) {
@ -735,7 +732,7 @@ string_repeat(register PyBytesObject *a, register Py_ssize_t n)
size = Py_SIZE(a) * n; size = Py_SIZE(a) * n;
if (n && size / n != Py_SIZE(a)) { if (n && size / n != Py_SIZE(a)) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"repeated string is too long"); "repeated bytes are too long");
return NULL; return NULL;
} }
if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) { if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) {
@ -745,7 +742,7 @@ string_repeat(register PyBytesObject *a, register Py_ssize_t n)
nbytes = (size_t)size; nbytes = (size_t)size;
if (nbytes + sizeof(PyBytesObject) <= nbytes) { if (nbytes + sizeof(PyBytesObject) <= nbytes) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"repeated string is too long"); "repeated bytes are too long");
return NULL; return NULL;
} }
op = (PyBytesObject *) op = (PyBytesObject *)
@ -799,7 +796,7 @@ static PyObject *
string_item(PyBytesObject *a, register Py_ssize_t i) string_item(PyBytesObject *a, register Py_ssize_t i)
{ {
if (i < 0 || i >= Py_SIZE(a)) { if (i < 0 || i >= Py_SIZE(a)) {
PyErr_SetString(PyExc_IndexError, "string index out of range"); PyErr_SetString(PyExc_IndexError, "index out of range");
return NULL; return NULL;
} }
return PyLong_FromLong((unsigned char)a->ob_sval[i]); return PyLong_FromLong((unsigned char)a->ob_sval[i]);
@ -908,7 +905,7 @@ string_subscript(PyBytesObject* self, PyObject* item)
i += PyBytes_GET_SIZE(self); i += PyBytes_GET_SIZE(self);
if (i < 0 || i >= PyBytes_GET_SIZE(self)) { if (i < 0 || i >= PyBytes_GET_SIZE(self)) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(PyExc_IndexError,
"string index out of range"); "index out of range");
return NULL; return NULL;
} }
return PyLong_FromLong((unsigned char)self->ob_sval[i]); return PyLong_FromLong((unsigned char)self->ob_sval[i]);
@ -958,7 +955,7 @@ string_subscript(PyBytesObject* self, PyObject* item)
} }
else { else {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"string indices must be integers, not %.200s", "byte indices must be integers, not %.200s",
Py_TYPE(item)->tp_name); Py_TYPE(item)->tp_name);
return NULL; return NULL;
} }
@ -1348,7 +1345,7 @@ rsplit_char(PyBytesObject *self, Py_ssize_t len, char ch, Py_ssize_t maxcount)
} }
PyDoc_STRVAR(rsplit__doc__, PyDoc_STRVAR(rsplit__doc__,
"B.rsplit([sep[, maxsplit]]) -> list of strings\n\ "B.rsplit([sep[, maxsplit]]) -> list of bytes\n\
\n\ \n\
Return a list of the sections in B, using sep as the delimiter,\n\ Return a list of the sections in B, using sep as the delimiter,\n\
starting at the end of B and working to the front.\n\ starting at the end of B and working to the front.\n\
@ -1482,7 +1479,7 @@ string_join(PyObject *self, PyObject *orig)
sz += seplen; sz += seplen;
if (sz < old_sz || sz > PY_SSIZE_T_MAX) { if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"join() result is too long for a Python string"); "join() result is too long for bytes");
Py_DECREF(seq); Py_DECREF(seq);
return NULL; return NULL;
} }
@ -2091,13 +2088,13 @@ replace_interleave(PyBytesObject *self,
product = count * to_len; product = count * to_len;
if (product / to_len != count) { if (product / to_len != count) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacement bytes are too long");
return NULL; return NULL;
} }
result_len = product + self_len; result_len = product + self_len;
if (result_len < 0) { if (result_len < 0) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacement bytes are too long");
return NULL; return NULL;
} }
@ -2346,13 +2343,13 @@ replace_single_character(PyBytesObject *self,
product = count * (to_len-1); product = count * (to_len-1);
if (product / (to_len-1) != count) { if (product / (to_len-1) != count) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacement bytes are too long");
return NULL; return NULL;
} }
result_len = self_len + product; result_len = self_len + product;
if (result_len < 0) { if (result_len < 0) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacment bytes are too long");
return NULL; return NULL;
} }
@ -2416,13 +2413,13 @@ replace_substring(PyBytesObject *self,
product = count * (to_len-from_len); product = count * (to_len-from_len);
if (product / (to_len-from_len) != count) { if (product / (to_len-from_len) != count) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacement bytes are too long");
return NULL; return NULL;
} }
result_len = self_len + product; result_len = self_len + product;
if (result_len < 0) { if (result_len < 0) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"replace string is too long"); "replacement bytes are too long");
return NULL; return NULL;
} }
@ -2620,7 +2617,7 @@ PyDoc_STRVAR(startswith__doc__,
Return True if B starts with the specified prefix, False otherwise.\n\ Return True if B starts with the specified prefix, False otherwise.\n\
With optional start, test B beginning at that position.\n\ With optional start, test B beginning at that position.\n\
With optional end, stop comparing B at that position.\n\ With optional end, stop comparing B at that position.\n\
prefix can also be a tuple of strings to try."); prefix can also be a tuple of bytes to try.");
static PyObject * static PyObject *
string_startswith(PyBytesObject *self, PyObject *args) string_startswith(PyBytesObject *self, PyObject *args)
@ -2661,7 +2658,7 @@ PyDoc_STRVAR(endswith__doc__,
Return True if B ends with the specified suffix, False otherwise.\n\ Return True if B ends with the specified suffix, False otherwise.\n\
With optional start, test B beginning at that position.\n\ With optional start, test B beginning at that position.\n\
With optional end, stop comparing B at that position.\n\ With optional end, stop comparing B at that position.\n\
suffix can also be a tuple of strings to try."); suffix can also be a tuple of bytes to try.");
static PyObject * static PyObject *
string_endswith(PyBytesObject *self, PyObject *args) string_endswith(PyBytesObject *self, PyObject *args)
@ -3310,7 +3307,7 @@ PyBytes_Fini(void)
nullstring = NULL; nullstring = NULL;
} }
/*********************** Str Iterator ****************************/ /*********************** Bytes Iterator ****************************/
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD