MCPcopy Create free account
hub / github.com/arvidn/libtorrent / entry_from_python

Class entry_from_python

bindings/python/src/entry.cpp:75–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73};
74
75struct entry_from_python
76{
77 entry_from_python()
78 {
79 converter::registry::push_back(
80 &convertible, &construct, type_id<entry>()
81 );
82 }
83
84 static void* convertible(PyObject* e)
85 {
86 return e;
87 }
88
89 static entry construct0(object e)
90 {
91 if (extract<dict>(e).check())
92 {
93 dict d = extract<dict>(e);
94 list items(d.items());
95 std::size_t length = extract<std::size_t>(items.attr("__len__")());
96 entry result(entry::dictionary_t);
97
98 for (std::size_t i = 0; i < length; ++i)
99 {
100 if (extract<bytes>(items[i][0]).check())
101 {
102 result.dict().insert(
103 std::make_pair(
104 extract<bytes>(items[i][0])().arr,
105 construct0(items[i][1])
106 )
107 );
108 }
109 else
110 {
111 result.dict().insert(
112 std::make_pair(
113 extract<char const*>(items[i][0])(),
114 construct0(items[i][1])
115 )
116 );
117 }
118 }
119
120 return result;
121 }
122 else if (extract<list>(e).check())
123 {
124 list l = extract<list>(e);
125
126 std::size_t length = extract<std::size_t>(l.attr("__len__")());
127 entry result(entry::list_t);
128
129 for (std::size_t i = 0; i < length; ++i)
130 {
131 result.list().push_back(construct0(l[i]));
132 }

Callers 1

bind_entryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected