Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

Re: cpython: Fix findnocoding.p and pysource.py scripts

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


storchaka at gmail

Aug 1, 2012, 1:52 PM

Post #1 of 2 (106 views)
Permalink
Re: cpython: Fix findnocoding.p and pysource.py scripts

On 01.08.12 21:16, victor.stinner wrote:
> http://hg.python.org/cpython/rev/67d36e8ddcfc
> changeset: 78375:67d36e8ddcfc
> user: Victor Stinner <victor.stinner [at] gmail>
> date: Wed Aug 01 20:12:51 2012 +0200
> summary:
> Fix findnocoding.p and pysource.py scripts
>
> I suppose that these scripts didn't work since Python 3.0.

> - 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.
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


victor.stinner at gmail

Aug 1, 2012, 3:12 PM

Post #2 of 2 (101 views)
Permalink
Re: cpython: Fix findnocoding.p and pysource.py scripts [In reply to]

2012/8/1 Serhiy Storchaka <storchaka [at] gmail>:
>> 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
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.