mirror of https://github.com/python/cpython.git
Add warnings to the strop module, for to those functions that really
*are* obsolete; three variables and the maketrans() function are not (yet) obsolete. Add a compensating warnings.filterwarnings() call to test_strop.py. Add this to the NEWS.
This commit is contained in:
parent
9cba64318e
commit
2e0a654f6e
|
@ -1,4 +1,6 @@
|
||||||
from test_support import verbose
|
from test_support import verbose
|
||||||
|
import warnings
|
||||||
|
warnings.filterwarnings("ignore", "", DeprecationWarning, __name__)
|
||||||
import strop, sys
|
import strop, sys
|
||||||
|
|
||||||
def test(name, input, output, *args):
|
def test(name, input, output, *args):
|
||||||
|
|
|
@ -87,6 +87,10 @@ Core
|
||||||
|
|
||||||
Library
|
Library
|
||||||
|
|
||||||
|
- strop is now *really* obsolete (this was announced before with 1.6),
|
||||||
|
and issues DeprecationWarning when used (except for the four items
|
||||||
|
that are still imported into string.py).
|
||||||
|
|
||||||
- Cookie.py now sorts key+value pairs by key in output strings.
|
- Cookie.py now sorts key+value pairs by key in output strings.
|
||||||
|
|
||||||
- pprint.isrecursive(object) didn't correctly identify recursive objects.
|
- pprint.isrecursive(object) didn't correctly identify recursive objects.
|
||||||
|
|
|
@ -12,6 +12,10 @@ static char strop_module__doc__[] =
|
||||||
/* XXX This file assumes that the <ctype.h> is*() functions
|
/* XXX This file assumes that the <ctype.h> is*() functions
|
||||||
XXX are defined for all 8-bit characters! */
|
XXX are defined for all 8-bit characters! */
|
||||||
|
|
||||||
|
#define WARN if (PyErr_Warn(PyExc_DeprecationWarning, \
|
||||||
|
"strop functions are obsolete; use string methods")) \
|
||||||
|
return NULL
|
||||||
|
|
||||||
/* The lstrip(), rstrip() and strip() functions are implemented
|
/* The lstrip(), rstrip() and strip() functions are implemented
|
||||||
in do_strip(), which uses an additional parameter to indicate what
|
in do_strip(), which uses an additional parameter to indicate what
|
||||||
type of strip should occur. */
|
type of strip should occur. */
|
||||||
|
@ -95,6 +99,7 @@ strop_splitfields(PyObject *self, PyObject *args)
|
||||||
char *s, *sub;
|
char *s, *sub;
|
||||||
PyObject *list, *item;
|
PyObject *list, *item;
|
||||||
|
|
||||||
|
WARN;
|
||||||
sub = NULL;
|
sub = NULL;
|
||||||
n = 0;
|
n = 0;
|
||||||
splitcount = 0;
|
splitcount = 0;
|
||||||
|
@ -167,6 +172,7 @@ strop_joinfields(PyObject *self, PyObject *args)
|
||||||
char* p = NULL;
|
char* p = NULL;
|
||||||
intargfunc getitemfunc;
|
intargfunc getitemfunc;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
|
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (sep == NULL) {
|
if (sep == NULL) {
|
||||||
|
@ -292,6 +298,7 @@ strop_find(PyObject *self, PyObject *args)
|
||||||
char *s, *sub;
|
char *s, *sub;
|
||||||
int len, n, i = 0, last = INT_MAX;
|
int len, n, i = 0, last = INT_MAX;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "t#t#|ii:find", &s, &len, &sub, &n, &i, &last))
|
if (!PyArg_ParseTuple(args, "t#t#|ii:find", &s, &len, &sub, &n, &i, &last))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -335,6 +342,7 @@ strop_rfind(PyObject *self, PyObject *args)
|
||||||
int len, n, j;
|
int len, n, j;
|
||||||
int i = 0, last = INT_MAX;
|
int i = 0, last = INT_MAX;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "t#t#|ii:rfind", &s, &len, &sub, &n, &i, &last))
|
if (!PyArg_ParseTuple(args, "t#t#|ii:rfind", &s, &len, &sub, &n, &i, &last))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -404,6 +412,7 @@ static char strip__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
strop_strip(PyObject *self, PyObject *args)
|
strop_strip(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
WARN;
|
||||||
return do_strip(args, BOTHSTRIP);
|
return do_strip(args, BOTHSTRIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,6 +425,7 @@ static char lstrip__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
strop_lstrip(PyObject *self, PyObject *args)
|
strop_lstrip(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
WARN;
|
||||||
return do_strip(args, LEFTSTRIP);
|
return do_strip(args, LEFTSTRIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +438,7 @@ static char rstrip__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
strop_rstrip(PyObject *self, PyObject *args)
|
strop_rstrip(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
WARN;
|
||||||
return do_strip(args, RIGHTSTRIP);
|
return do_strip(args, RIGHTSTRIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,6 +456,7 @@ strop_lower(PyObject *self, PyObject *args)
|
||||||
PyObject *new;
|
PyObject *new;
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_Parse(args, "t#", &s, &n))
|
if (!PyArg_Parse(args, "t#", &s, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
new = PyString_FromStringAndSize(NULL, n);
|
new = PyString_FromStringAndSize(NULL, n);
|
||||||
|
@ -483,6 +495,7 @@ strop_upper(PyObject *self, PyObject *args)
|
||||||
PyObject *new;
|
PyObject *new;
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_Parse(args, "t#", &s, &n))
|
if (!PyArg_Parse(args, "t#", &s, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
new = PyString_FromStringAndSize(NULL, n);
|
new = PyString_FromStringAndSize(NULL, n);
|
||||||
|
@ -522,6 +535,7 @@ strop_capitalize(PyObject *self, PyObject *args)
|
||||||
PyObject *new;
|
PyObject *new;
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_Parse(args, "t#", &s, &n))
|
if (!PyArg_Parse(args, "t#", &s, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
new = PyString_FromStringAndSize(NULL, n);
|
new = PyString_FromStringAndSize(NULL, n);
|
||||||
|
@ -577,6 +591,7 @@ strop_expandtabs(PyObject *self, PyObject *args)
|
||||||
int stringlen;
|
int stringlen;
|
||||||
int tabsize = 8;
|
int tabsize = 8;
|
||||||
|
|
||||||
|
WARN;
|
||||||
/* Get arguments */
|
/* Get arguments */
|
||||||
if (!PyArg_ParseTuple(args, "s#|i:expandtabs", &string, &stringlen, &tabsize))
|
if (!PyArg_ParseTuple(args, "s#|i:expandtabs", &string, &stringlen, &tabsize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -642,6 +657,7 @@ strop_count(PyObject *self, PyObject *args)
|
||||||
int i = 0, last = INT_MAX;
|
int i = 0, last = INT_MAX;
|
||||||
int m, r;
|
int m, r;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "t#t#|ii:count", &s, &len, &sub, &n, &i, &last))
|
if (!PyArg_ParseTuple(args, "t#t#|ii:count", &s, &len, &sub, &n, &i, &last))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (last > len)
|
if (last > len)
|
||||||
|
@ -685,6 +701,7 @@ strop_swapcase(PyObject *self, PyObject *args)
|
||||||
PyObject *new;
|
PyObject *new;
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_Parse(args, "t#", &s, &n))
|
if (!PyArg_Parse(args, "t#", &s, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
new = PyString_FromStringAndSize(NULL, n);
|
new = PyString_FromStringAndSize(NULL, n);
|
||||||
|
@ -733,6 +750,7 @@ strop_atoi(PyObject *self, PyObject *args)
|
||||||
long x;
|
long x;
|
||||||
char buffer[256]; /* For errors */
|
char buffer[256]; /* For errors */
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "s|i:atoi", &s, &base))
|
if (!PyArg_ParseTuple(args, "s|i:atoi", &s, &base))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -786,6 +804,7 @@ strop_atol(PyObject *self, PyObject *args)
|
||||||
PyObject *x;
|
PyObject *x;
|
||||||
char buffer[256]; /* For errors */
|
char buffer[256]; /* For errors */
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "s|i:atol", &s, &base))
|
if (!PyArg_ParseTuple(args, "s|i:atol", &s, &base))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -830,6 +849,7 @@ strop_atof(PyObject *self, PyObject *args)
|
||||||
double x;
|
double x;
|
||||||
char buffer[256]; /* For errors */
|
char buffer[256]; /* For errors */
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "s:atof", &s))
|
if (!PyArg_ParseTuple(args, "s:atof", &s))
|
||||||
return NULL;
|
return NULL;
|
||||||
while (*s && isspace(Py_CHARMASK(*s)))
|
while (*s && isspace(Py_CHARMASK(*s)))
|
||||||
|
@ -913,6 +933,7 @@ strop_translate(PyObject *self, PyObject *args)
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
int trans_table[256];
|
int trans_table[256];
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "St#|t#:translate", &input_obj,
|
if (!PyArg_ParseTuple(args, "St#|t#:translate", &input_obj,
|
||||||
&table1, &tablen, &del_table, &dellen))
|
&table1, &tablen, &del_table, &dellen))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1124,6 +1145,7 @@ strop_replace(PyObject *self, PyObject *args)
|
||||||
int count = -1;
|
int count = -1;
|
||||||
PyObject *new;
|
PyObject *new;
|
||||||
|
|
||||||
|
WARN;
|
||||||
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",
|
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",
|
||||||
&str, &len, &pat, &pat_len, &sub, &sub_len,
|
&str, &len, &pat, &pat_len, &sub, &sub_len,
|
||||||
&count))
|
&count))
|
||||||
|
|
Loading…
Reference in New Issue