Skip to content

Commit 2bb96f5

Browse files
committed
Cleanup code: remove int/long idioms and simplify a while statement.
1 parent 8d48b43 commit 2bb96f5

5 files changed

Lines changed: 10 additions & 35 deletions

File tree

Lib/ftplib.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ def set_pasv(self, val):
175175

176176
# Internal: "sanitize" a string for printing
177177
def sanitize(self, s):
178-
if s[:5] == 'pass ' or s[:5] == 'PASS ':
179-
i = len(s)
180-
while i > 5 and s[i-1] in {'\r', '\n'}:
181-
i = i-1
178+
if s[:5] in {'pass ', 'PASS '}:
179+
i = len(s.rstrip('\r\n'))
182180
s = s[:5] + '*'*(i-5) + s[i:]
183181
return repr(s)
184182

@@ -596,10 +594,7 @@ def size(self, filename):
596594
resp = self.sendcmd('SIZE ' + filename)
597595
if resp[:3] == '213':
598596
s = resp[3:].strip()
599-
try:
600-
return int(s)
601-
except (OverflowError, ValueError):
602-
return int(s)
597+
return int(s)
603598

604599
def mkd(self, dirname):
605600
'''Make a directory, return its full pathname.'''
@@ -861,11 +856,7 @@ def parse150(resp):
861856
m = _150_re.match(resp)
862857
if not m:
863858
return None
864-
s = m.group(1)
865-
try:
866-
return int(s)
867-
except (OverflowError, ValueError):
868-
return int(s)
859+
return int(m.group(1))
869860

870861

871862
_227_re = None

Lib/optparse.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,8 @@ def _parse_num(val, type):
417417
def _parse_int(val):
418418
return _parse_num(val, int)
419419

420-
def _parse_long(val):
421-
return _parse_num(val, int)
422-
423420
_builtin_cvt = { "int" : (_parse_int, _("integer")),
424-
"long" : (_parse_long, _("long integer")),
421+
"long" : (_parse_int, _("integer")),
425422
"float" : (float, _("floating-point")),
426423
"complex" : (complex, _("complex")) }
427424

Lib/pickletools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,7 @@ def read_decimalnl_short(f):
510510
elif s == b"01":
511511
return True
512512

513-
try:
514-
return int(s)
515-
except OverflowError:
516-
return int(s)
513+
return int(s)
517514

518515
def read_decimalnl_long(f):
519516
r"""

Lib/xdrlib.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ def unpack_uint(self):
141141
data = self.__buf[i:j]
142142
if len(data) < 4:
143143
raise EOFError
144-
x = struct.unpack('>L', data)[0]
145-
try:
146-
return int(x)
147-
except OverflowError:
148-
return x
144+
return struct.unpack('>L', data)[0]
149145

150146
def unpack_int(self):
151147
i = self.__pos

Lib/xmlrpc/client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,6 @@ def dump_nil (self, value, write):
535535
write("<value><nil/></value>")
536536
dispatch[type(None)] = dump_nil
537537

538-
def dump_int(self, value, write):
539-
# in case ints are > 32 bits
540-
if value > MAXINT or value < MININT:
541-
raise OverflowError("int exceeds XML-RPC limits")
542-
write("<value><int>")
543-
write(str(value))
544-
write("</int></value>\n")
545-
#dispatch[int] = dump_int
546-
547538
def dump_bool(self, value, write):
548539
write("<value><boolean>")
549540
write(value and "1" or "0")
@@ -558,6 +549,9 @@ def dump_long(self, value, write):
558549
write("</int></value>\n")
559550
dispatch[int] = dump_long
560551

552+
# backward compatible
553+
dump_int = dump_long
554+
561555
def dump_double(self, value, write):
562556
write("<value><double>")
563557
write(repr(value))

0 commit comments

Comments
 (0)