Commit 8664f7f2 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix handling of property maps with python::object values with dot and gml formats

parent 8141f5f2
......@@ -29,14 +29,12 @@
#include <set>
#include <unordered_set>
namespace boost
{
// Base64 Encoding
std::string base64_encode(const std::string& s);
std::string base64_decode(const std::string& s);
#include "base64.hh"
namespace boost
{
/////////////////////////////////////////////////////////////////////////////
// Graph reader exceptions
......
......@@ -18,6 +18,7 @@ libgraph_tool_coredir = $(MOD_DIR)
libgraph_tool_core_LTLIBRARIES = libgraph_tool_core.la
libgraph_tool_core_la_SOURCES = \
base64.cc \
graph.cc \
graph_exceptions.cc \
graph_bind.cc \
......@@ -41,6 +42,7 @@ libgraph_tool_core_la_SOURCES = \
libgraph_tool_core_la_includedir = $(MOD_DIR)/include
libgraph_tool_core_la_include_HEADERS = \
../../config.h \
base64.hh \
fast_vector_property_map.hh \
gml.hh \
graph.hh \
......
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2015 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "base64.hh"
#include <sstream>
#include <boost/archive/iterators/ostream_iterator.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
std::string base64_encode(const std::string& s)
{
static const std::string base64_padding[] = {"", "==","="};
namespace bai = boost::archive::iterators;
std::stringstream os;
typedef bai::base64_from_binary<bai::transform_width<const char *, 6, 8> >
base64_enc;
std::copy(base64_enc(s.c_str()), base64_enc(s.c_str() + s.size()),
std::ostream_iterator<char>(os));
os << base64_padding[s.size() % 3];
return os.str();
}
std::string base64_decode(const std::string& s)
{
namespace bai = boost::archive::iterators;
std::stringstream os;
typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec;
unsigned int size = s.size();
// Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629
if (size && s[size - 1] == '=')
{
--size;
if (size && s[size - 1] == '=')
--size;
}
if (size == 0)
return std::string();
std::copy(base64_dec(s.data()), base64_dec(s.data() + size),
std::ostream_iterator<char>(os));
return os.str();
}
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2015 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef BASE64_HH
#define BASE64_HH
#include <string>
std::string base64_encode(const std::string& s);
std::string base64_decode(const std::string& s);
#endif
......@@ -48,6 +48,8 @@
#include <unordered_map>
#include "base64.hh"
namespace graph_tool{
using namespace std;
......@@ -362,7 +364,7 @@ struct get_str
ValueType v = any_cast<ValueType>(val);
if (std::is_same<ValueType, python::object>::value)
{
sval = lexical_cast<string>(v);
sval = base64_encode(lexical_cast<string>(v));
}
else
{
......
......@@ -25,7 +25,6 @@
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/graph/graphml.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/xpressive/xpressive.hpp>
......@@ -79,8 +78,19 @@ python::object lexical_cast<python::object,string>(const string& ps)
o = object_unpickler(IStream(s));
return o;
}
namespace python
{
std::ostringstream& operator<<(std::ostringstream& stream, const boost::python::object& o)
{
stream << base64_encode(lexical_cast<string>(o));
return stream;
}
}
}
#include <boost/graph/graphviz.hpp>
#include "graph_io_binary.hh"
// the following source & sink provide iostream access to python file-like
......
......@@ -16,56 +16,15 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/archive/iterators/xml_escape.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#include <sstream>
#include "base64.hh"
using namespace boost;
namespace boost
{
std::string base64_encode(const std::string& s)
{
static const std::string base64_padding[] = {"", "==","="};
namespace bai = boost::archive::iterators;
std::stringstream os;
typedef bai::base64_from_binary<bai::transform_width<const char *, 6, 8> >
base64_enc;
std::copy(base64_enc(s.c_str()), base64_enc(s.c_str() + s.size()),
std::ostream_iterator<char>(os));
os << base64_padding[s.size() % 3];
return os.str();
}
std::string base64_decode(const std::string& s)
{
namespace bai = boost::archive::iterators;
std::stringstream os;
typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec;
unsigned int size = s.size();
// Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629
if (size && s[size - 1] == '=')
{
--size;
if (size && s[size - 1] == '=')
--size;
}
if (size == 0)
return std::string();
std::copy(base64_dec(s.data()), base64_dec(s.data() + size),
std::ostream_iterator<char>(os));
return os.str();
}
std::string protect_xml_string(const std::string& os)
{
using namespace boost::archive::iterators;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment