Ignore:
Timestamp:
Nov 9, 2011, 6:44:36 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Children:
155:8b2ed9549399, 159:bbb746f79718
Message:

Allow wokkel.data_form.Form to be used as a read-only dict.

In [1334124db2fd] wokkel.pubsub.PubSubRequest.options was changed to be a
Form instead of dictionary, which makes existing code using that field to be
incompatible.

To reduce the impact of that change, this change implements various methods in
wokkel.data_form.Form to emulate a read-only dictionary. It now maps the
name of each field to its value, similar to the dictionary returned from
getValues. The latter is now identical to dict(form).

  • * *

Address incompatible change concerning PubSubRequest?.options.

In changeset [1334124db2fd], PubSubRequest.options was changed to hold the
wokkel.data_form.Form that represents the data form sent in the original
request. This makes it easier to type check the form in a step separate from
parsing the request. However, this is an incompatible change.

To remedy this, we move the form to optionsForm and make options a property
that returns the values of the form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r97 r105  
    385385        """
    386386        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    387         if form and form.formType == 'submit':
     387        if form is not None and form.formType == 'submit':
    388388            values = form.getValues()
    389389            self.nodeType = values.get('pubsub#node_type', 'leaf')
     
    397397        """
    398398        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    399         if form:
     399        if form is not None:
    400400            if form.formType in ('submit', 'cancel'):
    401401                self.options = form
     
    413413            if element.uri == NS_PUBSUB and element.name == 'configure':
    414414                form = data_form.findForm(element, NS_PUBSUB_NODE_CONFIG)
    415                 if form:
     415                if form is not None:
    416416                    if form.formType != 'submit':
    417417                        raise BadRequest(text=u"Unexpected form type '%s'" %
     
    497497        """
    498498        form = data_form.findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
    499         if form:
     499        if form is not None:
    500500            if form.formType in ('submit', 'cancel'):
    501501                self.options = form
     
    516516                form = data_form.findForm(element,
    517517                                          NS_PUBSUB_SUBSCRIBE_OPTIONS)
    518                 if form:
     518                if form is not None:
    519519                    if form.formType != 'submit':
    520520                        raise BadRequest(text=u"Unexpected form type '%s'" %
     
    527527
    528528    def _render_optionsWithSubscribe(self, verbElement):
    529         if self.options:
     529        if self.options is not None:
    530530            optionsElement = verbElement.parent.addElement('options')
    531531            self._render_options(optionsElement)
     
    11951195
    11961196            handler = getattr(self, handlerName)
    1197 
    11981197            args = [getattr(request, arg) for arg in argNames]
    1199             if 'options' in argNames:
    1200                 args[argNames.index('options')] = request.options.getValues()
    1201 
    12021198            d = handler(*args)
    12031199
Note: See TracChangeset for help on using the changeset viewer.