Changeset 21:6e73325a5473 in ralphm-patches for pubsub-create-configure.patch


Ignore:
Timestamp:
Dec 30, 2009, 10:01:00 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Split off data forms changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pubsub-create-configure.patch

    r20 r21  
    1 diff -r 26ba5a2ff579 wokkel/data_form.py
    2 --- a/wokkel/data_form.py       Wed Dec 30 17:55:07 2009 +0100
    3 +++ b/wokkel/data_form.py       Wed Dec 30 20:46:36 2009 +0100
    4 @@ -253,10 +253,10 @@
    5              field['var'] = self.var
    6  
    7          for value in self.values:
    8 -            if self.fieldType == 'boolean':
    9 +            if isinstance(value, bool):
    10                  value = unicode(value).lower()
    11 -            elif self.fieldType in ('jid-single', 'jid-multi'):
    12 -                value = value.full()
    13 +            else:
    14 +                value = unicode(value)
    15  
    16              field.addElement('value', content=unicode(value))
    17  
    18 @@ -616,3 +616,24 @@
    19  
    20          for field in filtered:
    21              self.removeField(field)
    22 +
    23 +
    24 +def findForm(element, formNamespace):
    25 +    """
    26 +    Find a Data Form.
    27 +
    28 +    Look for an element that represents a Data Form with the specified
    29 +    form namespace as a child element of the given element.
    30 +    """
    31 +    if not element:
    32 +        return None
    33 +
    34 +    for child in element.elements():
    35 +        if (child.uri, child.name) == ((NS_X_DATA, 'x')):
    36 +            form = Form.fromElement(child)
    37 +
    38 +            if (form.formNamespace == formNamespace or
    39 +                not form.formNamespace and form.formType=='cancel'):
    40 +                return form
    41 +
    42 +    return None
    43 diff -r 26ba5a2ff579 wokkel/pubsub.py
    44 --- a/wokkel/pubsub.py  Wed Dec 30 17:55:07 2009 +0100
    45 +++ b/wokkel/pubsub.py  Wed Dec 30 20:46:36 2009 +0100
     1diff -r d64e96596c50 -r 8425a88d49f5 wokkel/pubsub.py
     2--- a/wokkel/pubsub.py  Wed Dec 30 21:41:55 2009 +0100
     3+++ b/wokkel/pubsub.py  Wed Dec 30 21:42:27 2009 +0100
    464@@ -234,7 +234,7 @@
    475         'optionsSet': ['nodeOrEmpty', 'jid', 'options'],
     
    5311         'configureGet': ['nodeOrEmpty'],
    5412         'configureSet': ['nodeOrEmpty', 'configure'],
    55 @@ -252,30 +252,6 @@
    56          self.verb = verb
    57  
    58  
    59 -    @staticmethod
    60 -    def _findForm(element, formNamespace):
    61 -        """
    62 -        Find a Data Form.
    63 -
    64 -        Look for an element that represents a Data Form with the specified
    65 -        form namespace as a child element of the given element.
    66 -        """
    67 -        if not element:
    68 -            return None
    69 -
    70 -        form = None
    71 -        for child in element.elements():
    72 -            try:
    73 -                form = data_form.Form.fromElement(child)
    74 -            except data_form.Error:
    75 -                continue
    76 -
    77 -            if form.formNamespace != NS_PUBSUB_NODE_CONFIG:
    78 -                continue
    79 -
    80 -        return form
    81 -
    82 -
    83      def _parse_node(self, verbElement):
    84          """
    85          Parse the required node identifier out of the verbElement.
    86 @@ -366,7 +342,7 @@
    87          """
    88          Parse node type out of a request for the default node configuration.
    89          """
    90 -        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    91 +        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    92          if form and form.formType == 'submit':
    93              values = form.getValues()
    94              self.nodeType = values.get('pubsub#node_type', 'leaf')
    95 @@ -378,7 +354,7 @@
    96          """
    97          Parse options out of a request for setting the node configuration.
    98          """
    99 -        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    100 +        form = data_form.findForm(verbElement, NS_PUBSUB_NODE_CONFIG)
    101          if form:
    102              if form.formType in ('submit', 'cancel'):
    103                  self.options = form
    104 @@ -388,6 +364,33 @@
     13@@ -364,6 +364,33 @@
    10514             raise BadRequest(text="Missing configuration form")
    10615 
     
    13645     def _parse_itemIdentifiers(self, verbElement):
    13746         """
    138 @@ -435,7 +438,7 @@
    139  
    140  
    141      def _parse_options(self, verbElement):
    142 -        form = PubSubRequest._findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
    143 +        form = data_form.findForm(verbElement, NS_PUBSUB_SUBSCRIBE_OPTIONS)
    144          if form:
    145              if form.formType not in ('submit', 'cancel'):
    146                  raise BadRequest(text="Unexpected form type %r" % form.formType)
    147 @@ -451,8 +454,8 @@
    148      def _parse_optionsWithSubscribe(self, verbElement):
    149          for element in verbElement.parent.elements():
    150              if element.name == 'options' and element.uri == NS_PUBSUB:
    151 -                form = PubSubRequest._findForm(element,
    152 -                                               NS_PUBSUB_SUBSCRIBE_OPTIONS)
    153 +                form = data_form.findForm(element,
    154 +                                          NS_PUBSUB_SUBSCRIBE_OPTIONS)
    155                  if not form:
    156                      continue
    157  
    158 @@ -662,7 +665,8 @@
     47@@ -602,7 +629,8 @@
    15948         pass
    16049 
     
    16655         Create a publish subscribe node.
    16756 
    168 @@ -670,12 +674,20 @@
     57@@ -610,12 +638,20 @@
    16958         @type service: L{JID}
    17059         @param nodeIdentifier: Optional suggestion for the id of the node.
     
    18776             try:
    18877                 new_node = iq.pubsub.create["node"]
    189 @@ -956,8 +968,6 @@
     78@@ -887,8 +923,6 @@
    19079             d = self.getNodes(requestor, target)
    19180         else:
     
    19685         d.addCallback(lambda nodes: [disco.DiscoItem(target, node)
    19786                                      for node in nodes])
    198 @@ -1067,6 +1077,12 @@
     87@@ -998,6 +1032,12 @@
    19988         form.typeCheck(fieldDefs, filterUnknown=True)
    20089 
     
    20998         if request.nodeType not in ('leaf', 'collection'):
    21099             raise error.StanzaError('not-acceptable')
    211 diff -r 26ba5a2ff579 wokkel/test/test_pubsub.py
    212 --- a/wokkel/test/test_pubsub.py        Wed Dec 30 17:55:07 2009 +0100
    213 +++ b/wokkel/test/test_pubsub.py        Wed Dec 30 20:46:36 2009 +0100
     100diff -r d64e96596c50 -r 8425a88d49f5 wokkel/test/test_pubsub.py
     101--- a/wokkel/test/test_pubsub.py        Wed Dec 30 21:41:55 2009 +0100
     102+++ b/wokkel/test/test_pubsub.py        Wed Dec 30 21:42:27 2009 +0100
    214103@@ -19,7 +19,7 @@
    215104 from wokkel.test.helpers import TestableRequestHandlerMixin, XmlStreamStub
     
    262151         """
    263152         Test sending delete request.
    264 @@ -998,6 +1032,7 @@
     153@@ -935,6 +969,7 @@
    265154         self.assertEqual(JID('user@example.org'), request.sender)
    266155         self.assertEqual(JID('pubsub.example.org'), request.recipient)
     
    270159 
    271160     def test_fromElementCreateInstant(self):
    272 @@ -1018,6 +1053,78 @@
     161@@ -955,6 +990,78 @@
    273162         self.assertIdentical(None, request.nodeIdentifier)
    274163 
     
    349238         """
    350239         Test parsing a request for the default node configuration.
    351 @@ -1804,6 +1911,52 @@
     240@@ -1741,6 +1848,52 @@
    352241         return d
    353242 
     
    402291         """
    403292         A default request should result in
    404 @@ -1837,7 +1990,7 @@
     293@@ -1774,7 +1927,7 @@
    405294             self.assertEqual(NS_PUBSUB_OWNER, element.uri)
    406295             self.assertEqual(NS_PUBSUB_OWNER, element.default.uri)
     
    411300         self.resource.getConfigurationOptions = getConfigurationOptions
    412301         self.resource.default = default
    413 @@ -1966,7 +2119,7 @@
     302@@ -1903,7 +2056,7 @@
    414303             self.assertEqual(NS_PUBSUB_OWNER, element.uri)
    415304             self.assertEqual(NS_PUBSUB_OWNER, element.configure.uri)
Note: See TracChangeset for help on using the changeset viewer.