iniparse fail on empty files.

2 views
Skip to first unread message

Tim Lauridsen

unread,
Oct 1, 2007, 4:18:28 AM10/1/07
to iniparse...@googlegroups.com
If you use iniparse with an empty file then you get this Traceback.

parser.readfp(confpp_obj)
File "/usr/lib/python2.5/site-packages/iniparse/compat.py", line 106, in readfp
self.data.readfp(fp)
File "/usr/lib/python2.5/site-packages/iniparse/ini.py", line 563, in readfp
if line and line[-1]=='\n':
UnboundLocalError: local variable 'line' referenced before assignment

I have attached a patch to fix it, please check if it look ok, before i commit it.

Tim


iniparse-empty-file.patch

Paramjit Oberoi

unread,
Oct 1, 2007, 10:59:57 AM10/1/07
to iniparse...@googlegroups.com
This change makes some tests fail... It's really to run the tests -
from the iniparse directory, just type './runtests.py'. They run
pretty quickly too - it takes 0.3 seconds on my machine.

Regarding the problem: How about just initializing 'line' to 'None'
before the loop?

Also, could you add a test to test_misc.py that checks that an empty
file is parsed and written out correctly?

Thanks,
-param

Tim Lauridsen

unread,
Oct 2, 2007, 4:43:12 AM10/2/07
to iniparse...@googlegroups.com
Paramjit Oberoi wrote:
> This change makes some tests fail... It's really to run the tests -
> from the iniparse directory, just type './runtests.py'. They run
> pretty quickly too - it takes 0.3 seconds on my machine.
>
> Regarding the problem: How about just initializing 'line' to 'None'
> before the loop?
>
Yes, i though it was some indentation issue, i should have run the
tests. :)

> Also, could you add a test to test_misc.py that checks that an empty
> file is parsed and written out correctly?
>
> Thanks,
> -param
>
Here is a new patch there fixes the issue, and also contains a test case
for an empty file.

Tim

iniparse-empty-file.patch

Paramjit Oberoi

unread,
Oct 2, 2007, 10:52:46 AM10/2/07
to iniparse...@googlegroups.com
Looks good.

Tim Lauridsen

unread,
Oct 2, 2007, 11:58:11 AM10/2/07
to iniparse...@googlegroups.com
Paramjit Oberoi wrote:
> Looks good.
>
OK, committed

Tim

Reply all
Reply to author
Forward
0 new messages