]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/dict.cpp
4f3490a42189152e239a65cbd8431ea43b637255
1 // Copyright David Abrahams 2004. Distributed under the Boost
2 // Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 #include <boost/python/module.hpp>
5 #define BOOST_ENABLE_ASSERT_HANDLER
6 #include <boost/assert.hpp>
8 #include <boost/python/def.hpp>
9 #include <boost/python/class.hpp>
10 #include <boost/python/dict.hpp>
14 using namespace boost::python
;
26 tmp2
["key2"] = "value2";
29 tmp1
["key1"] = "value1";
34 object
dict_from_sequence(object sequence
)
36 return dict(sequence
);
39 object
dict_keys(dict data
)
44 object
dict_values(dict data
)
49 object
dict_items(dict data
)
54 void work_with_dict(dict data1
, dict data2
)
56 if (!data1
.has_key("k1")) {
57 throw std::runtime_error("dict does not have key 'k1'");
62 void test_templates(object print
)
64 std::string key
= "key";
69 tmp
[1] = "a test string";
73 print(tmp
.get(2,"default"));
74 print(tmp
.setdefault(3,"default"));
76 BOOST_ASSERT(!tmp
.has_key(key
));
79 BOOST_PYTHON_MODULE(dict_ext
)
81 def("new_dict", new_dict
);
82 def("data_dict", data_dict
);
83 def("dict_keys", dict_keys
);
84 def("dict_values", dict_values
);
85 def("dict_items", dict_items
);
86 def("dict_from_sequence", dict_from_sequence
);
87 def("work_with_dict", work_with_dict
);
88 def("test_templates", test_templates
);
91 #include "module_tail.cpp"