Bug#538723: python-apt: Please allow a way to get "raw" data for a tag
On Sun, Jul 26, 2009 at 05:04:34PM +0200, John Wright wrote:
> Package: python-apt
> Version: 0.7.11.0
> Severity: wishlist
> Tags: patch
>
> There are times when it would be nice to get the raw data for a tag,
> without any white space stripped off the front. For example, see
> #538376, where we would like to know if the data started with a newline.
>
> I have attached a patch that adds a FindRaw method to TagSection.
Whoops, I didn't actually attach the patch. Here it is.
--
John Wright <jsw@debian.org>
commit d1272e937729cb13b54ea2d2955692bceb078236
Author: John Wright <john@johnwright.org>
Date: Sun Jul 26 16:12:06 2009 +0200
Add a FindRaw method for TagSection objects
diff --git a/python/tag.cc b/python/tag.cc
index 217be29..6fe97ed 100644
--- a/python/tag.cc
+++ b/python/tag.cc
@@ -92,6 +92,29 @@ static PyObject *TagSecFind(PyObject *Self,PyObject *Args)
return PyString_FromStringAndSize(Start,Stop-Start);
}
+static char *doc_FindRaw = "FindRaw(Name) -> String/None";
+static PyObject *TagSecFindRaw(PyObject *Self,PyObject *Args)
+{
+ char *Name = 0;
+ char *Default = 0;
+ if (PyArg_ParseTuple(Args,"s|z",&Name,&Default) == 0)
+ return 0;
+
+ unsigned Pos;
+ if (GetCpp<pkgTagSection>(Self).Find(Name,Pos) == false)
+ {
+ if (Default == 0)
+ Py_RETURN_NONE;
+ return PyString_FromString(Default);
+ }
+
+ const char *Start;
+ const char *Stop;
+ GetCpp<pkgTagSection>(Self).Get(Start,Stop,Pos);
+
+ return PyString_FromStringAndSize(Start,Stop-Start);
+}
+
static char *doc_FindFlag = "FindFlag(Name) -> integer/none";
static PyObject *TagSecFindFlag(PyObject *Self,PyObject *Args)
{
@@ -355,6 +378,7 @@ static PyMethodDef TagSecMethods[] =
{
// Query
{"Find",TagSecFind,METH_VARARGS,doc_Find},
+ {"FindRaw",TagSecFindRaw,METH_VARARGS,doc_FindRaw},
{"FindFlag",TagSecFindFlag,METH_VARARGS,doc_FindFlag},
{"Bytes",TagSecBytes,METH_VARARGS,doc_Bytes},
Reply to: