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

Skip to content

Commit ae39ddd

Browse files
committed
Mechanically translated string method calls to string methods.
Instead of splitting a string and looping over it to call s.split(), use list comprehensions for readability.
1 parent ef5864e commit ae39ddd

1 file changed

Lines changed: 22 additions & 36 deletions

File tree

Tools/scripts/texi2html.py

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def flush(self):
125125

126126
def link(self, label, nodename, rel=None, rev=None):
127127
if nodename:
128-
if string.lower(nodename) == '(dir)':
128+
if nodename.lower() == '(dir)':
129129
addr = '../dir.html'
130130
title = ''
131131
else:
@@ -138,14 +138,13 @@ def link(self, label, nodename, rel=None, rev=None):
138138

139139
def finalize(self):
140140
length = len(self.lines)
141-
self.text = string.joinfields(self.lines, '')
141+
self.text = ''.join(self.lines)
142142
self.lines = []
143143
self.open_links()
144144
self.output_links()
145145
self.close_links()
146-
links = string.joinfields(self.lines, '')
146+
links = ''.join(self.lines)
147147
self.lines = []
148-
149148
self.prologue = (
150149
self.DOCTYPE +
151150
'\n<HTML><HEAD>\n'
@@ -337,7 +336,7 @@ def collectsavings(self):
337336
# Write text to file, or save it in a buffer, or ignore it
338337
def write(self, *args):
339338
try:
340-
text = string.joinfields(args, '')
339+
text = ''.join(args)
341340
except:
342341
print args
343342
raise TypeError
@@ -392,7 +391,7 @@ def process(self, accu):
392391
for line in accu:
393392
mo = miprog.match(line)
394393
if not mo:
395-
line = string.strip(line) + '\n'
394+
line = line.strip() + '\n'
396395
self.expand(line)
397396
continue
398397
bgn, end = mo.span(0)
@@ -412,7 +411,7 @@ def process(self, accu):
412411
self.htmlhelp.menuitem(nodename)
413412
self.expand(line[end:])
414413
else:
415-
text = string.joinfields(accu, '')
414+
text = ''.join(accu)
416415
self.expand(text)
417416

418417
# find 'menu' (we might be inside 'ifset' or 'ifclear')
@@ -699,21 +698,15 @@ def open_inforef(self):
699698
self.startsaving()
700699
def close_inforef(self):
701700
text = self.collectsavings()
702-
args = string.splitfields(text, ',')
703-
n = len(args)
704-
for i in range(n):
705-
args[i] = string.strip(args[i])
701+
args = [s.strip() for s in text.split(',')]
706702
while len(args) < 3: args.append('')
707703
node = args[0]
708704
file = args[2]
709705
self.write('`', file, '\', node `', node, '\'')
710706

711707
def makeref(self):
712708
text = self.collectsavings()
713-
args = string.splitfields(text, ',')
714-
n = len(args)
715-
for i in range(n):
716-
args[i] = string.strip(args[i])
709+
args = [s.strip() for s in text.split(',')]
717710
while len(args) < 5: args.append('')
718711
nodename = label = args[0]
719712
if args[2]: label = args[2]
@@ -729,10 +722,7 @@ def open_uref(self):
729722
self.startsaving()
730723
def close_uref(self):
731724
text = self.collectsavings()
732-
args = string.splitfields(text, ',')
733-
n = len(args)
734-
for i in range(n):
735-
args[i] = string.strip(args[i])
725+
args = [s.strip() for s in text.split(',')]
736726
while len(args) < 2: args.append('')
737727
href = args[0]
738728
label = args[1]
@@ -752,10 +742,7 @@ def close_image(self):
752742
self.makeimage()
753743
def makeimage(self):
754744
text = self.collectsavings()
755-
args = string.splitfields(text, ',')
756-
n = len(args)
757-
for i in range(n):
758-
args[i] = string.strip(args[i])
745+
args = [s.strip() for s in text.split(',')]
759746
while len(args) < 5: args.append('')
760747
filename = args[0]
761748
width = args[1]
@@ -882,7 +869,7 @@ def close_small(self): pass
882869
def command(self, line, mo):
883870
a, b = mo.span(1)
884871
cmd = line[a:b]
885-
args = string.strip(line[b:])
872+
args = line[b:].strip()
886873
if self.debugging > 1:
887874
print '!'*self.debugging, 'command:', self.skip, self.stack, \
888875
'@' + cmd, args
@@ -910,7 +897,7 @@ def unknown_cmd(self, cmd, args):
910897
self.unknown[cmd] = self.unknown[cmd] + 1
911898

912899
def do_end(self, args):
913-
words = string.split(args)
900+
words = args.split()
914901
if not words:
915902
print '*** @end w/o args'
916903
else:
@@ -954,12 +941,12 @@ def bgn_tex(self, args): self.skip = self.skip + 1
954941
def end_tex(self): self.skip = self.skip - 1
955942

956943
def do_set(self, args):
957-
fields = string.splitfields(args, ' ')
944+
fields = args.split(' ')
958945
key = fields[0]
959946
if len(fields) == 1:
960947
value = 1
961948
else:
962-
value = string.joinfields(fields[1:], ' ')
949+
value = ' '.join(fields[1:])
963950
self.values[key] = value
964951

965952
def do_clear(self, args):
@@ -1059,9 +1046,8 @@ def do_center(self, args):
10591046
def do_node(self, args):
10601047
self.endnode()
10611048
self.nodelineno = 0
1062-
parts = string.splitfields(args, ',')
1049+
parts = [s.strip() for s in args.split(',')]
10631050
while len(parts) < 4: parts.append('')
1064-
for i in range(4): parts[i] = string.strip(parts[i])
10651051
self.nodelinks = parts
10661052
[name, next, prev, up] = parts[:4]
10671053
file = self.dirname + '/' + makefile(name)
@@ -1083,7 +1069,7 @@ def do_node(self, args):
10831069

10841070
def link(self, label, nodename):
10851071
if nodename:
1086-
if string.lower(nodename) == '(dir)':
1072+
if nodename.lower() == '(dir)':
10871073
addr = '../dir.html'
10881074
else:
10891075
addr = makefile(nodename)
@@ -1577,7 +1563,7 @@ def index(self, name, args):
15771563
self.htmlhelp.index(args, self.nodename)
15781564

15791565
def do_synindex(self, args):
1580-
words = string.split(args)
1566+
words = args.split()
15811567
if len(words) <> 2:
15821568
print '*** bad @synindex', args
15831569
return
@@ -1594,7 +1580,7 @@ def do_synindex(self, args):
15941580
do_syncodeindex = do_synindex # XXX Should use code font
15951581

15961582
def do_printindex(self, args):
1597-
words = string.split(args)
1583+
words = args.split()
15981584
for name in words:
15991585
if self.whichindex.has_key(name):
16001586
self.prindex(name)
@@ -1612,7 +1598,7 @@ def prindex(self, name):
16121598
index1 = []
16131599
junkprog = re.compile('^(@[a-z]+)?{')
16141600
for key, node in index:
1615-
sortkey = string.lower(key)
1601+
sortkey = key.lower()
16161602
# Remove leading `@cmd{' from sort key
16171603
# -- don't bother about the matching `}'
16181604
oldsortkey = sortkey
@@ -1647,7 +1633,7 @@ def report(self):
16471633
cmds = self.unknown.keys()
16481634
cmds.sort()
16491635
for cmd in cmds:
1650-
print string.ljust(cmd, 20), self.unknown[cmd]
1636+
print cmd.ljust(20), self.unknown[cmd]
16511637

16521638

16531639
class TexinfoParserHTML3(TexinfoParser):
@@ -1988,7 +1974,7 @@ def findwordend(str, i, n):
19881974

19891975
# Convert a node name into a file name
19901976
def makefile(nodename):
1991-
nodename = string.strip(nodename)
1977+
nodename = nodename.strip()
19921978
return fixfunnychars(nodename) + '.html'
19931979

19941980

@@ -2017,7 +2003,7 @@ def increment(s):
20172003
for sequence in string.digits, string.lowercase, string.uppercase:
20182004
lastc = s[-1]
20192005
if lastc in sequence:
2020-
i = string.index(sequence, lastc) + 1
2006+
i = sequence.index(lastc) + 1
20212007
if i >= len(sequence):
20222008
if len(s) == 1:
20232009
s = sequence[0]*2

0 commit comments

Comments
 (0)