[Python-Dev] cpython: Fix findnocoding.p and pysource.py scripts
Victor Stinner
victor.stinner at gmail.com
Thu Aug 2 00:12:17 CEST 2012
2012/8/1 Serhiy Storchaka <storchaka at gmail.com>:
>> changeset: 78375:67d36e8ddcfc
>> Fix findnocoding.p and pysource.py scripts
>>
>
>> - line1 = infile.readline()
>> - line2 = infile.readline()
>> + with infile:
>> + line1 = infile.readline()
>> + line2 = infile.readline()
>>
>> - if get_declaration(line1) or get_declaration(line2):
>> - # the file does have an encoding declaration, so trust it
>> - infile.close()
>> - return False
>> + if get_declaration(line1) or get_declaration(line2):
>> + # the file does have an encoding declaration, so trust it
>> + infile.close()
>> + return False
>
> infile.close() is unnecessary here.
Ah yes correct, I forgot this one. The new changeset 8ace059cdffd removes it.
It is not perfect, there is still a race condition in
looks_like_python() (pysource.py) if KeyboardInterrupt occurs between
the file is opened and the beginning of the "with infile" block, but
it don't think that it is really important ;-)
Victor
More information about the Python-Dev
mailing list