summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2015-05-22 12:12:47 +0200
committerMichael Vogt <mvo@ubuntu.com>2015-05-22 12:12:47 +0200
commit83d876034f5bd74f007376f2cefc98cae77a5a94 (patch)
treeb9bd765d40e2cbaf654f58bb01bdeb8dda3c39a6
parent39e58a1efcf45fa06e9cc87790f5c8883f157039 (diff)
downloadpython-apt-83d876034f5bd74f007376f2cefc98cae77a5a94.tar.gz
rename "md5" keyword argument in AcquireFile() to "hash" and add backward compatiblity
-rw-r--r--python/acquire-item.cc35
-rw-r--r--tests/test_paths.py14
2 files changed, 40 insertions, 9 deletions
diff --git a/python/acquire-item.cc b/python/acquire-item.cc
index 5589a1f2..d07f4c82 100644
--- a/python/acquire-item.cc
+++ b/python/acquire-item.cc
@@ -224,26 +224,43 @@ PyTypeObject PyAcquireItem_Type = {
static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * kwds)
{
PyObject *pyfetcher;
- const char *uri, *md5, *descr, *shortDescr;
+ 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|sissO&O&", kwlist,
- &PyAcquire_Type, &pyfetcher, &uri, &md5,
+#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) == 0)
+ 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,
diff --git a/tests/test_paths.py b/tests/test_paths.py
index 51d22f49..993ad02b 100644
--- a/tests/test_paths.py
+++ b/tests/test_paths.py
@@ -35,6 +35,20 @@ class TestPath(unittest.TestCase):
destdir=self.file_unicode,
destfile=self.file_unicode)
+ def test_acquire_file_md5_keyword_backward_compat(self):
+ """
+ Ensure that both "md5" and "hash" is supported as keyword for
+ AcquireFile
+ """
+ apt_pkg.AcquireFile(
+ apt_pkg.Acquire(), "http://example.com",
+ destfile=self.file_bytes,
+ md5="abcdef")
+ apt_pkg.AcquireFile(
+ apt_pkg.Acquire(), "http://example.com",
+ destfile=self.file_bytes,
+ hash="sha1:41050ed528554fdd6c6c9a086ddd6bdba5857b21")
+
def test_ararchive(self):
archive = apt_inst.ArArchive(u"data/test_debs/data-tar-xz.deb")