diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-02-10 19:56:53 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-02-10 19:56:53 +0100 |
commit | cf59fcb049c222f20563301a6cf24ebe0ff1eadf (patch) | |
tree | a61be31cd0303fe3a2d06d0b8f1815c348dd3458 /src/exiv2wrapper.cpp | |
parent | f244656175547b3c9b4b7af55be0efeca68c32e3 (diff) | |
download | pyexiv2-cf59fcb049c222f20563301a6cf24ebe0ff1eadf.tar.gz |
Raise an IOError when trying to read an image of an unknown type.
Diffstat (limited to 'src/exiv2wrapper.cpp')
-rw-r--r-- | src/exiv2wrapper.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index ab52892..8c63701 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -41,36 +41,51 @@ namespace exiv2wrapper { -// Base constructor -Image::Image(const std::string& filename) +void Image::_instantiate_image() { + bool success = true; + int error_code; + // Release the GIL to allow other python threads to run // while opening the file. Py_BEGIN_ALLOW_THREADS - _filename = filename; - _image = Exiv2::ImageFactory::open(filename); - assert(_image.get() != 0); - _dataRead = false; + try + { + _image = Exiv2::ImageFactory::open(_filename); + } + catch (Exiv2::Error& error) + { + success = false; + error_code = error.code(); + } // Re-acquire the GIL Py_END_ALLOW_THREADS + + if (success) + { + assert(_image.get() != 0); + _dataRead = false; + } + else + { + throw Exiv2::Error(error_code, _filename); + } +} + +// Base constructor +Image::Image(const std::string& filename) +{ + _filename = filename; + _instantiate_image(); } // Copy constructor Image::Image(const Image& image) { - // Release the GIL to allow other python threads to run - // while opening the file. - Py_BEGIN_ALLOW_THREADS - _filename = image._filename; - _image = Exiv2::ImageFactory::open(_filename); - assert(_image.get() != 0); - _dataRead = false; - - // Re-acquire the GIL - Py_END_ALLOW_THREADS + _instantiate_image(); } void Image::readMetadata() |