Changeset 443

Show
Ignore:
Timestamp:
02/13/03 15:09:42 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBTelepathy/RBTelepathy/Connection.py

    r442 r443  
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2121 
     22""" 
     23A Connection is the intermediatary between packet handlers and the 
     24protocol.  OnStreamPacket distributes inbound packets based on packet type 
     25and namespace to the registered packet handler.  Packet handlers 
     26registrations are managed with the LoadHandler and UnloadHandler methods. 
     27In this way, new features and functionality can be added within the 
     28framework by simply extending the packet handler table. 
     29 
     30The Connection is also the central repository for sharing state information 
     31between packet handlers.  So, common information like login id can be found 
     32here, or a few steps from here. 
     33 
     34Related Packages: 
     35    Packet 
     36    Stream 
     37""" 
     38 
    2239#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2340#~ Imports  
     
    3451 
    3552class Connection(object): 
    36     """ 
    37     A Connection is the intermediatary between packet handlers and the 
    38     protocol.  OnStreamPacket distributes inbound packets based on packet type 
    39     and namespace to the registered packet handler.  Packet handlers 
    40     registrations are managed with the LoadHandler and UnloadHandler methods. 
    41     In this way, new features and functionality can be added within the 
    42     framework by simply extending the packet handler table. 
    43  
    44     The Connection is also the central repository for sharing state information 
    45     between packet handlers.  So, common information like login id can be found 
    46     here, or a few steps from here. 
    47  
    48     Related Packages: 
    49         Packet 
    50         Stream 
    51     """ 
    52  
    5353    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5454    #~ Constants / Variables / Etc.  
     
    140140        return packethandler.OnStreamPacket(packet, *args, **kw) 
    141141 
    142     def OnStreamShutdown(self, how): 
     142    def OnShutdown(self, how): 
    143143        self.log.debug('Stream shutdown by "%s"', how) 
    144144 
  • trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py

    r442 r443  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
    26 import logging 
    27 from xml.sax.saxutils import quoteattr as xmlquoteattr 
    28  
    29 from RBMBuilder import * 
    30 import RBMElements 
    31 import URIAddress 
     26from PacketHandler import * 
    3227 
    3328#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4641#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4742 
    48 class AuthenticationBaseHandler(object): 
     43class AuthenticationBaseHandler(PacketHandler): 
    4944    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5045    #~ Constants / Variables / Etc.  
     
    5348    ElementFactories = {(RBMessagingNamespace, 'authentication'): EF.Static(AuthenticationElement)} 
    5449    StreamPacketHandlers = ElementFactories.keys() 
    55     RoutedPacketHandlers = {} 
    5650 
    5751    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py

    r442 r443  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
    26 import logging 
    27 from RBMBuilder import * 
    28 import RBMElements 
     26from PacketHandler import * 
    2927 
    3028#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4341#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4442 
    45 class ErrorHandler(object): 
     43class ErrorHandler(PacketHandler): 
    4644    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4745    #~ Constants / Variables / Etc.  
     
    5048    ElementFactories = {(RBMessagingNamespace, 'error'): EF.Static(ErrorElement)} 
    5149    StreamPacketHandlers = ElementFactories.keys() 
    52     RoutedPacketHandlers = {} 
    5350 
    5451    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py

    r442 r443  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
    26 import logging 
     26from PacketHandler import * 
    2727import copy 
    28  
    29 from RBMBuilder import * 
    30 import RBMElements 
    31 import RBMStreamElements 
    32 from RBMessaging import ErrorTypes 
    3328 
    3429#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    5146#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5247 
    53 class HostMessageHandler(object): 
     48class HostMessageHandler(PacketHandler): 
    5449    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5550    #~ Constants / Variables / Etc.  
     
    5853    ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 
    5954    StreamPacketHandlers = ElementFactories.keys() 
    60     RoutedPacketHandlers = {} 
    6155 
    6256    log = logging.getLogger('HostMessageHandler') 
     
    10094#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    10195 
    102 class ClientMessageHandler(object): 
     96class ClientMessageHandler(PacketHandler): 
    10397    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    10498    #~ Constants / Variables / Etc.  
     
    107101    ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 
    108102    StreamPacketHandlers = ElementFactories.keys() 
    109     RoutedPacketHandlers = {} 
    110103 
    111     log = logging.getLogger('HostMessageHandler') 
     104    log = logging.getLogger('ClientMessageHandler') 
    112105 
    113106    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBTelepathy/RBTelepathy/Routing/RouterBase.py

    r442 r443  
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2121 
     22""" 
     23Routers are responsible for directing traffic between packet handlers, and 
     24thereby, between Connections.  There are many ways to route these packets, 
     25and possibly just as many different interfaces needed to do so.  This 
     26interface takes a fairly simple and extensible approach to allowing for 
     27these different implementations, while still providing some structure. 
     28""" 
     29 
    2230#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2331#~ Imports  
     
    3139 
    3240class RouterBase(object): 
    33     """ 
    34     Routers are responsible for directing traffic between packet handlers, and 
    35     thereby, between Connections.  There are many ways to route these packets, 
    36     and possibly just as many different interfaces needed to do so.  This 
    37     interface takes a fairly simple and extensible approach to allowing for 
    38     these different implementations, while still providing some structure. 
    39     """ 
    40  
    4141    def RoutePacket(self, *args, **kw): 
    4242        """Synonym for OnRoutedPacket""" 
  • trunk/RBTelepathy/RBTelepathy/SocketConnections.py

    r442 r443  
    7272        protocol.stream = stream 
    7373        stream.OnRecvStreamData = WeakBindCallable(protocol.OnRecvStreamData) 
    74         stream.OnShutdown = WeakBindCallable(protocol._OnStreamShutdown) 
     74        stream.OnShutdown = WeakBindCallable(protocol._OnShutdown) 
    7575 
    7676        # Create and setup the connection 
     
    7878        self.protocol = protocol 
    7979        protocol.OnStreamPacket = WeakBindCallable(self.OnStreamPacket) 
    80         protocol.OnStreamShutdown = WeakBindCallable(self.OnStreamShutdown) 
     80        protocol.OnShutdown = WeakBindCallable(self.OnShutdown) 
    8181 
    8282        # Setup model links 
  • trunk/RBTelepathy/RBTelepathy/Stream/Protocol.py

    r442 r443  
    1919##~ 
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     21 
     22""" 
     23Stream Protocol is a fairly complicated adapter between the Connection/Packet 
     24Handlers and the Stream Data representation.  To summarize the functionality, 
     25the protocol takes data piece by piece from the stream interface, assembles it 
     26into packets using the packetbuilder set by the connection.  Once a packet is 
     27complete, it is send to the connection via the OnStreamPacket method which is 
     28meant to be reassigned.  The same goes for OnShutdown. 
     29 
     30On the outbound packet side, OnOutboundPacket is used to turn packets into 
     31Stream data.  It assumes that the packet passed to it either can be converted 
     32to a string, or that the packet supports the GetStreamHeader and GetStreamData 
     33methods of the Streaming interface. 
     34""" 
    2135 
    2236#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    5064    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5165 
    52     def OnPacket(self, packet): 
     66    def SendPacket(self, *args, **kw): 
     67        """Synonym for OnOutboundPacket""" 
     68        return self.OnOutboundPacket(*args, **kw) 
     69 
     70    def OnOutboundPacket(self, packet): 
    5371        """Called from Connection to convert a packet to stream data via this protocol. 
    5472        Packet is required to implement GetStreamHeader and GetStreamData for this method to work. 
    5573        Optionally, packet can be the raw header string.""" 
    56         if isinstance(packet, (str, unicode)): 
    57             streamdata = packet + self.delimiter 
     74        try: 
     75            StreamHeader = packet.GetStreamHeader 
     76            StreamData = packet.GetStreamData 
     77        except AttributeError: 
     78            StreamHeader, StreamData = str(packet), '' 
    5879        else: 
    59             streamdata = ''.join((packet.GetStreamHeader(), self.delimiter, packet.GetStreamData())) 
     80            StreamHeader, StreamData = StreamHeader(), StreamData() 
     81        StreamData = ''.join((StreamHeader, self.delimiter, StreamData)) 
    6082        self.stream.write(streamdata) 
    61     SendPacket = OnPacket 
    6283 
    6384    def OnRecvStreamData(self, streamdata): 
    6485        """Called from Stream object to introduce more raw stream bytes into the system""" 
    6586        if streamdata: 
    66             if self.data:  
    67                 self.data += streamdata 
    68             else:  
    69                 self.data = streamdata 
     87            if self.data: self.data += streamdata 
     88            else: self.data = streamdata 
    7089 
    7190        while self.ProcessData(): 
     
    134153        pass 
    135154 
    136     def OnStreamShutdown(self, how): 
     155    def OnShutdown(self, how): 
    137156        pass 
    138157 
     
    182201                raise 
    183202 
    184     def _OnStreamShutdown(self, how): 
    185         return self.OnStreamShutdown(how) 
    186  
     203    def _OnShutdown(self, how): 
     204        return self.OnShutdown(how) 
     205 
  • trunk/RBTelepathy/RBTelepathy/Stream/SocketAdaptor.py

    r437 r443  
    1919##~ 
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     21 
     22""" 
     23The SocketStream and LockingSocketStream classes try to be as lightweight as 
     24practical, yet still helpful.  They mainly provide an adaption between the 
     25RBFoundation.SmartSelect module, sockets, and the RBMessaging architecture. 
     26Their main responsiblity is to keep watch and interface with on the socket 
     27state including send, receive, shutdown, and other errors.  Furthermore, since 
     28RBMessaging is based on a push model, as data is read from the socket, that 
     29data is pushed to OnRecvStreamData which is intended to be reassigned.  The 
     30same idea is applied to the OnShutdown event. 
     31""" 
    2132 
    2233#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    185196 
    186197class LockingSocketStream(SocketStream): 
     198    """Same functionality of SocketStream, except that SendData access is guarded by a lock.""" 
     199 
    187200    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    188201    #~ Constants / Variables / Etc.