Changeset 4:e8e7d5543a6f


Ignore:
Timestamp:
Aug 22, 2007, 5:00:48 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@5
Message:

Reverse how handlers are associated with the stream manager. Kick version.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • setup.py

    r3 r4  
    88
    99setup(name='wokkel',
    10       version='0.1.0',
     10      version='0.2.0',
    1111      description='Twisted Jabber support library',
    1212      author='Ralph Meijer',
  • wokkel/iwokkel.py

    r2 r4  
    1919    xmlstream = Attribute("""The managed XML stream""")
    2020
     21    def setHandlerParent(parent):
     22        """
     23        Set the parent of the handler.
     24
     25        @type parent: L{IXMPPHandlerCollection}
     26        """
     27
     28    def disownHandlerParent(parent):
     29        """
     30        Remove the parent of the handler.
     31
     32        @type parent: L{IXMPPHandlerCollection}
     33        """
     34
    2135    def makeConnection(xs):
    2236        """
     
    6074        """
    6175
     76class IXMPPHandlerCollection(Interface):
     77    """
     78    Collection of handlers.
     79
     80    Contain several handlers and manage their connection.
     81    """
     82
     83    def __iter__():
     84        """
     85        Get an iterator over all child handlers.
     86        """
     87
     88    def addHandler(handler):
     89        """
     90        Add a child handler.
     91
     92        @type handler: L{IXMPPHandler}
     93        """
     94
     95    def removeHandler(handler):
     96        """
     97        Remove a child handler.
     98
     99        @type handler: L{IXMPPHandler}
     100        """
    62101
    63102class IDisco(Interface):
  • wokkel/subprotocols.py

    r1 r4  
    1616from twisted.words.xish.domish import IElement
    1717
    18 from wokkel.iwokkel import IXMPPHandler
     18from wokkel.iwokkel import IXMPPHandler, IXMPPHandlerCollection
    1919
    2020class XMPPHandler(object):
    2121    implements(IXMPPHandler)
     22
     23    def setHandlerParent(self, parent):
     24        self.parent = parent
     25        self.parent.addHandler(self)
     26
     27    def disownHandlerParent(self, parent):
     28        self.parent.removeHandler(self)
     29        self.parent = None
    2230
    2331    def makeConnection(self, xs):
     
    4957                    L{xmlstream.XmlStream} for details.
    5058        """
    51         self.manager.send(obj)
    52 
    53 class XMPPHandlerContainer(object):
    54     """
    55     Container for XMPP subprotocol handlers.
    56     """
     59        self.parent.send(obj)
     60
     61
     62class XMPPHandlerCollection(object):
     63    """
     64    Collection of XMPP subprotocol handlers.
     65
     66    This allows for grouping of subprotocol handlers, but is not an
     67    L{XMPPHandler} itself, so this is not recursive.
     68
     69    @ivar xmlstream: Currently managed XML stream.
     70    @type xmlstream: L{XmlStream}
     71    @ivar handlers: List of protocol handlers.
     72    @type handlers: L{list} of objects providing
     73                      L{IXMPPHandler}
     74    """
     75
     76    implements(IXMPPHandlerCollection)
    5777
    5878    def __init__(self):
     
    7898
    7999        self.handlers.append(handler)
    80         handler.manager = self
    81100
    82101        # get protocol handler up to speed when a connection has already
     
    91110        """
    92111
    93         handler.manager = None
    94112        self.handlers.remove(handler)
    95113
    96 class StreamManager(XMPPHandlerContainer):
     114class StreamManager(XMPPHandlerCollection):
    97115    """
    98116    Business logic representing a managed XMPP connection.
     
    103121    using L{addHandler}.
    104122
    105     @ivar xmlstream: currently managed XML stream
    106     @type xmlstream: L{XmlStream}
    107     @ivar handlers: list of protocol handlers
    108     @type handlers: L{list} of objects providing
    109                       L{IXMPPHandler}
    110123    @ivar logTraffic: if true, log all traffic.
    111124    @type logTraffic: L{bool}
  • wokkel/test/test_pubsub.py

    r1 r4  
    2323    def test_onPublishNoNode(self):
    2424        handler = pubsub.PubSubService()
    25         handler.manager = self
     25        handler.parent = self
    2626        iq = domish.Element((None, 'iq'))
    2727        iq['from'] = 'user@example.org'
     
    4141
    4242        handler = Handler()
    43         handler.manager = self
     43        handler.parent = self
    4444        iq = domish.Element((None, 'iq'))
    4545        iq['type'] = 'set'
     
    5454    def test_onOptionsGet(self):
    5555        handler = pubsub.PubSubService()
    56         handler.manager = self
     56        handler.parent = self
    5757        iq = domish.Element((None, 'iq'))
    5858        iq['from'] = 'user@example.org'
  • wokkel/test/test_subprotocols.py

    r1 r4  
    2222
    2323
    24 class DummyXMPPHandler(object):
     24class DummyXMPPHandler(subprotocols.XMPPHandler):
    2525    def __init__(self):
    2626        self.doneMade = 0
     
    5656
    5757        handler = subprotocols.XMPPHandler()
    58         handler.manager = DummyStreamManager()
     58        handler.parent = DummyStreamManager()
    5959        handler.send('<presence/>')
    60         self.assertEquals(['<presence/>'], handler.manager.outlist)
     60        self.assertEquals(['<presence/>'], handler.parent.outlist)
    6161
    6262
     
    9090        sm = self.streamManager
    9191        handler = DummyXMPPHandler()
    92         sm.addHandler(handler)
     92        handler.setHandlerParent(sm)
    9393        xs = xmlstream.XmlStream(xmlstream.Authenticator())
    9494        sm._connected(xs)
     
    104104        sm = self.streamManager
    105105        handler = DummyXMPPHandler()
    106         sm.addHandler(handler)
     106        handler.setHandlerParent(sm)
    107107        xs = xmlstream.XmlStream(xmlstream.Authenticator())
    108108        sm._authd(xs)
     
    118118        sm = self.streamManager
    119119        handler = DummyXMPPHandler()
    120         sm.addHandler(handler)
     120        handler.setHandlerParent(sm)
    121121        xs = xmlstream.XmlStream(xmlstream.Authenticator())
    122122        sm._disconnected(xs)
     
    131131        sm = self.streamManager
    132132        handler = DummyXMPPHandler()
    133         sm.addHandler(handler)
     133        handler.setHandlerParent(sm)
    134134        self.assertIn(handler, sm)
    135         self.assertIdentical(sm, handler.manager)
     135        self.assertIdentical(sm, handler.parent)
    136136
    137137        self.assertEquals(0, handler.doneMade)
     
    153153        sm._authd(xs)
    154154        handler = DummyXMPPHandler()
    155         sm.addHandler(handler)
     155        handler.setHandlerParent(sm)
    156156
    157157        self.assertEquals(1, handler.doneMade)
     
    165165        sm = self.streamManager
    166166        handler = DummyXMPPHandler()
    167         sm.addHandler(handler)
    168         sm.removeHandler(handler)
     167        handler.setHandlerParent(sm)
     168        handler.disownHandlerParent(sm)
    169169        self.assertNotIn(handler, sm)
    170         self.assertIdentical(None, handler.manager)
     170        self.assertIdentical(None, handler.parent)
    171171
    172172    def test_sendInitialized(self):
Note: See TracChangeset for help on using the changeset viewer.