a/src/python/recoll/pyrecoll.cpp b/src/python/recoll/pyrecoll.cpp
...
...
293
    return -1;
293
    return -1;
294
    the_docs.insert(self->doc);
294
    the_docs.insert(self->doc);
295
    return 0;
295
    return 0;
296
}
296
}
297
297
298
PyDoc_STRVAR(doc_getbinurl,
299
"getbinurl(none) -> binary url\n"
300
"\n"
301
"Returns an URL with a path part which is a as bit for bit copy of the \n"
302
"file system path, without encoding\n"
303
);
304
305
static PyObject *
306
Doc_getbinurl(recoll_DocObject *self)
307
{
308
    LOGDEB(("Doc_getbinurl\n"));
309
    if (self->doc == 0 || 
310
  the_docs.find(self->doc) == the_docs.end()) {
311
        PyErr_SetString(PyExc_AttributeError, "doc");
312
  return 0;
313
    }
314
    return PyByteArray_FromStringAndSize(self->doc->url.c_str(), 
315
                   self->doc->url.size());
316
}
317
318
PyDoc_STRVAR(doc_setbinurl,
319
"setbinurl(url) -> binary url\n"
320
"\n"
321
"Set the URL from binary path like file://may/contain/unencodable/bytes\n"
322
);
323
324
static int
325
Doc_setbinurl(recoll_DocObject *self, PyObject *value)
326
{
327
    if (self->doc == 0 || 
328
  the_docs.find(self->doc) == the_docs.end()) {
329
        PyErr_SetString(PyExc_AttributeError, "doc??");
330
  return -1;
331
    }
332
333
    self->doc->url = string(PyByteArray_AsString(value),
334
              PyByteArray_Size(value));
335
    return 0;
336
}
337
338
339
static PyMethodDef Doc_methods[] = {
340
    {"getbinurl", (PyCFunction)Doc_getbinurl, METH_NOARGS,
341
     doc_getbinurl},
342
    {"setbinurl", (PyCFunction)Doc_setbinurl, METH_O,
343
     doc_setbinurl},
344
    {NULL}  /* Sentinel */
345
};
346
298
static PyObject *
347
static PyObject *
299
Doc_getattr(recoll_DocObject *self, char *name)
348
Doc_getattr(recoll_DocObject *self, char *name)
300
{
349
{
301
    LOGDEB(("Doc_getattr: name [%s]\n", name));
350
    LOGDEB(("Doc_getattr: name [%s]\n", name));
302
    if (self->doc == 0 || 
351
    if (self->doc == 0 || 
...
...
310
    LOGDEB(("meta[%s] -> [%s]\n", it->first.c_str(), it->second.c_str()));
359
    LOGDEB(("meta[%s] -> [%s]\n", it->first.c_str(), it->second.c_str()));
311
    }
360
    }
312
#endif
361
#endif
313
    string key = rclconfig->fieldCanon(string(name));
362
    string key = rclconfig->fieldCanon(string(name));
314
363
315
    // Handle special cases, then try retrieving key value from meta 
364
    // Handle special cases, then check this is not a method then
316
    // array
365
    // try retrieving key value from the meta array
366
317
    string value;
367
    string value;
368
    bool found = false;
318
    switch (key.at(0)) {
369
    switch (key.at(0)) {
319
    case 'u':
370
    case 'u':
320
    if (!key.compare(Rcl::Doc::keyurl)) {
371
    if (!key.compare(Rcl::Doc::keyurl)) {
321
        value = self->doc->url;
372
        value = self->doc->url; found = true;
322
    }
373
    }
323
    break;
374
    break;
324
    case 'f':
375
    case 'f':
325
    if (!key.compare(Rcl::Doc::keyfs)) {
376
    if (!key.compare(Rcl::Doc::keyfs)) {
326
        value = self->doc->fbytes;
377
        value = self->doc->fbytes; found = true;
327
    } else if (!key.compare(Rcl::Doc::keyfs)) {
378
    } else if (!key.compare(Rcl::Doc::keyfs)) {
328
        value = self->doc->fbytes;
379
        value = self->doc->fbytes; found = true;
329
    } else if (!key.compare(Rcl::Doc::keyfmt)) {
380
    } else if (!key.compare(Rcl::Doc::keyfmt)) {
330
        value = self->doc->fmtime;
381
        value = self->doc->fmtime; found = true;
331
    }
382
    }
332
    break;
383
    break;
333
    case 'd':
384
    case 'd':
334
    if (!key.compare(Rcl::Doc::keyds)) {
385
    if (!key.compare(Rcl::Doc::keyds)) {
335
        value = self->doc->dbytes;
386
        value = self->doc->dbytes; found = true;
336
    } else if (!key.compare(Rcl::Doc::keydmt)) {
387
    } else if (!key.compare(Rcl::Doc::keydmt)) {
337
        value = self->doc->dmtime;
388
        value = self->doc->dmtime; found = true;
338
    }
389
    }
339
    break;
390
    break;
340
    case 'i':
391
    case 'i':
341
    if (!key.compare(Rcl::Doc::keyipt)) {
392
    if (!key.compare(Rcl::Doc::keyipt)) {
342
        value = self->doc->ipath;
393
        value = self->doc->ipath; found = true;
343
    }
394
    }
344
    break;
395
    break;
345
    case 'm':
396
    case 'm':
346
    if (!key.compare(Rcl::Doc::keytp)) {
397
    if (!key.compare(Rcl::Doc::keytp)) {
347
        value = self->doc->mimetype;
398
        value = self->doc->mimetype; found = true;
348
    } else if (!key.compare(Rcl::Doc::keymt)) {
399
    } else if (!key.compare(Rcl::Doc::keymt)) {
349
        value = self->doc->dmtime.empty() ? self->doc->fmtime : 
400
        value = self->doc->dmtime.empty() ? self->doc->fmtime : 
350
        self->doc->dmtime;
401
        self->doc->dmtime; found = true;
351
    }
402
    }
352
    break;
403
    break;
353
    case 'o':
404
    case 'o':
354
    if (!key.compare(Rcl::Doc::keyoc)) {
405
    if (!key.compare(Rcl::Doc::keyoc)) {
355
        value = self->doc->origcharset;
406
        value = self->doc->origcharset; found = true;
356
    }
407
    }
357
    break;
408
    break;
358
    case 's':
409
    case 's':
359
    if (!key.compare(Rcl::Doc::keysig)) {
410
    if (!key.compare(Rcl::Doc::keysig)) {
360
        value = self->doc->sig;
411
        value = self->doc->sig; found = true;
361
    } else  if (!key.compare(Rcl::Doc::keysz)) {
412
    } else  if (!key.compare(Rcl::Doc::keysz)) {
362
        value = self->doc->dbytes.empty() ? self->doc->fbytes : 
413
        value = self->doc->dbytes.empty() ? self->doc->fbytes : 
363
        self->doc->dbytes;
414
        self->doc->dbytes; found = true;
364
    }
415
    }
365
    break;
416
    break;
366
    }
417
    }
367
418
368
    if (value.empty())
419
    if (!found) {
420
  PyObject *meth = Py_FindMethod(Doc_methods, (PyObject*)self, 
421
                     key.c_str());
422
  if (meth) {
423
      return meth;
424
  } else {
425
      PyErr_Clear();
426
  }
427
428
  if (self->doc->getmeta(key, 0)) {
369
    value = self->doc->meta[key];
429
        value = self->doc->meta[key];
430
  }
431
    }
370
432
371
    LOGDEB(("Doc_getattr: [%s] (%s) -> [%s]\n",
433
    LOGDEB(("Doc_getattr: [%s] (%s) -> [%s]\n",
372
        name, key.c_str(), value.c_str()));
434
        name, key.c_str(), value.c_str()));
373
    // Return a python unicode object
435
    // Return a python unicode object
374
    PyObject* res = PyUnicode_Decode(value.c_str(), value.size(), "UTF-8", 
436
    PyObject* res = PyUnicode_Decode(value.c_str(), value.size(), "utf-8",
375
                     "replace");
437
                     "replace");
376
    return res;
438
    return res;
377
}
439
}
378
440
379
static int
441
static int
...
...
464
    }
