@@ -45,12 +45,81 @@ namespace boost
45
45
}
46
46
}
47
47
48
+ #include < boost/asio/error.hpp>
49
+ #if defined TORRENT_USE_OPENSSL
50
+ #include < boost/asio/ssl/error.hpp>
51
+ #endif
48
52
#include " boost_python.hpp"
49
53
50
54
using namespace boost ::python;
51
55
using namespace libtorrent ;
52
56
using boost::system::error_category;
53
57
58
+ namespace {
59
+
60
+ struct ec_pickle_suite : boost::python::pickle_suite
61
+ {
62
+ static boost::python::tuple
63
+ getinitargs (error_code const & ec)
64
+ {
65
+ return boost::python::tuple ();
66
+ }
67
+
68
+ static boost::python::tuple
69
+ getstate (error_code const & ec)
70
+ {
71
+ return boost::python::make_tuple (ec.value (), ec.category ().name ());
72
+ }
73
+
74
+ static void
75
+ setstate (error_code& ec, boost::python::tuple state)
76
+ {
77
+ using namespace boost ::python;
78
+ if (len (state) != 2 )
79
+ {
80
+ PyErr_SetObject (PyExc_ValueError,
81
+ (" expected 2-item tuple in call to __setstate__; got %s"
82
+ % state).ptr ());
83
+ throw_error_already_set ();
84
+ }
85
+
86
+ int const value = extract<int >(state[0 ]);
87
+ std::string const category = extract<std::string>(state[1 ]);
88
+ if (category == " system" )
89
+ ec.assign (value, libtorrent::system_category ());
90
+ else if (category == " generic" )
91
+ ec.assign (value, libtorrent::generic_category ());
92
+ else if (category == " libtorrent" )
93
+ ec.assign (value, libtorrent::libtorrent_category ());
94
+ else if (category == " http error" )
95
+ ec.assign (value, libtorrent::http_category ());
96
+ else if (category == " UPnP error" )
97
+ ec.assign (value, libtorrent::upnp_category ());
98
+ else if (category == " bdecode error" )
99
+ ec.assign (value, libtorrent::bdecode_category ());
100
+ else if (category == " asio.netdb" )
101
+ ec.assign (value, boost::asio::error::get_netdb_category ());
102
+ else if (category == " asio.addinfo" )
103
+ ec.assign (value, boost::asio::error::get_addrinfo_category ());
104
+ else if (category == " asio.misc" )
105
+ ec.assign (value, boost::asio::error::get_misc_category ());
106
+ else if (category == " asio.misc" )
107
+ ec.assign (value, boost::asio::error::get_misc_category ());
108
+ #if defined TORRENT_USE_OPENSSL
109
+ else if (category == " asio.ssl" )
110
+ ec.assign (value, boost::asio::error::get_ssl_category ());
111
+ #endif
112
+ else
113
+ {
114
+ PyErr_SetObject (PyExc_ValueError,
115
+ (" unexpected error_category passed to __setstate__; got '%s'"
116
+ % object (category)).ptr ());
117
+ throw_error_already_set ();
118
+ }
119
+ }
120
+ };
121
+ }
122
+
54
123
void bind_error_code ()
55
124
{
56
125
using boost::noncopyable;
@@ -71,6 +140,7 @@ void bind_error_code()
71
140
.def (" category" , &error_code::category
72
141
, return_value_policy<reference_existing_object>())
73
142
.def (" assign" , &error_code::assign)
143
+ .def_pickle (ec_pickle_suite ())
74
144
;
75
145
76
146
using return_existing = return_value_policy<reference_existing_object>;
0 commit comments