summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/cache.cc8
-rw-r--r--python/generic.h4
2 files changed, 12 insertions, 0 deletions
diff --git a/python/cache.cc b/python/cache.cc
index 10561ca0..e527faba 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -1247,6 +1247,12 @@ static PyObject *PackageFile_GetArchitecture(PyObject *Self,void*)
return Safe_FromString(File.Architecture());
}
+static PyObject *PackageFile_GetCodename(PyObject *Self,void*)
+{
+ pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);
+ return Safe_FromString(File.Codename());
+}
+
static PyObject *PackageFile_GetSite(PyObject *Self,void*)
{
pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);
@@ -1305,6 +1311,8 @@ static PyGetSetDef PackageFileGetSet[] = {
"The archive of the package file (i.e. 'Suite' in the Release file)."},
{"component",PackageFile_GetComponent,0,
"The component of this package file (e.g. 'main')."},
+ {"codename",PackageFile_GetCodename,0,
+ "The codename of this package file (e.g. squeeze-updates)."},
{"filename",PackageFile_GetFileName,0,
"The path to the file."},
{"id",PackageFile_GetID,0,
diff --git a/python/generic.h b/python/generic.h
index f9680ca5..914456e2 100644
--- a/python/generic.h
+++ b/python/generic.h
@@ -80,10 +80,14 @@ typedef int Py_ssize_t;
static inline const char *PyUnicode_AsString(PyObject *op) {
// Convert to bytes object, using the default encoding.
+#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
+ return PyUnicode_AsUTF8(op);
+#else
// Use Python-internal API, there is no other way to do this
// without a memory leak.
PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);
return bytes ? PyBytes_AS_STRING(bytes) : 0;
+#endif
}
// Convert any type of string based object to a const char.