User Tools

Site Tools


programming:python:pyradix_search_all_patch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:python:pyradix_search_all_patch [2008/07/05 20:55] crustymonkeyprogramming:python:pyradix_search_all_patch [2008/07/05 22:10] (current) crustymonkey
Line 13: Line 13:
 Usage: Usage:
 <code> <code>
-Radix.search_all_containing(<network>) -> [ <node> , <node> , ...] or None+Radix.search_all_containing(<network>) -> [ <node> , <node> , ... ]
 </code> </code>
 <code python> <code python>
Line 61: Line 61:
 Here is the code for the patch, followed by a link to the file. Here is the code for the patch, followed by a link to the file.
 <code> <code>
---- radix_python.c  2008-07-05 15:22:55.000000000 -0500 +--- radix_python.c  2008-07-05 17:08:51.000000000 -0500 
-+++ radix_python.c.new  2008-07-05 15:19:03.000000000 -0500 ++++ radix_python.c.new  2008-07-05 17:08:11.000000000 -0500 
-@@ -453,6 +453,53 @@+@@ -453,6 +453,52 @@
     return (PyObject *)node_obj;     return (PyObject *)node_obj;
  }  }
Line 89: Line 89:
 +   long prefixlen = -1; +   long prefixlen = -1;
 +   int packlen = -1; +   int packlen = -1;
 ++   if ((node_list = PyList_New(0)) == NULL)
 ++       return NULL;
 + +
-+   if (!PyArg_ParseTupleAndKeywords(args, kw_args, "|sls#:search_best", keywords,++   if (!PyArg_ParseTupleAndKeywords(args, kw_args, "|sls#:search_all_containing", keywords,
 +       &addr, &prefixlen, &packed, &packlen)) +       &addr, &prefixlen, &packed, &packlen))
 +       return NULL; +       return NULL;
Line 99: Line 101:
 +       node->data == NULL) { +       node->data == NULL) {
 +       Deref_Prefix(prefix); +       Deref_Prefix(prefix);
-+       Py_INCREF(Py_None); ++       return node_list;
-+       return Py_None;+
 +   } +   }
 +   Deref_Prefix(prefix); +   Deref_Prefix(prefix);
-+   node_list = PyList_New(0); ++   PyList_Append(node_list , (PyObject *)node->data);
-+   node_obj = node->data; +
-+   PyList_Append(node_list , (PyObject *)node_obj);+
 +   while ((parent = node->parent) != NULL) { +   while ((parent = node->parent) != NULL) {
-      node_obj = parent->data; +       if (parent->data != NULL) 
-      PyList_Append(node_list , (PyObject *)node_obj);+           PyList_Append(node_list , (PyObject *)parent->data);
 +       node = parent; +       node = parent;
 +   } +   }
Line 117: Line 116:
  "Radix.nodes(prefix) -> List of RadixNode\n\  "Radix.nodes(prefix) -> List of RadixNode\n\
  \n\  \n\
-@@ -640,6 +687,7 @@+@@ -640,6 +686,7 @@
     {"delete",  (PyCFunction)Radix_delete,  METH_VARARGS|METH_KEYWORDS, Radix_delete_doc    },     {"delete",  (PyCFunction)Radix_delete,  METH_VARARGS|METH_KEYWORDS, Radix_delete_doc    },
     {"search_exact",(PyCFunction)Radix_search_exact,METH_VARARGS|METH_KEYWORDS, Radix_search_exact_doc  },     {"search_exact",(PyCFunction)Radix_search_exact,METH_VARARGS|METH_KEYWORDS, Radix_search_exact_doc  },
Line 126: Line 125:
     {"__getstate__",(PyCFunction)Radix_getstate,    METH_VARARGS,           NULL            },     {"__getstate__",(PyCFunction)Radix_getstate,    METH_VARARGS,           NULL            },
 </code> </code>
 +
 The patch file: {{:programming:python:radix_python.c.patch.gz|}} The patch file: {{:programming:python:radix_python.c.patch.gz|}}
 +
 +===== Patching =====
 +Download the above patch file and do the following:
 +<code>
 +# cp radix_python.c.patch.gz /path/to/untarred/py-radix/source/directory
 +# cd /path/to/untarred/py-radix/source/directory
 +# gunzip radix_python.c.patch.gz
 +# patch -p0 radix_python.c < radix_python.c.patch
 +# python setup.py install
 +</code>
 +The last line there will install the patched module.
 +
programming/python/pyradix_search_all_patch.txt · Last modified: 2008/07/05 22:10 by crustymonkey