Hi,
I'm working on a python wrapper for the lib libexiv2
This is the port to Python 3 of pyexiv2 written for Python 2
I've two machines, one 32 bits with these versions:
vincent@tiemoko:~$ dpkg --list | grep libboost
ii libboost-python-dev 1.48.0.2 Boost.Python Library
development files (default version)
ii libboost-python1.46-dev 1.46.1-7ubuntu3 Boost.Python Library
development files
ii libboost-python1.46.1 1.46.1-7ubuntu3 Boost.Python Library
ii libboost-python1.48.0 1.48.0-3 Boost.Python Library
ii libboost1.46-dev 1.46.1-7ubuntu3 Boost C++ Libraries
development files
and one 64 bits (this is my main devel machine):
vincent@djoliba:~$ dpkg --list | grep libboost
ii libboost-date-time1.54.0:amd64 1.54.0-4ubuntu3.1 amd64 set of
date-time libraries
ii libboost-python-dev 1.54.0.1ubuntu1 amd64
Boost.Python Library
ii libboost-python1.54-dev:amd64 1.54.0-4ubuntu3.1 amd64
Boost.Python Library development files
ii libboost-python1.54.0:amd64 1.54.0-4ubuntu3.1 amd64
Boost.Python Library
rc libboost-serialization1.46.1 1.46.1-7ubuntu3 amd64
serialization library for C++
ii libboost-system1.54.0:amd64 1.54.0-4ubuntu3.1 amd64 Operating
system (e.g. diagnostics support) library
ii libboost1.54-dev 1.54.0-4ubuntu3.1 amd64 Boost C++
Libraries development files
It's seems these different versions have different behaviours with the
python string.
On the more recent version, I encode my python string in utf-8 before
send it to the wrapper and that's works fine.
On the 32 bits machine I've this error:
TypeError: No registered converter was able to produce a C++ rvalue of
type std::string from this Python object of type bytes
If I send directly the unicode string to the wrapper, without encoding,
that's solve the problem.
Example:
python:
# xmp tag values are embedded into a list
value = ['déjà vu']
try:
tag._setArrayValue([v.encode('utf-8') for v in value])
except TypeError:
# old libboost-python version
tag._setArrayValue(value)
-------------------------------------------------------------------------
exiv2wrapper_python.cpp
#include "exiv2wrapper.hpp"
#include "exiv2/exv_conf.h"
#include "exiv2/version.hpp"
#include <boost/python.hpp>
using namespace boost::python;
using namespace exiv2wrapper;
BOOST_PYTHON_MODULE(libexiv2python)
{
scope().attr("exiv2_version_info") = \
boost::python::make_tuple(EXIV2_MAJOR_VERSION,
EXIV2_MINOR_VERSION,
EXIV2_PATCH_VERSION);
register_exception_translator<Exiv2::Error>(&translateExiv2Error);
// Swallow all warnings and error messages written by libexiv2 to
stderr
// (if it was compiled with DEBUG or without SUPPRESS_WARNINGS).
// See https://bugs.launchpad.net/pyexiv2/+bug/507620.
std::cerr.rdbuf(NULL);
[skip]
.def("_setArrayValue", &XmpTag::setArrayValue)
---------------------------------------------------------------------------
exiv2wrapper.cpp
#include "exiv2wrapper.hpp"
#include "boost/python/stl_iterator.hpp"
#include <fstream>
[skip]
void XmpTag::setArrayValue(const boost::python::list& values)
{
// Reset the value
_datum->setValue(0);
for(boost::python::stl_input_iterator<std::string> iterator(values);
iterator != boost::python::stl_input_iterator<std::string>();
++iterator)
{
_datum->setValue(*iterator);
}
}
-------------------------------------------------------------------------
Is this difference into two versions is normal ?
I can adapt my python code for that, but how to know the version of
libboost ?
Here I use "dpkg --list | grep libboost" but that's for debian
pacckaging system only and my lib must be run on any os (Windows include).
Thanks for all advices.
Vincent
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig