Ignore:
Timestamp:
Apr 22, 2009, 5:02:02 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@169
Message:

Add a PubSubRequest? class, to parse and render publish-subscribe requests.

Author: ralphm.
Fixes #45.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/generic.py

    r55 r57  
    1111
    1212from twisted.internet import defer, protocol
    13 from twisted.words.protocols.jabber import error, xmlstream
     13from twisted.words.protocols.jabber import error, jid, xmlstream
    1414from twisted.words.protocols.jabber.xmlstream import toResponse
    1515from twisted.words.xish import domish, utility
     
    163163
    164164
     165
     166class Stanza(object):
     167    """
     168    Abstract representation of a stanza.
     169
     170    @ivar sender: The sending entity.
     171    @type sender: L{jid.JID}
     172    @ivar recipient: The receiving entity.
     173    @type recipient: L{jid.JID}
     174    """
     175
     176    sender = None
     177    recipient = None
     178    stanzaType = None
     179
     180    @classmethod
     181    def fromElement(Class, element):
     182        stanza = Class()
     183        stanza.parseElement(element)
     184        return stanza
     185
     186
     187    def parseElement(self, element):
     188        self.sender = jid.internJID(element['from'])
     189        if element.hasAttribute('from'):
     190            self.sender = jid.internJID(element['from'])
     191        if element.hasAttribute('to'):
     192            self.recipient = jid.internJID(element['to'])
     193        self.stanzaType = element.getAttribute('type')
     194
     195
    165196class DeferredXmlStreamFactory(BootstrapMixin, protocol.ClientFactory):
    166197    protocol = xmlstream.XmlStream
Note: See TracChangeset for help on using the changeset viewer.