source: ralphm-patches/findform.patch @ 26:59ace4d1df68

Last change on this file since 26:59ace4d1df68 was 26:59ace4d1df68, checked in by Ralph Meijer <ralphm@…>, 11 years ago

Clean up patches, more tests, adjust copyright statements to new year.

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