Commit 3cf10fd6 authored by Simon Poirier's avatar Simon Poirier
Browse files

Decode locale-encoded descriptions.

The translated description returned by libapt-pkg is, unlike other
fields, locale-encoded (see apt-pkg/deb/debrecords.cc). As such, try
decoding that description with the current locale.
parent afed4b29
......@@ -31,6 +31,7 @@
#include <string>
#include <iostream>
#include <new>
#include <langinfo.h>
/**
* Exception class for almost all Python errors
......@@ -220,6 +221,12 @@ inline PyObject *CppPyString(const char *Str)
return PyString_FromString(Str);
}
inline PyObject *CppPyLocaleString(const std::string &Str)
{
char const * const codeset = nl_langinfo(CODESET);
return PyUnicode_Decode(Str.c_str(), Str.length(), codeset, "replace");
}
#if PY_MAJOR_VERSION >= 3
static inline PyObject *CppPyPath(const std::string &path)
{
......
......@@ -127,7 +127,7 @@ static PyObject *PkgRecordsGetShortDesc(PyObject *Self,void*) {
}
static PyObject *PkgRecordsGetLongDesc(PyObject *Self,void*) {
PkgRecordsStruct &Struct = GetStruct(Self,"LongDesc");
return (Struct.Last != 0) ? CppPyString(Struct.Last->LongDesc()) : 0;
return (Struct.Last != 0) ? CppPyLocaleString(Struct.Last->LongDesc()) : 0;
}
static PyObject *PkgRecordsGetName(PyObject *Self,void*) {
PkgRecordsStruct &Struct = GetStruct(Self,"Name");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment