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

Skip to content

Commit 41b60b2

Browse files
committed
minor refactoring
1 parent 81bd9a2 commit 41b60b2

15 files changed

Lines changed: 39 additions & 39 deletions

File tree

extra/beautifulsoup/beautifulsoup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def __setitem__(self, key, value):
621621
self._getAttrMap()
622622
self.attrMap[key] = value
623623
found = False
624-
for i in range(0, len(self.attrs)):
624+
for i in xrange(0, len(self.attrs)):
625625
if self.attrs[i][0] == key:
626626
self.attrs[i] = (key, value)
627627
found = True
@@ -664,7 +664,7 @@ def __eq__(self, other):
664664
return True
665665
if not hasattr(other, 'name') or not hasattr(other, 'attrs') or not hasattr(other, 'contents') or self.name != other.name or self.attrs != other.attrs or len(self) != len(other):
666666
return False
667-
for i in range(0, len(self.contents)):
667+
for i in xrange(0, len(self.contents)):
668668
if self.contents[i] != other.contents[i]:
669669
return False
670670
return True
@@ -1267,14 +1267,14 @@ def _popToTag(self, name, inclusivePop=True):
12671267

12681268
numPops = 0
12691269
mostRecentTag = None
1270-
for i in range(len(self.tagStack)-1, 0, -1):
1270+
for i in xrange(len(self.tagStack)-1, 0, -1):
12711271
if name == self.tagStack[i].name:
12721272
numPops = len(self.tagStack)-i
12731273
break
12741274
if not inclusivePop:
12751275
numPops = numPops - 1
12761276

1277-
for i in range(0, numPops):
1277+
for i in xrange(0, numPops):
12781278
mostRecentTag = self.popTag()
12791279
return mostRecentTag
12801280

@@ -1301,7 +1301,7 @@ def _smartPop(self, name):
13011301
isResetNesting = self.RESET_NESTING_TAGS.has_key(name)
13021302
popTo = None
13031303
inclusive = True
1304-
for i in range(len(self.tagStack)-1, 0, -1):
1304+
for i in xrange(len(self.tagStack)-1, 0, -1):
13051305
p = self.tagStack[i]
13061306
if (not p or p.name == name) and not isNestable:
13071307
#Non-nestable tags get popped to the top or to their
@@ -1579,7 +1579,7 @@ def start_meta(self, attrs):
15791579
contentTypeIndex = None
15801580
tagNeedsEncodingSubstitution = False
15811581

1582-
for i in range(0, len(attrs)):
1582+
for i in xrange(0, len(attrs)):
15831583
key, value = attrs[i]
15841584
key = key.lower()
15851585
if key == 'http-equiv':
@@ -1968,7 +1968,7 @@ def _ebcdic_to_ascii(self, s):
19681968
250,251,252,253,254,255)
19691969
import string
19701970
c.EBCDIC_TO_ASCII_MAP = string.maketrans( \
1971-
''.join(map(chr, range(256))), ''.join(map(chr, emap)))
1971+
''.join(map(chr, xrange(256))), ''.join(map(chr, emap)))
19721972
return s.translate(c.EBCDIC_TO_ASCII_MAP)
19731973

