401 std::ostringstream ss;
403 if(PyBytes_Check(obj)) {
407 ss <<
"\"" << PyBytes_AsString(obj) <<
"\"";
410 else if(PyUnicode_Check(obj)) {
415 ss <<
"\"" << PyBytes_AsString(bytes) <<
"\"";
418 else if(PyDict_Check(obj)) {
428 int n = PyList_Size(keys);
430 for(
int i=0; i<
n; ++i) {
431 PyObject* key = PyList_GetItem(keys, i);
432 int keylen = python_string_len(key);
433 if(keylen > keymaxlen)
439 bool outer = (pos == 0 && indent == 0);
445 for(
int i=0; i<
n; ++i) {
446 PyObject* key = PyList_GetItem(keys, i);
448 std::string ks = python_to_cxx_str(key);
449 ss << std::setw(indent) <<
""
450 << std::setw(keymaxlen) <<
std::left << ks <<
" : "
451 <<
format(value, indent + keymaxlen + 3, indent+2, maxlen, depth+1)
457 ss << std::setw(indent-1) <<
std::right <<
'}';
463 else if(PyList_Check(obj) || PyTuple_Check(obj)) {
471 if(PyList_Check(obj)) {
474 n = PyList_Size(obj);
479 n = PyTuple_Size(obj);
484 std::string sep(1, open_seq);
485 unsigned int break_indent = pos+1;
486 for(
int i=0; i<
n; ++i) {
489 PyObject* ele = PySequence_GetItem(obj, i);
493 std::string f =
format(ele, pos, break_indent, maxlen, depth+1);
497 std::string::size_type fs = f.size();
498 std::string::size_type n1 = std::min(f.find(
'\n'), fs);
505 bool force_break = PyList_Check(ele) || PyTuple_Check(ele) || PyDict_Check(ele);
506 if(i > 0 && (force_break || pos + n1 > maxlen)) {
507 ss <<
'\n' << std::setw(break_indent) <<
"";
509 f =
format(ele, pos, break_indent, maxlen, depth+1);
520 std::string::size_type n2 = f.find_last_of(
'\n');
526 sep = std::string(
", ");
541 PyObject* pystr = PyObject_Str(obj);
542 std::string
s = python_to_cxx_str(pystr);
546 if(s == std::string(
"True"))
548 else if(s == std::string(
"False"))
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
then echo File list $list not found else cat $list while read file do echo $file sed s
byte bytes
Alias for common language habits.