526
    }
465
    break;
527
    break;
466
    }
528
    }
467
    return 0;
529
    return 0;
468
}
530
}
531
469
532
470
PyDoc_STRVAR(doc_DocObject,
533
PyDoc_STRVAR(doc_DocObject,
471
"Doc()\n"
534
"Doc()\n"
472
"\n"
535
"\n"
473
"A Doc object contains index data for a given document.\n"
536
"A Doc object contains index data for a given document.\n"
...
...
530
    0,                     /* tp_clear */
593
    0,                     /* tp_clear */
531
    0,                     /* tp_richcompare */
594
    0,                     /* tp_richcompare */
532
    0,                     /* tp_weaklistoffset */
595
    0,                     /* tp_weaklistoffset */
533
    0,                     /* tp_iter */
596
    0,                     /* tp_iter */
534
    0,                     /* tp_iternext */
597
    0,                     /* tp_iternext */
535
    0,                         /* tp_methods */
598
    Doc_methods,               /* tp_methods */
536
    0,                         /* tp_members */
599
    0,                         /* tp_members */
537
    0,                         /* tp_getset */
600
    0,                         /* tp_getset */
538
    0,                         /* tp_base */
601
    0,                         /* tp_base */
539
    0,                         /* tp_dict */
602
    0,                         /* tp_dict */
540
    0,                         /* tp_descr_get */
603
    0,                         /* tp_descr_get */