Simplify podofo str->unicode conversion

This commit is contained in:
Kovid Goyal 2019-07-31 16:28:04 +05:30
parent 91b812b718
commit 3255ecbcf1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 10 deletions

View File

@ -394,7 +394,6 @@ PDFDoc_version_getter(PDFDoc *self, void *closure) {
static PyObject *
PDFDoc_getter(PDFDoc *self, int field)
{
PyObject *ans;
PdfString s;
PdfInfo *info = self->doc->GetInfo();
if (info == NULL) {
@ -419,13 +418,7 @@ PDFDoc_getter(PDFDoc *self, int field)
return NULL;
}
ans = podofo_convert_pdfstring(s);
if (ans == NULL) {PyErr_NoMemory(); return NULL;}
PyObject *uans = PyUnicode_FromEncodedObject(ans, "utf-8", "replace");
Py_DECREF(ans);
if (uans == NULL) {return NULL;}
Py_INCREF(uans);
return uans;
return podofo_convert_pdfstring(s);
}
static int

View File

@ -25,8 +25,7 @@ pdf::podofo_set_exception(const PdfError &err) {
PyObject *
pdf::podofo_convert_pdfstring(const PdfString &s) {
std::string raw = s.GetStringUtf8();
return PyBytes_FromStringAndSize(raw.c_str(), raw.length());
return PyUnicode_FromString(s.GetStringUtf8().c_str());
}
PdfString *