Changeset 443
- Timestamp:
- 02/13/03 15:09:42 (6 years ago)
- Files:
-
- trunk/RBTelepathy/RBTelepathy/Connection.py (modified) (3 diffs)
- trunk/RBTelepathy/RBTelepathy/Handlers (added)
- trunk/RBTelepathy/RBTelepathy/Handlers/__init__.py (added)
- trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py (modified) (3 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py (modified) (3 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py (modified) (5 diffs)
- trunk/RBTelepathy/RBTelepathy/Routing/RouterBase.py (modified) (2 diffs)
- trunk/RBTelepathy/RBTelepathy/SocketConnections.py (modified) (2 diffs)
- trunk/RBTelepathy/RBTelepathy/Stream/Protocol.py (modified) (4 diffs)
- trunk/RBTelepathy/RBTelepathy/Stream/SocketAdaptor.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBTelepathy/RBTelepathy/Connection.py
r442 r443 20 20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 21 22 """ 23 A Connection is the intermediatary between packet handlers and the 24 protocol. OnStreamPacket distributes inbound packets based on packet type 25 and namespace to the registered packet handler. Packet handlers 26 registrations are managed with the LoadHandler and UnloadHandler methods. 27 In this way, new features and functionality can be added within the 28 framework by simply extending the packet handler table. 29 30 The Connection is also the central repository for sharing state information 31 between packet handlers. So, common information like login id can be found 32 here, or a few steps from here. 33 34 Related Packages: 35 Packet 36 Stream 37 """ 38 22 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 40 #~ Imports … … 34 51 35 52 class Connection(object): 36 """37 A Connection is the intermediatary between packet handlers and the38 protocol. OnStreamPacket distributes inbound packets based on packet type39 and namespace to the registered packet handler. Packet handlers40 registrations are managed with the LoadHandler and UnloadHandler methods.41 In this way, new features and functionality can be added within the42 framework by simply extending the packet handler table.43 44 The Connection is also the central repository for sharing state information45 between packet handlers. So, common information like login id can be found46 here, or a few steps from here.47 48 Related Packages:49 Packet50 Stream51 """52 53 53 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 54 #~ Constants / Variables / Etc. … … 140 140 return packethandler.OnStreamPacket(packet, *args, **kw) 141 141 142 def OnS treamShutdown(self, how):142 def OnShutdown(self, how): 143 143 self.log.debug('Stream shutdown by "%s"', how) 144 144 trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py
r442 r443 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import logging 27 from xml.sax.saxutils import quoteattr as xmlquoteattr 28 29 from RBMBuilder import * 30 import RBMElements 31 import URIAddress 26 from PacketHandler import * 32 27 33 28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 46 41 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 42 48 class AuthenticationBaseHandler( object):43 class AuthenticationBaseHandler(PacketHandler): 49 44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50 45 #~ Constants / Variables / Etc. … … 53 48 ElementFactories = {(RBMessagingNamespace, 'authentication'): EF.Static(AuthenticationElement)} 54 49 StreamPacketHandlers = ElementFactories.keys() 55 RoutedPacketHandlers = {}56 50 57 51 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py
r442 r443 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import logging 27 from RBMBuilder import * 28 import RBMElements 26 from PacketHandler import * 29 27 30 28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 43 41 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 44 42 45 class ErrorHandler( object):43 class ErrorHandler(PacketHandler): 46 44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 45 #~ Constants / Variables / Etc. … … 50 48 ElementFactories = {(RBMessagingNamespace, 'error'): EF.Static(ErrorElement)} 51 49 StreamPacketHandlers = ElementFactories.keys() 52 RoutedPacketHandlers = {}53 50 54 51 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py
r442 r443 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import logging 26 from PacketHandler import * 27 27 import copy 28 29 from RBMBuilder import *30 import RBMElements31 import RBMStreamElements32 from RBMessaging import ErrorTypes33 28 34 29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 51 46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 47 53 class HostMessageHandler( object):48 class HostMessageHandler(PacketHandler): 54 49 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 50 #~ Constants / Variables / Etc. … … 58 53 ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 59 54 StreamPacketHandlers = ElementFactories.keys() 60 RoutedPacketHandlers = {}61 55 62 56 log = logging.getLogger('HostMessageHandler') … … 100 94 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 95 102 class ClientMessageHandler( object):96 class ClientMessageHandler(PacketHandler): 103 97 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 104 98 #~ Constants / Variables / Etc. … … 107 101 ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 108 102 StreamPacketHandlers = ElementFactories.keys() 109 RoutedPacketHandlers = {}110 103 111 log = logging.getLogger(' HostMessageHandler')104 log = logging.getLogger('ClientMessageHandler') 112 105 113 106 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBTelepathy/RBTelepathy/Routing/RouterBase.py
r442 r443 20 20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 21 22 """ 23 Routers are responsible for directing traffic between packet handlers, and 24 thereby, between Connections. There are many ways to route these packets, 25 and possibly just as many different interfaces needed to do so. This 26 interface takes a fairly simple and extensible approach to allowing for 27 these different implementations, while still providing some structure. 28 """ 29 22 30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 31 #~ Imports … … 31 39 32 40 class RouterBase(object): 33 """34 Routers are responsible for directing traffic between packet handlers, and35 thereby, between Connections. There are many ways to route these packets,36 and possibly just as many different interfaces needed to do so. This37 interface takes a fairly simple and extensible approach to allowing for38 these different implementations, while still providing some structure.39 """40 41 41 def RoutePacket(self, *args, **kw): 42 42 """Synonym for OnRoutedPacket""" trunk/RBTelepathy/RBTelepathy/SocketConnections.py
r442 r443 72 72 protocol.stream = stream 73 73 stream.OnRecvStreamData = WeakBindCallable(protocol.OnRecvStreamData) 74 stream.OnShutdown = WeakBindCallable(protocol._OnS treamShutdown)74 stream.OnShutdown = WeakBindCallable(protocol._OnShutdown) 75 75 76 76 # Create and setup the connection … … 78 78 self.protocol = protocol 79 79 protocol.OnStreamPacket = WeakBindCallable(self.OnStreamPacket) 80 protocol.OnS treamShutdown = WeakBindCallable(self.OnStreamShutdown)80 protocol.OnShutdown = WeakBindCallable(self.OnShutdown) 81 81 82 82 # Setup model links trunk/RBTelepathy/RBTelepathy/Stream/Protocol.py
r442 r443 19 19 ##~ 20 20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 22 """ 23 Stream Protocol is a fairly complicated adapter between the Connection/Packet 24 Handlers and the Stream Data representation. To summarize the functionality, 25 the protocol takes data piece by piece from the stream interface, assembles it 26 into packets using the packetbuilder set by the connection. Once a packet is 27 complete, it is send to the connection via the OnStreamPacket method which is 28 meant to be reassigned. The same goes for OnShutdown. 29 30 On the outbound packet side, OnOutboundPacket is used to turn packets into 31 Stream data. It assumes that the packet passed to it either can be converted 32 to a string, or that the packet supports the GetStreamHeader and GetStreamData 33 methods of the Streaming interface. 34 """ 21 35 22 36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 50 64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 51 65 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): 53 71 """Called from Connection to convert a packet to stream data via this protocol. 54 72 Packet is required to implement GetStreamHeader and GetStreamData for this method to work. 55 73 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), '' 58 79 else: 59 streamdata = ''.join((packet.GetStreamHeader(), self.delimiter, packet.GetStreamData())) 80 StreamHeader, StreamData = StreamHeader(), StreamData() 81 StreamData = ''.join((StreamHeader, self.delimiter, StreamData)) 60 82 self.stream.write(streamdata) 61 SendPacket = OnPacket62 83 63 84 def OnRecvStreamData(self, streamdata): 64 85 """Called from Stream object to introduce more raw stream bytes into the system""" 65 86 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 70 89 71 90 while self.ProcessData(): … … 134 153 pass 135 154 136 def OnS treamShutdown(self, how):155 def OnShutdown(self, how): 137 156 pass 138 157 … … 182 201 raise 183 202 184 def _OnS treamShutdown(self, how):185 return self.OnS treamShutdown(how)186 203 def _OnShutdown(self, how): 204 return self.OnShutdown(how) 205 trunk/RBTelepathy/RBTelepathy/Stream/SocketAdaptor.py
r437 r443 19 19 ##~ 20 20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 22 """ 23 The SocketStream and LockingSocketStream classes try to be as lightweight as 24 practical, yet still helpful. They mainly provide an adaption between the 25 RBFoundation.SmartSelect module, sockets, and the RBMessaging architecture. 26 Their main responsiblity is to keep watch and interface with on the socket 27 state including send, receive, shutdown, and other errors. Furthermore, since 28 RBMessaging is based on a push model, as data is read from the socket, that 29 data is pushed to OnRecvStreamData which is intended to be reassigned. The 30 same idea is applied to the OnShutdown event. 31 """ 21 32 22 33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 185 196 186 197 class LockingSocketStream(SocketStream): 198 """Same functionality of SocketStream, except that SendData access is guarded by a lock.""" 199 187 200 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 188 201 #~ Constants / Variables / Etc.
