source: ralphm-patches/findform.patch @ 21:6e73325a5473

Last change on this file since 21:6e73325a5473 was 21:6e73325a5473, checked in by Ralph Meijer <ralphm@…>, 13 years ago

Split off data forms changes.

File size: 2.9 KB
RevLine 
[21]1diff -r 031a0ad83156 -r fda6b92d81a1 wokkel/data_form.py
2--- a/wokkel/data_form.py       Wed Dec 30 21:37:33 2009 +0100
3+++ b/wokkel/data_form.py       Wed Dec 30 21:39:55 2009 +0100
4@@ -616,3 +616,24 @@
5 
6         for field in filtered:
7             self.removeField(field)
8+
9+
10+def findForm(element, formNamespace):
11+    """
12+    Find a Data Form.
13+
14+    Look for an element that represents a Data Form with the specified
15+    form namespace as a child element of the given element.
16+    """
17+    if not element:
18+        return None
19+
20+    for child in element.elements():
21+        if (child.uri, child.name) == ((NS_X_DATA, 'x')):
22+            form = Form.fromElement(child)
23+
24+            if (form.formNamespace == formNamespace or
25+                not form.formNamespace and form.formType=='cancel'):
26+                return form
27+
28+    return None
29diff -r 031a0ad83156 -r fda6b92d81a1 wokkel/pubsub.py
30--- a/wokkel/pubsub.py  Wed Dec 30 21:37:33 2009 +0100
31+++ b/wokkel/pubsub.py  Wed Dec 30 21:39:55 2009 +0100
32@@ -252,30 +252,6 @@
33         self.verb = verb
34 
35 
36-    @staticmethod
37-    def _findForm(element, formNamespace):
38-        """
39-        Find a Data Form.
40-
41-        Look for an element that represents a Data Form with the specified
42-        form namespace as a child element of the given element.
43-        """
44-        if not element:
45-            return None
46-
47-        form = None
48-        for child in element.elements():
49-            try:
50-                form = data_form.Form.fromElement(child)
51-            except data_form.Error:
52-                continue
53-
54-            if form.formNamespace != NS_PUBSUB_NODE_CONFIG:
55-                continue
56-
57-        return form
58-
59-
60     def _parse_node(self, verbElement):
61         """
62         Parse the required node identifier out of the verbElement.
63@@ -366,7 +342,7 @@
64         """
65         Parse node type out of a request for the default node configuration.
66         """
67-        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
68+        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
69         if form and form.formType == 'submit':
70             values = form.getValues()
71             self.nodeType = values.get('pubsub#node_type', 'leaf')
72@@ -378,7 +354,7 @@
73         """
74         Parse options out of a request for setting the node configuration.
75         """
76-        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
77+        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
78         if form:
79             if form.formType in ('submit', 'cancel'):
80                 self.options = form
81@@ -435,7 +411,7 @@
82 
83 
84     def _parse_options(self, verbElement):
85-        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
86+        form = data_form.findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
87         if form:
88             if form.formType not in ('submit', 'cancel'):
89                 raise BadRequest(text="Unexpected form type %r" % form.formType)
Note: See TracBrowser for help on using the repository browser.