diff options
Diffstat (limited to 'python/acquire-item.cc')
| -rw-r--r-- | python/acquire-item.cc | 76 |
1 files changed, 29 insertions, 47 deletions
diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 5e7423ab..d07f4c82 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -224,23 +224,43 @@ 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, *hash, *md5, *descr, *shortDescr; + PyApt_Filename destDir, destFile; int size = 0; - uri = md5 = descr = shortDescr = destDir = destFile = ""; + uri = hash = md5 = descr = shortDescr = destDir = destFile = ""; - char *kwlist[] = {"owner","uri", "md5", "size", "descr", "short_descr", - "destdir", "destfile", NULL + // "md5" is only in this list for backward compatiblity, everyone should + // use "hash" + char *kwlist[] = {"owner", "uri", "hash", "size", "descr", "short_descr", + "destdir", "destfile", "md5", NULL }; - - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PyAcquire_Type, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, &destFile) == 0) +#if PY_MAJOR_VERSION >= 3 + const char *fmt = "O!s|sissO&O&$s"; +#else + // no "$" support to indicate that the remaining args are keyword only + // in py2.x :/ + const char *fmt = "O!s|sissO&O&s"; +#endif + if (PyArg_ParseTupleAndKeywords(Args, kwds, fmt, kwlist, + &PyAcquire_Type, &pyfetcher, &uri, &hash, + &size, &descr, &shortDescr, + PyApt_Filename::Converter, &destDir, + PyApt_Filename::Converter, &destFile, + &md5) == 0) return 0; + // issue deprecation warning for md5 + if (strlen(md5) > 0) { + PyErr_Warn(PyExc_DeprecationWarning, + "Using the md5 keyword is deprecated, please use 'hash' instead"); + } + // support "md5" keyword for backward compatiblity + if (strlen(hash) == 0 && strlen(md5) != 0) + hash = md5; pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyfetcher); pkgAcqFile *af = new pkgAcqFile(fetcher, // owner uri, // uri - md5, // md5 + hash, // hash size, // size descr, // descr shortDescr, @@ -320,41 +340,3 @@ PyTypeObject PyAcquireFile_Type = { acquirefile_new, // tp_new }; -#ifdef COMPAT_0_7 -char *doc_GetPkgAcqFile = - "GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; -PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) -{ - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " - "deprecated. Please see apt_pkg.AcquireFile() for the " - "replacement", 1); - PyObject *pyfetcher; - char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; - int size = 0; - uri = md5 = descr = shortDescr = destDir = destFile = ""; - - char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", - "destDir", "destFile", NULL - }; - - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PyAcquire_Type, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, &destFile) == 0) - return 0; - - pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyfetcher); - pkgAcqFile *af = new pkgAcqFile(fetcher, // owner - uri, // uri - md5, // md5 - size, // size - descr, // descr - shortDescr, - destDir, - destFile); // short-desc - CppPyObject<pkgAcqFile*> *AcqFileObj = CppPyObject_NEW<pkgAcqFile*>(NULL, &PyAcquireFile_Type); - AcqFileObj->Object = af; - AcqFileObj->NoDelete = true; - - return AcqFileObj; -} -#endif |