19741974
MS_CHARS = { '\x80' : ('euro', '20AC'),

extra/chardet/eucjpprober.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_charset_name(self):
5050

5151
def feed(self, aBuf):
5252
aLen = len(aBuf)
53-
for i in range(0, aLen):
53+
for i in xrange(0, aLen):
5454
codingState = self._mCodingSM.next_state(aBuf[i])
5555
if codingState == eError:
5656
if constants._debug:

extra/chardet/mbcharsetprober.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_charset_name(self):
5151

5252
def feed(self, aBuf):
5353
aLen = len(aBuf)
54-
for i in range(0, aLen):
54+
for i in xrange(0, aLen):
5555
codingState = self._mCodingSM.next_state(aBuf[i])
5656
if codingState == eError:
5757
if constants._debug:

extra/chardet/sjisprober.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_charset_name(self):
5050

5151
def feed(self, aBuf):
5252
aLen = len(aBuf)
53-
for i in range(0, aLen):
53+
for i in xrange(0, aLen):
5454
codingState = self._mCodingSM.next_state(aBuf[i])
5555
if codingState == eError:
5656
if constants._debug:

extra/chardet/utf8prober.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def feed(self, aBuf):
6969
def get_confidence(self):
7070
unlike = 0.99
7171
if self._mNumOfMBChar < 6:
72-
for i in range(0, self._mNumOfMBChar):
72+
for i in xrange(0, self._mNumOfMBChar):
7373
unlike = unlike * ONE_CHAR_PROB
7474
return 1.0 - unlike
7575
else:

extra/clientform/clientform.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def addheader(self, key, value, prefix=0,
384384
# 2.2 urllib2 doesn't normalize header case
385385
self._http_hdrs.append((key.capitalize(), value))
386386
else:
387-
for i in range(1, len(lines)):
387+
for i in xrange(1, len(lines)):
388388
lines[i] = " " + lines[i].strip()
389389
value = "\r\n".join(lines) + "\r\n"
390390
line = key.title() + ": " + value
@@ -1129,7 +1129,7 @@ def _ParseFileEx(file, base_uri,
11291129
forms, labels, id_to_labels, backwards_compat)
11301130
form._urlparse = _urlparse
11311131
form._urlunparse = _urlunparse
1132-
for ii in range(len(controls)):
1132+
for ii in xrange(len(controls)):
11331133
type, name, attrs = controls[ii]
11341134
# index=ii*10 allows ImageControl to return multiple ordered pairs
11351135
form.new_control(
@@ -2020,7 +2020,7 @@ def add_to_form(self, form):
20202020
# always count nameless elements as separate controls
20212021
Control.add_to_form(self, form)
20222022
else:
2023-
for ii in range(len(form.controls)-1, -1, -1):
2023+
for ii in xrange(len(form.controls)-1, -1, -1):
20242024
control = form.controls[ii]
20252025
if control.name == self.name and control.type == self.type:
20262026
if control._closed:
@@ -2151,7 +2151,7 @@ def _multiple_set_value(self, value):
21512151
names[nn] = 1
21522152
for name, count in names.items():
21532153
on, off = self._get_items(name, count)
2154-
for i in range(count):
2154+
for i in xrange(count):
21552155
if on:
21562156
item = on[0]
21572157
del on[0]
@@ -2850,7 +2850,7 @@ def new_control(self, type, name, attrs,
28502850
control = klass(type, name, a, index)
28512851

28522852
if type == "select" and len(attrs) == 1:
2853-
for ii in range(len(self.controls)-1, -1, -1):
2853+
for ii in xrange(len(self.controls)-1, -1, -1):
28542854
ctl = self.controls[ii]
28552855
if ctl.type == "select":
28562856
ctl.close_control()
@@ -3333,7 +3333,7 @@ def _pairs_and_controls(self):
33333333
control_index is the index of the control in self.controls
33343334
"""
33353335
pairs = []
3336-
for control_index in range(len(self.controls)):
3336+
for control_index in xrange(len(self.controls)):
33373337
control = self.controls[control_index]
33383338
for ii, key, val in control._totally_ordered_pairs():
33393339
pairs.append((ii, key, val, control_index))

extra/fcrypt/fcrypt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def _set_key(password):
475475

476476
k = [0] * (_ITERATIONS * 2)
477477

478-
for i in range(_ITERATIONS):
478+
for i in xrange(_ITERATIONS):
479479
# Only operates on top 28 bits.
480480
if shifts2[i]:
481481
c = (c >> 2) | (c << 26)
@@ -513,9 +513,9 @@ def _body(ks, E0, E1):
513513
# Copy global variable into locals for loop.
514514
SP0, SP1, SP2, SP3, SP4, SP5, SP6, SP7 = _SPtrans
515515

516-
inner = range(0, _ITERATIONS*2, 2)
516+
inner = xrange(0, _ITERATIONS*2, 2)
517517
l = r = 0
518-
for j in range(25):
518+
for j in xrange(25):
519519
l,r = r,l
520520
for i in inner:
521521
t = r ^ ((r >> 16) & 0xffff)
@@ -602,7 +602,7 @@ def crypt(password, salt):
602602
t2 >> 18 & 0x3f, t2 >> 12 & 0x3f, t2 >> 6 & 0x3f, t2 & 0x3f,
603603
t3 >> 18 & 0x3f, t3 >> 12 & 0x3f, t3 >> 6 & 0x3f ]
604604
# Convert to characters.
605-
for i in range(len(r)):
605+
for i in xrange(len(r)):
606606
r[i] = _cov_2char[r[i]]
607607
return salt[:2] + string.join(r, '')
608608

extra/mssqlsig/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def updateMSSQLXML():
5757
root = doc.createElement("root")
5858
doc.appendChild(root)
5959

60-
for index in range(0, releasesCount):
60+
for index in xrange(0, releasesCount):
6161
release = releases[index]
6262

6363
# Skip Microsoft SQL Server 6.5 because the HTML

extra/pagerank/pagerank.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def get_pagerank(url):
2323
rank = '0'
2424
return rank
2525

26-
def int_str(string, integer, factor):
27-
for i in range(len(string)) :
26+
def int_str(string_, integer, factor):
27+
for i in xrange(len(string_)) :
2828
integer *= factor
2929
integer &= 0xFFFFFFFF
30-
integer += ord(string[i])
30+
integer += ord(string_[i])
3131
return integer
3232

33-
def hash_url(string):
34-
c1 = int_str(string, 0x1505, 0x21)
35-
c2 = int_str(string, 0, 0x1003F)
33+
def hash_url(string_):
34+
c1 = int_str(string_, 0x1505, 0x21)
35+
c2 = int_str(string_, 0, 0x1003F)
3636

3737
c1 >>= 2
3838
c1 = ((c1 >> 4) & 0x3FFFFC0) | (c1 & 0x3F)

extra/safe2bin/safe2bin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def safecharencode(value):
4040
retVal = value
4141

4242
if isinstance(value, basestring):
43-
4443
retVal = retVal.replace('\\', SLASH_MARKER)
4544

4645
for char in SAFE_ENCODE_SLASH_REPLACEMENTS:

0 commit comments

Comments
 (0)