| 63 | namespace { |
| 64 | |
| 65 | struct ec_pickle_suite : boost::python::pickle_suite |
| 66 | { |
| 67 | static boost::python::tuple |
| 68 | getinitargs(error_code const&) |
| 69 | { |
| 70 | return boost::python::tuple(); |
| 71 | } |
| 72 | |
| 73 | static boost::python::tuple |
| 74 | getstate(error_code const& ec) |
| 75 | { |
| 76 | return boost::python::make_tuple(ec.value(), ec.category().name()); |
| 77 | } |
| 78 | |
| 79 | static void |
| 80 | setstate(error_code& ec, boost::python::tuple state) |
| 81 | { |
| 82 | using namespace boost::python; |
| 83 | if (len(state) != 2) |
| 84 | { |
| 85 | PyErr_SetObject(PyExc_ValueError, |
| 86 | ("expected 2-item tuple in call to __setstate__; got %s" |
| 87 | % state).ptr()); |
| 88 | throw_error_already_set(); |
| 89 | } |
| 90 | |
| 91 | int const value = extract<int>(state[0]); |
| 92 | std::string const category = extract<std::string>(state[1]); |
| 93 | if (category == "system") |
| 94 | ec.assign(value, lt::system_category()); |
| 95 | else if (category == "generic") |
| 96 | ec.assign(value, lt::generic_category()); |
| 97 | else if (category == "libtorrent") |
| 98 | ec.assign(value, lt::libtorrent_category()); |
| 99 | else if (category == "http error") |
| 100 | ec.assign(value, lt::http_category()); |
| 101 | else if (category == "UPnP error") |
| 102 | ec.assign(value, lt::upnp_category()); |
| 103 | else if (category == "bdecode error") |
| 104 | ec.assign(value, lt::bdecode_category()); |
| 105 | else if (category == "asio.netdb") |
| 106 | ec.assign(value, boost::asio::error::get_netdb_category()); |
| 107 | else if (category == "asio.addinfo") |
| 108 | ec.assign(value, boost::asio::error::get_addrinfo_category()); |
| 109 | else if (category == "asio.misc") |
| 110 | ec.assign(value, boost::asio::error::get_misc_category()); |
| 111 | #if TORRENT_USE_SSL |
| 112 | else if (category == "asio.ssl") |
| 113 | ec.assign(value, boost::asio::error::get_ssl_category()); |
| 114 | #endif |
| 115 | else |
| 116 | { |
| 117 | PyErr_SetObject(PyExc_ValueError, |
| 118 | ("unexpected error_category passed to __setstate__; got '%s'" |
| 119 | % object(category)).ptr()); |
| 120 | throw_error_already_set(); |
| 121 | } |
| 122 | } |