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

Skip to content

Commit 9d72bb4

Browse files
committed
Remove functions in string module that are also string methods. Also remove:
* all calls to functions in the string module (except maketrans) * everything from stropmodule except for maketrans() which is still used
1 parent ff11334 commit 9d72bb4

69 files changed

Lines changed: 396 additions & 2113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lib/Cookie.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,14 @@ class CookieError(Exception):
307307

308308
_idmap = ''.join(chr(x) for x in xrange(256))
309309

310-
def _quote(str, LegalChars=_LegalChars,
311-
idmap=_idmap, translate=string.translate):
310+
def _quote(str, LegalChars=_LegalChars, idmap=_idmap):
312311
#
313312
# If the string does not need to be double-quoted,
314313
# then just return the string. Otherwise, surround
315314
# the string in doublequotes and precede quote (with a \)
316315
# special characters.
317316
#
318-
if "" == translate(str, idmap, LegalChars):
317+
if "" == str.translate(idmap, LegalChars):
319318
return str
320319
else:
321320
return '"' + _nulljoin( map(_Translator.get, str, str) ) + '"'
@@ -440,14 +439,12 @@ def isReservedKey(self, K):
440439
return K.lower() in self._reserved
441440
# end isReservedKey
442441

443-
def set(self, key, val, coded_val,
444-
LegalChars=_LegalChars,
445-
idmap=_idmap, translate=string.translate):
442+
def set(self, key, val, coded_val, LegalChars=_LegalChars, idmap=_idmap):
446443
# First we verify that the key isn't a reserved word
447444
# Second we make sure it only contains legal characters
448445
if key.lower() in self._reserved:
449446
raise CookieError("Attempt to set a reserved key: %s" % key)
450-
if "" != translate(key, idmap, LegalChars):
447+
if "" != key.translate(idmap, LegalChars):
451448
raise CookieError("Illegal key value: %s" % key)
452449

453450
# It's a good key, so save it.

Lib/SimpleXMLRPCServer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ class instance, or by extending the SimpleXMLRPCServer
2121
2222
class MyFuncs:
2323
def __init__(self):
24-
# make all of the string functions available through
25-
# string.func_name
26-
import string
27-
self.string = string
24+
# make all of the sys functions available through sys.func_name
25+
import sys
26+
self.sys = sys
2827
def _listMethods(self):
2928
# implement this method so that system.listMethods
30-
# knows to advertise the strings methods
29+
# knows to advertise the sys methods
3130
return list_public_methods(self) + \
32-
['string.' + method for method in list_public_methods(self.string)]
31+
['sys.' + method for method in list_public_methods(self.sys)]
3332
def pow(self, x, y): return pow(x, y)
3433
def add(self, x, y) : return x + y
3534

Lib/bsddb/dbrecio.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"""
3030

3131
import errno
32-
import string
3332

3433
class DBRecIO:
3534
def __init__(self, db, key, txn=None):
@@ -83,9 +82,9 @@ def readline(self, length=None):
8382
if self.closed:
8483
raise ValueError, "I/O operation on closed file"
8584
if self.buflist:
86-
self.buf = self.buf + string.joinfields(self.buflist, '')
85+
self.buf = self.buf + ''.join(self.buflist)
8786
self.buflist = []
88-
i = string.find(self.buf, '\n', self.pos)
87+
i = self.buf.find('\n', self.pos)
8988
if i < 0:
9089
newpos = self.len
9190
else:
@@ -134,7 +133,7 @@ def write(self, s):
134133
self.pos = newpos
135134

136135
def writelines(self, list):
137-
self.write(string.joinfields(list, ''))
136+
self.write(''.join(list))
138137

139138
def flush(self):
140139
if self.closed:

Lib/bsddb/test/test_associate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TestCases for DB.associate.
33
"""
44

5-
import sys, os, string
5+
import sys, os
66
import tempfile
77
import time
88
from pprint import pprint
@@ -177,7 +177,7 @@ def addDataToDB(self, d, txn=None):
177177
for key, value in musicdata.items():
178178
if type(self.keytype) == type(''):
179179
key = "%02d" % key
180-
d.put(key, string.join(value, '|'), txn=txn)
180+
d.put(key, '|'.join(value), txn=txn)
181181

