17 const bp::object Path = bp::import(
"pathlib").attr(
"Path");
19 if (PyObject_IsInstance(str_path.ptr(), Path.ptr()))
20 str_path = str_path.attr(
"__str__")();
22 if (!PyObject_IsInstance(str_path.ptr(),
reinterpret_cast<PyObject *
>(&PyUnicode_Type)))
24 std::string what = bp::extract<std::string>(str_path.attr(
"__str__")())();
25 throw std::invalid_argument(what +
" is neither a Path nor a str.");
28 return bp::extract<std::string>(str_path);
31 std::vector<std::string>
pathList(
const bp::object & path_list)
33 if (!PyList_Check(path_list.ptr()))
35 std::string what = bp::extract<std::string>(path_list.attr(
"__str__")())();
36 throw std::invalid_argument(what +
" is not a list.");
40 bp::object bp_obj(bp::handle<>(bp::borrowed(path_list.ptr())));
41 bp::list bp_list(bp_obj);
42 bp::ssize_t list_size = bp::len(bp_list);
44 std::vector<std::string> path_vec;
45 path_vec.reserve(list_size);
47 for (bp::ssize_t k = 0; k < list_size; ++k)
49 path_vec.push_back(
path(bp_list[k]));