[Python-checkins] Case consistency [was: Re: cpython: Cleanup code: remove int/long idioms and simplify a while statement.]
Eric V. Smith
eric at trueblade.com
Mon Oct 24 20:10:52 CEST 2011
On 10/24/2011 1:04 PM, Jim Jewett wrote:
> Is there a reason to check for
> if s[:5] == 'pass ' or s[:5] == 'PASS ':
> instead of
> if s[:5].lower() == 'pass'
> ?
Just in case anyone copies this code verbatim, note that last string is
missing a trailing space.
Eric.
>
> If so, it should be documented; otherwise, I would rather see the more
> inclusive form, that would also allow things like "Pass"
>
> -jJ
>
>
> On Sun, Oct 23, 2011 at 4:21 PM, florent.xicluna
> <python-checkins at python.org> wrote:
>> http://hg.python.org/cpython/rev/67053b135ed9
>> changeset: 73076:67053b135ed9
>> user: Florent Xicluna <florent.xicluna at gmail.com>
>> date: Sun Oct 23 22:11:00 2011 +0200
>> summary:
>> Cleanup code: remove int/long idioms and simplify a while statement.
>
>> diff --git a/Lib/ftplib.py b/Lib/ftplib.py
>> --- a/Lib/ftplib.py
>> +++ b/Lib/ftplib.py
>> @@ -175,10 +175,8 @@
>>
>> # Internal: "sanitize" a string for printing
>> def sanitize(self, s):
>> - if s[:5] == 'pass ' or s[:5] == 'PASS ':
>> - i = len(s)
>> - while i > 5 and s[i-1] in {'\r', '\n'}:
>> - i = i-1
>> + if s[:5] in {'pass ', 'PASS '}:
>> + i = len(s.rstrip('\r\n'))
>> s = s[:5] + '*'*(i-5) + s[i:]
>> return repr(s)
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
More information about the Python-checkins
mailing list