Skip to content

Commit 700c827

Browse files
Replace string module functions with string object methods.
1 parent e5783f6 commit 700c827

File tree

12 files changed

+49
-63
lines changed

12 files changed

+49
-63
lines changed

Xlib/error.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818

19-
# Standard modules
20-
import string
21-
2219
# Xlib modules
2320
from . import X
2421

@@ -76,9 +73,9 @@ def __str__(self):
7673
s = []
7774
for f in ('code', 'resource_id', 'sequence_number',
7875
'major_opcode', 'minor_opcode'):
79-
s.append('%s = %s' % (f, self._data[f]))
76+
s.append('{0} = {1}'.format(f, self._data[f]))
8077

81-
return '%s: %s' % (self.__class__, string.join(s, ', '))
78+
return '{0}: {1}'.format(self.__class__, ', '.join(s))
8279

8380
class XResourceError(XError):
8481
_fields = rq.Struct( rq.Card8('type'), # Always 0

Xlib/protocol/rq.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import sys
2222
import traceback
2323
import struct
24-
import string
2524
from array import array
2625
import types
2726

@@ -533,7 +532,7 @@ def pack_value(self, val):
533532
for v in val:
534533
data.append(self.type.pack_value(v))
535534

536-
data = string.join(data, '')
535+
data = ''.join(data)
537536

538537
if self.pad:
539538
dlen = len(data)
@@ -1391,7 +1390,7 @@ def __repr__(self):
13911390
val = val | 0x80
13921391
kwlist.append('%s = %s' % (kw, repr(val)))
13931392

1394-
kws = string.join(kwlist, ', ')
1393+
kws = ', '.join(kwlist)
13951394
return '%s(%s)' % (self.__class__, kws)
13961395

13971396
def __cmp__(self, other):

Xlib/rdb.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323

2424
# Standard modules
25-
import string
26-
import types
25+
import locale
2726
import re
2827
import sys
2928

@@ -84,7 +83,7 @@ def insert_string(self, data):
8483
"""
8584

8685
# First split string into lines
87-
lines = string.split(data, '\n')
86+
lines = data.split('\n')
8887

8988
while lines:
9089
line = lines[0]
@@ -122,15 +121,15 @@ def insert_string(self, data):
122121
for i in range(1, len(splits), 2):
123122
s = splits[i]
124123
if len(s) == 3:
125-
splits[i] = chr(string.atoi(s, 8))
124+
splits[i] = chr(locale.atoi(s, 8))
126125
elif s == 'n':
127126
splits[i] = '\n'
128127

129128
# strip the last value part to get rid of any
130129
# unescaped blanks
131-
splits[-1] = string.rstrip(splits[-1])
130+
splits[-1] = splits[-1].rstrip()
132131

133-
value = string.join(splits, '')
132+
value = ''.join(splits)
134133

135134
self.insert(res, value)
136135

@@ -199,8 +198,8 @@ def __getitem__(self, keys_tuple):
199198
# Split name and class into their parts
200199
name, cls = keys_tuple
201200

202-
namep = string.split(name, '.')
203-
clsp = string.split(cls, '.')
201+
namep = name.split('.')
202+
clsp = cls.split('.')
204203

205204
# It is an error for name and class to have different number
206205
# of parts
@@ -537,7 +536,7 @@ def output_escape(value):
537536
('\000', '\\000'),
538537
('\n', '\\n')):
539538

540-
value = string.replace(value, char, esc)
539+
value = value.replace(char, esc)
541540

542541
# If first or last character is space or tab, escape them.
543542
if value[0] in ' \t':

Xlib/support/connect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818

1919
import sys
20-
import string
2120

2221
# List the modules which contain the corresponding functions
2322

@@ -43,7 +42,7 @@
4342
# Figure out which OS we're using.
4443
# sys.platform is either "OS-ARCH" or just "OS".
4544

46-
_parts = string.split(sys.platform, '-')
45+
_parts = sys.platform.split('-')
4746
platform = _parts[0]
4847
del _parts
4948

Xlib/support/unix_connect.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818

1919
import re
20-
import string
20+
import locale
2121
import os
2222
import platform
2323
import socket
@@ -106,8 +106,8 @@ def new_get_auth(sock, dname, host, dno):
106106

107107
# Convert the prettyprinted IP number into 4-octet string.
108108
# Sometimes these modules are too damn smart...
109-
octets = string.split(sock.getpeername()[0], '.')
110-
addr = string.join(map(lambda x: chr(int(x)), octets), '')
109+
octets = sock.getpeername()[0].split('.')
110+
addr = ''.join(map(lambda x: chr(int(x)), octets))
111111
else:
112112
family = xauth.FamilyLocal
113113
addr = socket.gethostname()
@@ -143,17 +143,17 @@ def old_get_auth(sock, dname, host, dno):
143143
# DISPLAY SCHEME COOKIE
144144
# We're interested in the two last parts for the
145145
# connection establishment
146-
lines = string.split(data, '\n')
146+
lines = data.split('\n')
147147
if len(lines) >= 1:
148-
parts = string.split(lines[0], None, 2)
148+
parts = lines[0].split(None, 2)
149149
if len(parts) == 3:
150150
auth_name = parts[1]
151151
hexauth = parts[2]
152152
auth = ''
153153

154154
# Translate hexcode into binary
155155
for i in range(0, len(hexauth), 2):
156-
auth = auth + chr(string.atoi(hexauth[i:i+2], 16))
156+
auth = auth + chr(locale.atoi(hexauth[i:i+2], 16))
157157

158158
auth_data = auth
159159
except os.error:

Xlib/xobject/colormap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import resource
2323

2424
import re
25-
import string
25+
import locale
2626

2727
rgb_res = [
2828
re.compile(r'\Argb:([0-9a-fA-F]{1,4})/([0-9a-fA-F]{1,4})/([0-9a-fA-F]{1,4})\Z'),
@@ -73,13 +73,13 @@ def alloc_named_color(self, name):
7373
m = r.match(name)
7474
if m:
7575
rs = m.group(1)
76-
r = string.atoi(rs + '0' * (4 - len(rs)), 16)
76+
r = locale.atoi(rs + '0' * (4 - len(rs)), 16)
7777

7878
gs = m.group(2)
79-
g = string.atoi(gs + '0' * (4 - len(gs)), 16)
79+
g = locale.atoi(gs + '0' * (4 - len(gs)), 16)
8080

8181
bs = m.group(3)
82-
b = string.atoi(bs + '0' * (4 - len(bs)), 16)
82+
b = locale.atoi(bs + '0' * (4 - len(bs)), 16)
8383

8484
return self.alloc_color(r, g, b)
8585

Xlib/xobject/drawable.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818

19-
import string
20-
2119
from Xlib import X, Xatom, Xutil
2220
from Xlib.protocol import request, rq
2321

@@ -668,7 +666,7 @@ def get_wm_class(self):
668666
if d is None or d.format != 8:
669667
return None
670668
else:
671-
parts = string.split(d.value, '\0')
669+
parts = d.value.split('\0')
672670
if len(parts) < 2:
673671
return None
674672
else:

test/gen/genprottest.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
sys.path.insert(1, os.path.join(sys.path[0], '../..'))
77

88
import types
9-
import string
109
import struct
1110
from whrandom import randint, choice
1211

@@ -35,11 +34,11 @@ def read_defs():
3534
event_defs = {}
3635

3736
for line in sys.stdin.readlines():
38-
parts = string.split(string.strip(line))
37+
parts = line.strip().split()
3938

4039
fields = []
4140
for f in parts[2:]:
42-
fields.append(string.split(f, ':'))
41+
fields.append(f.split(':'))
4342

4443
if parts[0] == 'REQUEST':
4544
request_defs[parts[1]] = fields
@@ -176,7 +175,7 @@ def build_request(endian):
176175
reply_bins = {}
177176
pc = os.popen('./genrequest', 'r')
178177
for line in pc.readlines():
179-
parts = string.split(string.strip(line))
178+
parts = line.strip().split()
180179
if parts[0] == 'REQUEST':
181180
req_bins[parts[1]] = parts[2]
182181
elif parts[0] == 'REPLY':
@@ -347,7 +346,7 @@ def build_event(endian):
347346
evt_bins = {}
348347
pc = os.popen('./genevent', 'r')
349348
for line in pc.readlines():
350-
parts = string.split(string.strip(line))
349+
parts = line.strip().split()
351350
if parts[0] == 'EVENT':
352351
evt_bins[parts[1]] = parts[2]
353352

@@ -488,7 +487,7 @@ def rand(x, rmin = rmin, rmax = rmax):
488487
'xKeymapEvent'):
489488
extra_vars.append('%s %s_def[%d] = { %s };'
490489
% (ctype, f.name, vflen,
491-
string.join(map(str, vfdata), ', ')))
490+
', '.join(map(str, vfdata))))
492491
varfs[f.name] = ('memcpy(data.xstruct.map, %s_def, sizeof(%s_def));'
493492
% (f.name, f.name),
494493
vflen, 0)
@@ -497,7 +496,7 @@ def rand(x, rmin = rmin, rmax = rmax):
497496
% (ctype, f.name, deflen))
498497
extra_vars.append('%s %s_def[%d] = { %s };'
499498
% (ctype, f.name, vflen,
500-
string.join(map(str, vfdata), ', ')))
499+
', '.join(map(str, vfdata))))
501500
varfs[f.name] = ('memcpy(data.%s, %s_def, sizeof(%s_def));'
502501
% (f.name, f.name, f.name),
503502
vflen, 0)
@@ -522,7 +521,7 @@ def rand(x, rmin = rmin, rmax = rmax):
522521

523522
extra_vars.append('struct { xHostEntry e; CARD8 name[4]; } %s_def[%d] = { %s };'
524523
% (f.name, len(pydata),
525-
string.join(cdata, ', ')))
524+
', '.join(cdata)))
526525

527526
varfs[f.name] = ('memcpy(data.%s, %s_def, sizeof(%s_def));'
528527
% (f.name, f.name, f.name),
@@ -551,13 +550,13 @@ def rand(x, rmin = rmin, rmax = rmax):
551550
pyd[f.type.fields[sj].name] = d[sj]
552551

553552
pydata.append(pyd)
554-
defdata.append('{ ' + string.join(map(str, d), ', ') + ' }')
553+
defdata.append('{ ' + ', '.join(map(str, d)) + ' }')
555554

556555
fc.write('x%s %s[%d];\n ' % (vfname, f.name, vflen))
557556

558557
extra_vars.append('x%s %s_def[%d] = { %s };'
559558
% (vfname, f.name, vflen,
560-
string.join(defdata, ', ')))
559+
', '.join(defdata)))
561560
varfs[f.name] = ('memcpy(data.%s, %s_def, sizeof(%s_def));'
562561
% (f.name, f.name, f.name),
563562
vflen, 0)
@@ -623,7 +622,7 @@ def rand(x, rmin = rmin, rmax = rmax):
623622

624623
# vlcode.append('data.%s_flags = %d;' % (f.name, flags))
625624

626-
varfs[f.name] = (string.join(vlcode, ' '), 0, 0)
625+
varfs[f.name] = (' '.join(vlcode), 0, 0)
627626
args[f.name] = vlargs
628627

629628
#
@@ -679,7 +678,7 @@ def rand(x, rmin = rmin, rmax = rmax):
679678
fc.write('%s %s[%d];\n ' % (ctype, f.name, len(cdata)))
680679
extra_vars.append('%s %s_def[%d] = { %s };'
681680
% (ctype, f.name, len(cdata),
682-
string.join(cdata, ', ')))
681+
', '.join(cdata)))
683682
varfs[f.name] = ('memcpy(data.%s, %s_def, sizeof(%s_def));'
684683
% (f.name, f.name, f.name),
685684
length, format)
@@ -699,11 +698,11 @@ def rand(x, rmin = rmin, rmax = rmax):
699698
elif format == 16:
700699
ctype = 'CARD16'
701700
clen = length + length % 2
702-
cdata = string.join(map(str, data), ', ')
701+
cdata = ', '.join(map(str, data))
703702
elif format == 32:
704703
ctype = 'CARD32'
705704
clen = length
706-
cdata = string.join(map(str, data), ', ')
705+
cdata = ', '.join(map(str, data))
707706

708707
if not isinstance(f, rq.FixedPropertyData):
709708
fc.write('%s %s[%d];\n ' %
@@ -825,7 +824,7 @@ def rand(x, rmin = rmin, rmax = rmax):
825824
pyd[pyf.type.fields[sj].name] = d[sj]
826825

827826
fc.write('{ %s def = { %s };\n '
828-
% (t, string.join(map(str, d), ', ')))
827+
% (t, ', '.join(map(str, d))))
829828
fc.write('memcpy(&data.xstruct.%s, &def, sizeof(def)); }\n ' % f)
830829
args[pyf.name] = pyd
831830

@@ -870,15 +869,15 @@ def pad4(l):
870869
return l + (4 - l % 4) % 4
871870

872871
def cstring(s):
873-
return '"' + string.join(map(lambda c: '\\x%x' % ord(c), s), '') + '"'
872+
return '"' + ''.join(map(lambda c: '\\x%x' % ord(c), s)) + '"'
874873

875874

876875
def build_args(args):
877876
kwlist = []
878877
for kw, val in args.items():
879878
kwlist.append(" '%s': %s,\n" % (kw, repr(val)))
880879

881-
return '{\n' + string.join(kwlist, '') + ' }'
880+
return '{\n' + ''.join(kwlist) + ' }'
882881

883882
def build_bin(bin):
884883
bins = []
@@ -892,7 +891,7 @@ def build_bin(bin):
892891
except IndexError:
893892
bins2.append("'%s'" % bins[i])
894893

895-
return string.join(bins2, ' \\\n ')
894+
return ' \\\n '.join(bins2)
896895

897896

898897
request_var_defs = {
@@ -1013,7 +1012,6 @@ def build_bin(bin):
10131012
import sys, os
10141013
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
10151014
1016-
import string
10171015
import unittest
10181016
from Xlib.protocol import request, rq, event
10191017
import Xlib.protocol.event
@@ -1040,7 +1038,7 @@ def __cmp__(self, other):
10401038
rq.array = CmpArray
10411039
10421040
def tohex(bin):
1043-
bin = string.join(map(lambda c: '\\x%%02x' %% ord(c), bin), '')
1041+
bin = ''.join(map(lambda c: '\\x%%02x' %% ord(c), bin))
10441042
10451043
bins = []
10461044
for i in range(0, len(bin), 16):
@@ -1053,7 +1051,7 @@ def tohex(bin):
10531051
except IndexError:
10541052
bins2.append("'%%s'" %% bins[i])
10551053
1056-
return string.join(bins2, ' \\\n ')
1054+
return ' \\\n '.join(bins2)
10571055
10581056
class DummyDisplay:
10591057
def get_resource_class(self, x):

0 commit comments

Comments
 (0)