pombreda / python-xmp-toolkit

Automatically exported from code.google.com/p/python-xmp-toolkit
Other
0 stars 1 forks source link

file_to_dict does not raise IOError on receiving non existent file #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. from libxmp.utils import *
2. x = file_to_dict('file_that_does_not_exist')
3. print x

What is the expected output? What do you see instead?
Would have expected that IOError would be raised. Instead, x is returned as
an empty dict

What version of the product are you using? On what operating system?
svn trunk
Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on openSUSE 11.1

Please provide any additional information below.
Not sure if it was intended to return an empty dict if you use file_to_dict
on a non-existent file. I thus modified utils.py to import os to do a
simple if not os.path.isfile('non_existent_file'): raise IOError

I also changed object_to_dict to return an empty dictionary if xmp is None
or if xmp is a list containing no elements. Otherwise, an exception will be
raised when the method looks for xmp[-1]

I built the package (from svn trunk, including the patch already provided
for the xmpfile.open_file(file_path,
XMP_OPEN_READ=libxmp.files.XMP_OPEN_READ) issue in file_to_dict in
utils.py) for openSUSE using the openSUSE build service. Currently it's
available with one-click-install here:
http://is.gd/1QoLR

The patch I used is attached here.

If the above was expected behaviour, please tell me and i will remove the
patch from the openSUSE version

Original issue reported on code.google.com by cfarrell...@gmail.com on 28 Jul 2009 at 10:43

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

I've incorporated you changes with the exception of 

    elif isinstance( xmp, list ):
        if len( xmp ) == 0:
            return {}

in object_to_dict, since the first (if not xmp) part also catches empty lists. 
Let me know if you have bug where 
this is not the case. I'll hopefully be releasing RC2 a bit later today. Also 
we plan to make a final 1.0 release in 
mid-March. Then we've had a chance to use the library in 3 larger production 
environments.

Original comment by lniel...@spacetelescope.org on 16 Feb 2010 at 4:38