Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e0a654

Browse files
committed
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.
1 parent 9cba643 commit 2e0a654

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/test/test_strop.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from test_support import verbose
2+
import warnings
3+
warnings.filterwarnings("ignore", "", DeprecationWarning, __name__)
24
import strop, sys
35

46
def test(name, input, output, *args):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ Core
8787

8888
Library
8989

90+
- strop is now *really* obsolete (this was announced before with 1.6),
91+
and issues DeprecationWarning when used (except for the four items
92+
that are still imported into string.py).
93+
9094
- Cookie.py now sorts key+value pairs by key in output strings.
9195

9296
- pprint.isrecursive(object) didn't correctly identify recursive objects.

Modules/stropmodule.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ static char strop_module__doc__[] =
1212
/* XXX This file assumes that the <ctype.h> is*() functions
1313
XXX are defined for all 8-bit characters! */
1414

15+
#define WARN if (PyErr_Warn(PyExc_DeprecationWarning, \
16+
"strop functions are obsolete; use string methods")) \
17+
return NULL
18+
1519
/* The lstrip(), rstrip() and strip() functions are implemented
1620
in do_strip(), which uses an additional parameter to indicate what
1721
type of strip should occur. */
@@ -95,6 +99,7 @@ strop_splitfields(PyObject *self, PyObject *args)
9599
char *s, *sub;
96100
PyObject *list, *item;
97101

102+
WARN;
98103
sub = NULL;
99104
n = 0;
100105
splitcount = 0;
@@ -167,6 +172,7 @@ strop_joinfields(PyObject *self, PyObject *args)
167172
char* p = NULL;
168173
intargfunc getitemfunc;
169174

175+
WARN;
170176
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
171177
return NULL;
172178
if (sep == NULL) {
@@ -292,6 +298,7 @@ strop_find(PyObject *self, PyObject *args)
292298
char *s, *sub;
293299
int len, n, i = 0, last = INT_MAX;
294300

301+
WARN;
295302
if (!PyArg_ParseTuple(args, "t#t#|ii:find", &s, &len, &sub, &n, &i, &last))
296303
return NULL;
297304

@@ -335,6 +342,7 @@ strop_rfind(PyObject *self, PyObject *args)
335342
int len, n, j;
336343
int i = 0, last = INT_MAX;
337344

345+
WARN;
338346
if (!PyArg_ParseTuple(args, "t#t#|ii:rfind", &s, &len, &sub, &n, &i, &last))
339347
return NULL;
340348

@@ -404,6 +412,7 @@ static char strip__doc__[] =
404412
static PyObject *
405413
strop_strip(PyObject *self, PyObject *args)
406414
{
415+
WARN;
407416
return do_strip(args, BOTHSTRIP);
408417
}
409418

@@ -416,6 +425,7 @@ static char lstrip__doc__[] =
416425
static PyObject *
417426
strop_lstrip(PyObject *self, PyObject *args)
418427
{
428+
WARN;
419429
return do_strip(args, LEFTSTRIP);
420430
}
421431

@@ -428,6 +438,7 @@ static char rstrip__doc__[] =
428438
static PyObject *
429439
strop_rstrip(PyObject *self, PyObject *args)
430440
{
441+
WARN;
431442
return do_strip(args, RIGHTSTRIP);
432443
}
433444

@@ -445,6 +456,7 @@ strop_lower(PyObject *self, PyObject *args)
445456
PyObject *new;
446457
int changed;
447458

459+
WARN;
448460
if (!PyArg_Parse(args, "t#", &s, &n))
449461
return NULL;
450462
new = PyString_FromStringAndSize(NULL, n);
@@ -483,6 +495,7 @@ strop_upper(PyObject *self, PyObject *args)
483495
PyObject *new;
484496
int changed;
485497

498+
WARN;
486499
if (!PyArg_Parse(args, "t#", &s, &n))
487500
return NULL;
488501
new = PyString_FromStringAndSize(NULL, n);
@@ -522,6 +535,7 @@ strop_capitalize(PyObject *self, PyObject *args)
522535
PyObject *new;
523536
int changed;
524537

538+
WARN;
525539
if (!PyArg_Parse(args, "t#", &s, &n))
526540
return NULL;
527541
new = PyString_FromStringAndSize(NULL, n);
@@ -577,6 +591,7 @@ strop_expandtabs(PyObject *self, PyObject *args)
577591
int stringlen;
578592
int tabsize = 8;
579593

594+
WARN;
580595
/* Get arguments */
581596
if (!PyArg_ParseTuple(args, "s#|i:expandtabs", &string, &stringlen, &tabsize))
582597
return NULL;
@@ -642,6 +657,7 @@ strop_count(PyObject *self, PyObject *args)
642657
int i = 0, last = INT_MAX;
643658
int m, r;
644659

660+
WARN;
645661
if (!PyArg_ParseTuple(args, "t#t#|ii:count", &s, &len, &sub, &n, &i, &last))
646662
return NULL;
647663
if (last > len)
@@ -685,6 +701,7 @@ strop_swapcase(PyObject *self, PyObject *args)
685701
PyObject *new;
686702
int changed;
687703

704+
WARN;
688705
if (!PyArg_Parse(args, "t#", &s, &n))
689706
return NULL;
690707
new = PyString_FromStringAndSize(NULL, n);
@@ -733,6 +750,7 @@ strop_atoi(PyObject *self, PyObject *args)
733750
long x;
734751
char buffer[256]; /* For errors */
735752

753+
WARN;
736754
if (!PyArg_ParseTuple(args, "s|i:atoi", &s, &base))
737755
return NULL;
738756

@@ -786,6 +804,7 @@ strop_atol(PyObject *self, PyObject *args)
786804
PyObject *x;
787805
char buffer[256]; /* For errors */
788806

807+
WARN;
789808
if (!PyArg_ParseTuple(args, "s|i:atol", &s, &base))
790809
return NULL;
791810

@@ -830,6 +849,7 @@ strop_atof(PyObject *self, PyObject *args)
830849
double x;
831850
char buffer[256]; /* For errors */
832851

852+
WARN;
833853
if (!PyArg_ParseTuple(args, "s:atof", &s))
834854
return NULL;
835855
while (*s && isspace(Py_CHARMASK(*s)))
@@ -913,6 +933,7 @@ strop_translate(PyObject *self, PyObject *args)
913933
PyObject *result;
914934
int trans_table[256];
915935

936+
WARN;
916937
if (!PyArg_ParseTuple(args, "St#|t#:translate", &input_obj,
917938
&table1, &tablen, &del_table, &dellen))
918939
return NULL;
@@ -1124,6 +1145,7 @@ strop_replace(PyObject *self, PyObject *args)
11241145
int count = -1;
11251146
PyObject *new;
11261147

1148+
WARN;
11271149
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",
11281150
&str, &len, &pat, &pat_len, &sub, &sub_len,
11291151
&count))

0 commit comments

Comments
 (0)