182182
def createDB(self, txn=None):
183183
self.cur = None
@@ -263,7 +263,7 @@ def finish_test(self, secDB, txn=None):
263263
rec = self.cur.first()
264264
while rec is not None:
265265
if type(self.keytype) == type(''):
266-
assert string.atoi(rec[0]) # for primary db, key is a number
266+
assert int(rec[0]) # for primary db, key is a number
267267
else:
268268
assert rec[0] and type(rec[0]) == type(0)
269269
count = count + 1
@@ -305,7 +305,7 @@ def getGenre(self, priKey, priData):
305305
assert type(priData) == type("")
306306
if verbose:
307307
print('getGenre key: %r data: %r' % (priKey, priData))
308-
genre = string.split(priData, '|')[2]
308+
genre = priData.split('|')[2]
309309
if genre == 'Blues':
310310
return db.DB_DONOTINDEX
311311
else:
@@ -427,13 +427,13 @@ def writer1(self, d):
427427
for key, value in musicdata.items():
428428
if type(self.keytype) == type(''):
429429
key = "%02d" % key
430-
d.put(key, string.join(value, '|'))
430+
d.put(key, '|'.join(value))
431431

432432
def writer2(self, d):
433433
for x in range(100, 600):
434434
key = 'z%2d' % x
435435
value = [key] * 4
436-
d.put(key, string.join(value, '|'))
436+
d.put(key, '|'.join(value))
437437

438438

439439
class ThreadedAssociateHashTestCase(ShelveAssociateTestCase):

Lib/bsddb/test/test_compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
regression test suite.
44
"""
55

6-
import sys, os, string
6+
import sys, os
77
import unittest
88
import tempfile
99

@@ -35,7 +35,7 @@ def test02_hashopen(self):
3535
self.do_bthash_test(hashopen, 'hashopen')
3636

3737
def test03_rnopen(self):
38-
data = string.split("The quick brown fox jumped over the lazy dog.")
38+
data = "The quick brown fox jumped over the lazy dog.".split()
3939
if verbose:
4040
print("\nTesting: rnopen")
4141

Lib/bsddb/test/test_dbobj.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import sys, os, string
2+
import sys, os
33
import unittest
44
import glob
55
import tempfile
@@ -38,7 +38,7 @@ def test01_both(self):
3838
class TestDBEnv(dbobj.DBEnv): pass
3939
class TestDB(dbobj.DB):
4040
def put(self, key, *args, **kwargs):
41-
key = string.upper(key)
41+
key = key.upper()
4242
# call our parent classes put method with an upper case key
4343
return dbobj.DB.put(self, key, *args, **kwargs)
4444
self.env = TestDBEnv()

Lib/bsddb/test/test_join.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""TestCases for using the DB.join and DBCursor.join_item methods.
22
"""
33

4-
import sys, os, string
4+
import sys, os
55
import tempfile
66
import time
77
from pprint import pprint

Lib/bsddb/test/test_lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TestCases for testing the locking sub-system.
33
"""
44

5-
import sys, os, string
5+
import sys, os
66
import tempfile
77
import time
88
from pprint import pprint

Lib/bsddb/test/test_pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import sys, os, string
2+
import sys, os
33
import pickle
44
try:
55
import cPickle

Lib/distutils/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
__revision__ = "$Id$"
1010

11-
import sys, os, string, re
11+
import sys, os, re
1212
from types import *
1313
from distutils.errors import *
1414
from distutils import util, dir_util, file_util, archive_util, dep_util
@@ -166,7 +166,7 @@ def dump_options (self, header=None, indent=""):
166166
print(indent + header)
167167
indent = indent + " "
168168
for (option, _, _) in self.user_options:
169-
option = string.translate(option, longopt_xlate)
169+
option = option.translate(longopt_xlate)
170170
if option[-1] == "=":
171171
option = option[:-1]
172172
value = getattr(self, option)
@@ -415,7 +415,7 @@ def make_file (self, infiles, outfile, func, args,
415415
"""
416416
if exec_msg is None:
417417
exec_msg = "generating %s from %s" % \
418-
(outfile, string.join(infiles, ', '))
418+
(outfile, ', '.join(infiles))
419419
if skip_msg is None:
420420
skip_msg = "skipping %s (inputs unchanged)" % outfile
421421

0 commit comments

Comments
 (0)