all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#11916: 24.1.50; Making url-dav work
@ 2012-07-11 21:00 David Engster
  2012-07-18 12:25 ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: David Engster @ 2012-07-11 21:00 UTC (permalink / raw)
  To: 11916

[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]

I'm trying to simply get a listing from a directory on a WebDAV share
using Emacs. I was overjoyed to see that Emacs ships with url-dav.el,
which seemed to do exactly what I needed. However, it seems that url-dav
depends on a specially patched xml.el for namespace expansion which
apparently never made it into Emacs proper. If you look into
`url-dav-supported-p', it looks for a function `xml-expand-namespace'
which I cannot find anywhere in xml.el's history. At least one other
lone soul faced the same problem and came to the same conclusion (see
http://lists.gnu.org/archive/html/help-gnu-emacs/2011-11/msg00158.html).

Now, xml.el can properly deal with namespaces since 2004 or so, but it
returns the QNames through a cons ("DAV:" . "property"), which is kind
of... cumbersome. The url-dav package naturally expects a plain symbol
'DAV:property.

I started rewriting url-dav to work with the cons's returned by xml.el,
but it's tedious work and, more importantly, makes the code really
ugly. Instead, I now just use a small function to replace the cons's in
xml.el's output with the plain symbols the package expects. Please find
the patch attached.

-David


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: url-dav-diff.patch --]
[-- Type: text/x-patch, Size: 1592 bytes --]

--- url-dav.el	2012-07-11 22:34:49.401721367 +0200
+++ url-dav.el_patched	2012-07-11 22:33:34.504867729 +0200
@@ -395,10 +395,15 @@
 		 url-http-content-type
 		 (string-match "\\`\\(text\\|application\\)/xml"
 			       url-http-content-type))
-		(setq tree (xml-parse-region (point) (point-max)))))
+		(setq tree (xml-parse-region (point) (point-max) nil nil t))))
 	;; Clean up after ourselves.
 	(kill-buffer buffer)))
 
+    ;; This package was initially written for a different kind of
+    ;; QNAMES expansion, hence we have now to rewrite those so that
+    ;; for example ("DAV:" . "foo") becomes the symbol 'DAV:foo.
+    (url-dav-changexml (car tree))
+
     ;; We should now be
     (if (eq (xml-node-name (car tree)) 'DAV:multistatus)
 	(url-dav-dispatch-node (car tree))
@@ -411,6 +416,21 @@
 	;; nobody but us needs to know the difference.
 	(list (cons url properties))))))
 
+(defun url-dav-changexml (node)
+  "Rewrite all expanded names in NODE to plain symbols.
+That means, all cons produced from `xml-parse-region'
+like (\"DAV:\" .  \"foo\") become plain symbols DAV:foo.
+This replacement happens in-place."
+  (when (consp node)
+    (let ((name (xml-node-name node))
+	  (children (xml-node-children node)))
+      (when (and (consp name)
+		 (equal (car name) "DAV:"))
+	(setcar node (intern (concat "DAV:" (cdr name)))))
+      (when children
+	(dolist (cur children)
+	  (url-dav-changexml cur))))))
+
 (defun url-dav-request (url method tag body
 				 &optional depth headers namespaces)
   "Perform WebDAV operation METHOD on URL.  Return the parsed responses.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-07-26 23:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-11 21:00 bug#11916: 24.1.50; Making url-dav work David Engster
2012-07-18 12:25 ` Stefan Monnier
2012-07-18 17:45   ` David Engster
2012-07-19  7:15     ` Stefan Monnier
2012-07-19 15:28       ` David Engster
2012-07-19 22:12         ` Stefan Monnier
2012-07-21 12:11           ` David Engster
2012-07-22 10:11             ` Stefan Monnier
2012-07-25 21:04               ` David Engster
2012-07-26  0:04                 ` Stefan Monnier
2012-07-26 16:01                   ` David Engster
2012-07-26 23:32                     ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.