|
a/src/python/recoll/pyrecoll.cpp |
|
b/src/python/recoll/pyrecoll.cpp |
|
... |
|
... |
607 |
}
|
607 |
}
|
608 |
|
608 |
|
609 |
static int
|
609 |
static int
|
610 |
Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
610 |
Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
611 |
{
|
611 |
{
|
612 |
LOGDEB0(("Doc_setattr: doc %p\n", self->doc));
|
|
|
613 |
if (self->doc == 0 || the_docs.find(self->doc) == the_docs.end()) {
|
612 |
if (self->doc == 0 || the_docs.find(self->doc) == the_docs.end()) {
|
614 |
PyErr_SetString(PyExc_AttributeError, "doc??");
|
613 |
PyErr_SetString(PyExc_AttributeError, "doc??");
|
615 |
return -1;
|
614 |
return -1;
|
616 |
}
|
615 |
}
|
617 |
if (!rclconfig || !rclconfig->ok()) {
|
616 |
if (!rclconfig || !rclconfig->ok()) {
|
618 |
PyErr_SetString(PyExc_EnvironmentError,
|
617 |
PyErr_SetString(PyExc_EnvironmentError,
|
619 |
"Configuration not initialized");
|
618 |
"Configuration not initialized");
|
620 |
return -1;
|
619 |
return -1;
|
621 |
}
|
620 |
}
|
|
|
621 |
if (name == 0) {
|
|
|
622 |
PyErr_SetString(PyExc_AttributeError, "name??");
|
|
|
623 |
return -1;
|
|
|
624 |
}
|
622 |
|
625 |
|
623 |
#if PY_MAJOR_VERSION < 3
|
|
|
624 |
if (PyString_Check(value)) {
|
626 |
if (PyBytes_Check(value)) {
|
625 |
value = PyUnicode_FromObject(value);
|
627 |
value = PyUnicode_FromEncodedObject(value, "UTF-8", "strict");
|
626 |
if (value == 0)
|
628 |
if (value == 0)
|
627 |
return -1;
|
629 |
return -1;
|
628 |
}
|
630 |
}
|
629 |
#endif
|
|
|
630 |
|
631 |
|
631 |
if (!PyUnicode_Check(value)) {
|
632 |
if (!PyUnicode_Check(value)) {
|
632 |
PyErr_SetString(PyExc_AttributeError, "value not str/unicode??");
|
633 |
PyErr_SetString(PyExc_AttributeError, "value not unicode??");
|
633 |
return -1;
|
|
|
634 |
}
|
|
|
635 |
if (name == 0) {
|
|
|
636 |
PyErr_SetString(PyExc_AttributeError, "name??");
|
|
|
637 |
return -1;
|
634 |
return -1;
|
638 |
}
|
635 |
}
|
639 |
|
636 |
|
640 |
PyObject* putf8 = PyUnicode_AsUTF8String(value);
|
637 |
PyObject* putf8 = PyUnicode_AsUTF8String(value);
|
641 |
if (putf8 == 0) {
|
638 |
if (putf8 == 0) {
|
642 |
LOGERR(("Doc_setmeta: encoding to utf8 failed\n"));
|
639 |
LOGERR(("Doc_setmeta: encoding to utf8 failed\n"));
|
643 |
PyErr_SetString(PyExc_AttributeError, "value??");
|
640 |
PyErr_SetString(PyExc_AttributeError, "value??");
|
644 |
return -1;
|
641 |
return -1;
|
645 |
}
|
642 |
}
|
646 |
char* uvalue = PyBytes_AsString(putf8);
|
643 |
char* uvalue = PyBytes_AsString(putf8);
|
647 |
Py_DECREF(putf8);
|
|
|
648 |
string key = rclconfig->fieldQCanon(string(name));
|
644 |
string key = rclconfig->fieldQCanon(string(name));
|
649 |
|
645 |
|
650 |
LOGDEB0(("Doc_setattr: [%s] (%s) -> [%s]\n", key.c_str(), name, uvalue));
|
646 |
LOGDEB0(("Doc_setattr: doc %p [%s] (%s) -> [%s]\n",
|
|
|
647 |
self->doc, key.c_str(), name, uvalue));
|
|
|
648 |
|
651 |
// We set the value in the meta array in all cases. Good idea ? or do it
|
649 |
// We set the value in the meta array in all cases. Good idea ? or do it
|
652 |
// only for fields without a dedicated Doc:: entry?
|
650 |
// only for fields without a dedicated Doc:: entry?
|
653 |
self->doc->meta[key] = uvalue;
|
651 |
self->doc->meta[key] = uvalue;
|
654 |
switch (key.at(0)) {
|
652 |
switch (key.at(0)) {
|
655 |
case 't':
|
653 |
case 't':
|
|
... |
|
... |
699 |
} else if (!key.compare(Rcl::Doc::keysz)) {
|
697 |
} else if (!key.compare(Rcl::Doc::keysz)) {
|
700 |
self->doc->dbytes = uvalue;
|
698 |
self->doc->dbytes = uvalue;
|
701 |
}
|
699 |
}
|
702 |
break;
|
700 |
break;
|
703 |
}
|
701 |
}
|
|
|
702 |
Py_DECREF(putf8);
|
704 |
return 0;
|
703 |
return 0;
|
705 |
}
|
704 |
}
|
706 |
|
705 |
|
707 |
|
706 |
|
708 |
PyDoc_STRVAR(doc_DocObject,
|
707 |
PyDoc_STRVAR(doc_DocObject,
|