cpython: 67053b135ed9 (original) (raw)
Mercurial > cpython
changeset 73076:67053b135ed9
Cleanup code: remove int/long idioms and simplify a while statement.
Florent Xicluna florent.xicluna@gmail.com | |
---|---|
date | Sun, 23 Oct 2011 22:11:00 +0200 |
parents | d4839fea4a5a |
children | 94e275e6450c |
files | Lib/ftplib.py Lib/optparse.py Lib/pickletools.py Lib/xdrlib.py Lib/xmlrpc/client.py |
diffstat | 5 files changed, 10 insertions(+), 35 deletions(-)[+] [-] Lib/ftplib.py 17 Lib/optparse.py 5 Lib/pickletools.py 5 Lib/xdrlib.py 6 Lib/xmlrpc/client.py 12 |
line wrap: on
line diff
--- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -175,10 +175,8 @@ class FTP: # Internal: "sanitize" a string for printing def sanitize(self, s):
if s[:5] == 'pass ' or s[:5] == 'PASS ':[](#l1.7)
i = len(s)[](#l1.8)
while i > 5 and s[i-1] in {'\r', '\n'}:[](#l1.9)
i = i-1[](#l1.10)
if s[:5] in {'pass ', 'PASS '}:[](#l1.11)
i = len(s.rstrip('\r\n'))[](#l1.12) s = s[:5] + '*'*(i-5) + s[i:][](#l1.13) return repr(s)[](#l1.14)
@@ -596,10 +594,7 @@ class FTP: resp = self.sendcmd('SIZE ' + filename) if resp[:3] == '213': s = resp[3:].strip()
try:[](#l1.20)
return int(s)[](#l1.21)
except (OverflowError, ValueError):[](#l1.22)
return int(s)[](#l1.23)
return int(s)[](#l1.24)
def mkd(self, dirname): '''Make a directory, return its full pathname.''' @@ -861,11 +856,7 @@ def parse150(resp): m = _150_re.match(resp) if not m: return None
- s = m.group(1)
- try:
return int(s)[](#l1.34)
- except (OverflowError, ValueError):
return int(s)[](#l1.36)
--- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -417,11 +417,8 @@ def _parse_num(val, type): def _parse_int(val): return _parse_num(val, int) -def _parse_long(val):
- _builtin_cvt = { "int" : (_parse_int, _("integer")),
"long" : (_parse_long, _("long integer")),[](#l2.11)
"long" : (_parse_int, _("integer")),[](#l2.12) "float" : (float, _("floating-point")),[](#l2.13) "complex" : (complex, _("complex")) }[](#l2.14)
--- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -510,10 +510,7 @@ def read_decimalnl_short(f): elif s == b"01": return True
def read_decimalnl_long(f): r"""
--- a/Lib/xdrlib.py +++ b/Lib/xdrlib.py @@ -141,11 +141,7 @@ class Unpacker: data = self.__buf[i:j] if len(data) < 4: raise EOFError
x = struct.unpack('>L', data)[0][](#l4.7)
try:[](#l4.8)
return int(x)[](#l4.9)
except OverflowError:[](#l4.10)
return x[](#l4.11)
return struct.unpack('>L', data)[0][](#l4.12)
def unpack_int(self): i = self.__pos
--- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -535,15 +535,6 @@ class Marshaller: write("") dispatch[type(None)] = dump_nil
- def dump_int(self, value, write):
# in case ints are > 32 bits[](#l5.8)
if value > MAXINT or value < MININT:[](#l5.9)
raise OverflowError("int exceeds XML-RPC limits")[](#l5.10)
write("<value><int>")[](#l5.11)
write(str(value))[](#l5.12)
write("</int></value>\n")[](#l5.13)
- #dispatch[int] = dump_int
- def dump_bool(self, value, write): write("") write(value and "1" or "0") @@ -558,6 +549,9 @@ class Marshaller: write("\n") dispatch[int] = dump_long
+ def dump_double(self, value, write): write("") write(repr(value))