From d16284af7875eb32a826a63620c83999fdbd29c3 Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Mon, 24 Aug 2009 09:42:24 -0400 Subject: [PATCH] fixed bugs related to sxml that had namespaced attributes (not sure if this fixes namespaced nodes). also added tests re #9 (1) --- src/query.lisp | 12 +++++++----- src/util.lisp | 25 ++++++++++++------------- test.lisp | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 test.lisp diff --git a/src/query.lisp b/src/query.lisp index 76eacd2..0637c7f 100644 --- a/src/query.lisp +++ b/src/query.lisp @@ -96,11 +96,13 @@ Parameters: :processor (lambda (sxml) (let* ((rows (find-nodes-by-name "ei" sxml)) - (c-blob (first (find-nodes-by-name "embeddedin" (find-nodes-by-name "query-continue" sxml)))) - (continuation (when c-blob - (destructuring-bind (_1 ((_2 continuation))) c-blob - (declare (ignore _1 _2)) - continuation))) + (c-blob (first (find-nodes-by-name + "embeddedin" + (first (find-nodes-by-name "query-continue" sxml))))) + (continuation (when c-blob + (destructuring-bind (_1 ((_2 continuation))) c-blob + (declare (ignore _1 _2)) + continuation))) titles) (loop for row in rows do (destructuring-bind (_1 ((_2 title) &rest _3)) row diff --git a/src/util.lisp b/src/util.lisp index bdffc4f..ce0e821 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -18,30 +18,29 @@ package)) (symbol str))) -(defun map-tree (fn &rest trees) +(defun map-sxml-tree (fn tree) "Do a depth first traversal of some set of trees calling fn on every non-nil element. " - (when trees - (dolist (n trees) - (etypecase n - (null) - (atom (funcall fn n)) - (list - (funcall fn n) - (apply #'map-tree fn n)))))) + (when tree + (labels ((rec (tree) + (funcall fn tree) + (dolist (n (cddr tree)) + (when (listp n) + (rec n))))) + (rec tree)))) -(defun find-tree (pred &rest trees) +(defun find-tree (pred tree) "find a tree based on a predicate" (let ((results)) (flet ((handler (node) (when (funcall pred node) (push node results)))) - (map-tree #'handler trees) + (map-sxml-tree #'handler tree) (nreverse results)))) -(defun find-nodes-by-name (name &rest trees) +(defun find-nodes-by-name (name tree) "find all sxml nodes with a given name " (find-tree (lambda (n) (string-equal (when (and (listp n) (stringp (car n))) - (car n)) name)) trees)) + (car n)) name)) tree)) diff --git a/test.lisp b/test.lisp new file mode 100644 index 0000000..11b109a --- /dev/null +++ b/test.lisp @@ -0,0 +1,19 @@ +;; -*- lisp -*- +(in-package :cl-mediawiki) + + + +(cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") + (cl-mediawiki:get-page-content "Pigment")) + +(cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") + (cl-mediawiki:get-action-tokens "Pigment")) + +(cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") + (cl-mediawiki:pages-that-embed "Template:Grateful_Dead" )) + +(cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") + (cl-mediawiki:get-page-info "Pigment" )) + +(cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") + (cl-mediawiki:user-contribs "bobbysmith007")) \ No newline at end of file -- 2.11.4.GIT