source: ralphm-patches/findform.patch @ 25:e467ff96b011

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

Split off data forms changes.

File size: 2.9 KB
  • wokkel/data_form.py

    diff -r 031a0ad83156 -r fda6b92d81a1 wokkel/data_form.py
    a b  
    616616
    617617        for field in filtered:
    618618            self.removeField(field)
     619
     620
     621def findForm(element, formNamespace):
     622    """
     623    Find a Data Form.
     624
     625    Look for an element that represents a Data Form with the specified
     626    form namespace as a child element of the given element.
     627    """
     628    if not element:
     629        return None
     630
     631    for child in element.elements():
     632        if (child.uri, child.name) == ((NS_X_DATA, 'x')):
     633            form = Form.fromElement(child)
     634
     635            if (form.formNamespace == formNamespace or
     636                not form.formNamespace and form.formType=='cancel'):
     637                return form
     638
     639    return None
  • wokkel/pubsub.py

    diff -r 031a0ad83156 -r fda6b92d81a1 wokkel/pubsub.py
    a b  
    252252        self.verb = verb
    253253
    254254
    255     @staticmethod
    256     def _findForm(element, formNamespace):
    257         """
    258         Find a Data Form.
    259 
    260         Look for an element that represents a Data Form with the specified
    261         form namespace as a child element of the given element.
    262         """
    263         if not element:
    264             return None
    265 
    266         form = None
    267         for child in element.elements():
    268             try:
    269                 form = data_form.Form.fromElement(child)
    270             except data_form.Error:
    271                 continue
    272 
    273             if form.formNamespace != NS_PUBSUB_NODE_CONFIG:
    274                 continue
    275 
    276         return form
    277 
    278 
    279255    def _parse_node(self, verbElement):
    280256        """
    281257        Parse the required node identifier out of the verbElement.
     
    366342        """
    367343        Parse node type out of a request for the default node configuration.
    368344        """
    369         form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
     345        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    370346        if form and form.formType == 'submit':
    371347            values = form.getValues()
    372348            self.nodeType = values.get('pubsub#node_type', 'leaf')
     
    378354        """
    379355        Parse options out of a request for setting the node configuration.
    380356        """
    381         form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
     357        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    382358        if form:
    383359            if form.formType in ('submit', 'cancel'):
    384360                self.options = form
     
    435411
    436412
    437413    def _parse_options(self, verbElement):
    438         form = PubSubRequest._findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
     414        form = data_form.findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
    439415        if form:
    440416            if form.formType not in ('submit', 'cancel'):
    441417                raise BadRequest(text="Unexpected form type %r" % form.formType)
Note: See TracBrowser for help on using the repository browser.