From 222a1e27d5a50e255dfacf5378225b9ec78dd124 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 8 Oct 2013 17:59:31 +0200 Subject: apt_pkg: Support paths supplied as bytes objects (See: #680971) We should be done now. DO NOT MERGE --- python/acquire-item.cc | 9 ++++++--- python/apt_pkgmodule.cc | 4 ++-- python/configuration.cc | 12 ++++++------ python/indexfile.cc | 4 ++-- python/indexrecords.cc | 4 ++-- python/lock.cc | 5 +++-- python/pkgmanager.cc | 4 ++-- python/policy.cc | 10 ++++++---- python/tag.cc | 5 ++--- 9 files changed, 31 insertions(+), 26 deletions(-) (limited to 'python') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 53c3802b..5589a1f2 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -224,7 +224,8 @@ PyTypeObject PyAcquireItem_Type = { static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * kwds) { PyObject *pyfetcher; - char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + const char *uri, *md5, *descr, *shortDescr; + PyApt_Filename destDir, destFile; int size = 0; uri = md5 = descr = shortDescr = destDir = destFile = ""; @@ -232,9 +233,11 @@ static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * "destdir", "destfile", NULL }; - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissO&O&", kwlist, &PyAcquire_Type, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, &destFile) == 0) + &size, &descr, &shortDescr, + PyApt_Filename::Converter, &destDir, + PyApt_Filename::Converter, &destFile) == 0) return 0; pkgAcquire *fetcher = GetCpp(pyfetcher); diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 4cffcaa5..5b06f721 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -434,9 +434,9 @@ static char *doc_GetLock = "provided by apt_pkg.FileLock instead using the with-statement."; static PyObject *GetLock(PyObject *Self,PyObject *Args) { - const char *file; + PyApt_Filename file; char errors = false; - if (PyArg_ParseTuple(Args,"s|b",&file,&errors) == 0) + if (PyArg_ParseTuple(Args,"O&|b",PyApt_Filename::Converter, &file,&errors) == 0) return 0; int fd = GetLock(file, errors); diff --git a/python/configuration.cc b/python/configuration.cc index 37374625..c57bc79c 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -351,8 +351,8 @@ char *doc_LoadConfig = "options in the configuration object."; PyObject *LoadConfig(PyObject *Self,PyObject *Args) { - char *Name = 0; - if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) + PyApt_Filename Name; + if (PyArg_ParseTuple(Args,"OO&",&Self,PyApt_Filename::Converter, &Name) == 0) return 0; if (PyConfiguration_Check(Self)== 0) { @@ -373,8 +373,8 @@ char *doc_LoadConfigISC = "configuration files."; PyObject *LoadConfigISC(PyObject *Self,PyObject *Args) { - char *Name = 0; - if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) + PyApt_Filename Name; + if (PyArg_ParseTuple(Args,"OO&",&Self,PyApt_Filename::Converter, &Name) == 0) return 0; if (PyConfiguration_Check(Self)== 0) { @@ -394,8 +394,8 @@ char *doc_LoadConfigDir = "correct order."; PyObject *LoadConfigDir(PyObject *Self,PyObject *Args) { - char *Name = 0; - if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) + PyApt_Filename Name; + if (PyArg_ParseTuple(Args,"OO&",&Self,PyApt_Filename::Converter, &Name) == 0) return 0; if (PyConfiguration_Check(Self)== 0) { diff --git a/python/indexfile.cc b/python/indexfile.cc index bf0df516..1a146bac 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -18,9 +18,9 @@ static PyObject *IndexFileArchiveURI(PyObject *Self,PyObject *Args) { pkgIndexFile *File = GetCpp(Self); - char *path; + PyApt_Filename path; - if (PyArg_ParseTuple(Args, "s",&path) == 0) + if (PyArg_ParseTuple(Args, "O&", PyApt_Filename::Converter, &path) == 0) return 0; return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str())); } diff --git a/python/indexrecords.cc b/python/indexrecords.cc index c7623cfd..ae8671ab 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -51,8 +51,8 @@ static char *indexrecords_lookup_doc = "and the second element 'size' is an int object."; static PyObject *indexrecords_lookup(PyObject *self,PyObject *args) { - const char *keyname; - if (PyArg_ParseTuple(args, "s", &keyname) == 0) + PyApt_Filename keyname; + if (PyArg_ParseTuple(args, "O&", PyApt_Filename::Converter, &keyname) == 0) return 0; indexRecords *records = GetCpp(self); const indexRecords::checkSum *result = records->Lookup(keyname); diff --git a/python/lock.cc b/python/lock.cc index 38a2bc74..7a76c9fd 100644 --- a/python/lock.cc +++ b/python/lock.cc @@ -183,9 +183,10 @@ static PyObject *filelock_exit(filelock_object *self, PyObject *args) static PyObject *filelock_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - char *filename = 0; + PyApt_Filename filename; char *kwlist[] = {"filename", NULL}; - if (PyArg_ParseTupleAndKeywords(args, kwds, "s:__init__", kwlist, + if (PyArg_ParseTupleAndKeywords(args, kwds, "O&:__init__", kwlist, + PyApt_Filename::Converter, &filename) == 0) { return NULL; } diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 5fff1e57..cf19e6bf 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -230,9 +230,9 @@ static PyObject *PkgManagerInstall(PyObject *Self,PyObject *Args) { PyPkgManager *pm = GetCpp(Self); PyObject *pkg; - const char *file; + PyApt_Filename file; - if (PyArg_ParseTuple(Args, "O!s", &PyPackage_Type,&pkg, &file) == 0) + if (PyArg_ParseTuple(Args, "O!O&", &PyPackage_Type,&pkg, PyApt_Filename::Converter, &file) == 0) return 0; return HandleErrors(PyBool_FromLong(pm->callInstall(PyPackage_ToCpp(pkg), file))); diff --git a/python/policy.cc b/python/policy.cc index 96b83abd..ac9a1ace 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -93,11 +93,12 @@ static char *policy_read_pinfile_doc = "and add it to the policy."; static PyObject *policy_read_pinfile(PyObject *self, PyObject *arg) { - if (!PyString_Check(arg)) + PyApt_Filename name; + if (!name.init(arg)) return 0; pkgPolicy *policy = GetCpp(self); - return PyBool_FromLong(ReadPinFile(*policy, PyString_AsString(arg))); + return PyBool_FromLong(ReadPinFile(*policy, name)); } #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 8) @@ -107,11 +108,12 @@ static char *policy_read_pindir_doc = "and add them to the policy."; static PyObject *policy_read_pindir(PyObject *self, PyObject *arg) { - if (!PyString_Check(arg)) + PyApt_Filename name; + if (!name.init(arg)) return 0; pkgPolicy *policy = GetCpp(self); - return PyBool_FromLong(ReadPinDir(*policy, PyString_AsString(arg))); + return PyBool_FromLong(ReadPinDir(*policy, name)); } #endif diff --git a/python/tag.cc b/python/tag.cc index a0f526ad..9f175cc4 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -435,9 +435,8 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) // check if we got a filename or a file object int fileno = -1; - const char *filename = NULL; - filename = PyObject_AsString(File); - if (filename == NULL) { + PyApt_Filename filename; + if (!filename.init(File)) { PyErr_Clear(); fileno = PyObject_AsFileDescriptor(File); } -- cgit v1.2.3