Changeset 415
- Timestamp:
- 01/23/03 01:47:44 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/URIparser.py (modified) (1 diff)
- trunk/RBFoundation/RBFoundation/XMLObjectify.py (modified) (1 diff)
- trunk/RBMessaging/RBMessaging/Model.py (modified) (2 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py (modified) (5 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/Elements.py (modified) (4 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py (modified) (3 diffs)
- trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py (modified) (2 diffs)
- trunk/RBTelepathy/RBTelepathy/Routing/SimpleRouter.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/URIparser.py
r414 r415 119 119 120 120 def __repr__(self): 121 return '<%s>' % (self.geturi(),)121 return repr(self.geturi()) 122 122 123 123 def __str__(self): trunk/RBFoundation/RBFoundation/XMLObjectify.py
r406 r415 265 265 """Removes all elements matching node.""" 266 266 lst = self._elements 267 if node is not None: 268 lst = [x for x in lst if x[0][-1] != node] 269 if namespace is not None: 270 lst = [x for x in lst if x[0][0] != namespace] 267 if namespace is None: 268 if node is not None: 269 lst = [x for x in lst if x[0][-1] != node] 270 elif node is None: 271 if namespace is not None: 272 lst = [x for x in lst if x[0][0] != namespace] 273 else: 274 lst = [x for x in lst if x[0] != (namespace, node)] 275 271 276 if len(lst) != len(self._elements): 272 277 self._elements = lst trunk/RBMessaging/RBMessaging/Model.py
r413 r415 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import weakref 27 26 28 import Connection 27 29 from RBFoundation import SmartSelect … … 39 41 self.Connections = {} 40 42 self.Routers = {} 43 44 def GetRouter(self, key): 45 try: 46 return weakref.proxy(self.Routers[key]) 47 except KeyError: 48 return None 41 49 42 50 def Process(self, timeout): trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py
r414 r415 42 42 (RBMessagingNamespace, ): EF.Static(RBMElements.PacketChildElement), 43 43 }) 44 45 def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 46 return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 44 _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 47 45 48 46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 61 59 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 60 63 def __init__(self ):61 def __init__(self, connection): 64 62 self._ValidTypes = {} 65 63 … … 96 94 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 97 95 98 class ServerAuthenticationHandler(AuthenticationBaseHandler):96 class HostAuthenticationHandler(AuthenticationBaseHandler): 99 97 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 100 98 #~ Constants / Variables / Etc. 101 99 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 100 103 log = logging.getLogger(' ServerAuthenticationHandler')101 log = logging.getLogger('HostAuthenticationHandler') 104 102 105 103 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 107 105 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 108 106 109 def __init__(self ):110 AuthenticationBaseHandler.__init__(self )107 def __init__(self, connection): 108 AuthenticationBaseHandler.__init__(self, connection) 111 109 self._EnableType('query') 112 110 self._EnableType('select') … … 139 137 self._reply_success(connection, packet, *args, **kw) 140 138 else: 141 connection.OnAuthenticated(False, None)139 connection.OnAuthenticated(False, simple.addr) 142 140 self._reply_failure(connection, packet, *args, **kw) 143 141 trunk/RBTelepathy/RBTelepathy/Packet/Elements.py
r412 r415 27 27 from RBFoundation.XMLClassBuilder import XMLClassBuilderObjectMixin 28 28 from RBFoundation.XMLObjectify import BaseObjectifiedXML, AttributedObjectifiedXML, ObjectifiedXML 29 30 from RBMBuilder import RBMessagingNamespace 29 31 import URIAddress 30 32 … … 105 107 class RouteableRootElement(RootElementBase): 106 108 def GetAddresses(self, nodename='to'): 107 existing = self._getElements(node=nodename, namespace=self.__namespace__) 108 return [each.addr for each in existing] 109 existing = self._getElements(node=nodename, namespace=RBMessagingNamespace) 110 result = [each.addr for each in existing] 111 return result 109 112 110 113 def SetAddresses(self, addresses, nodename='to'): 111 114 # Figure out which addresses we are to maintain 112 existing = self._getElements(node=nodename, namespace= self.__namespace__)115 existing = self._getElements(node=nodename, namespace=RBMessagingNamespace) 113 116 if existing: 114 117 idxAddresses = self._getElementIndex(existing[0]) … … 119 122 120 123 # Remove all existing addresses 121 self._delElements(node=nodename, namespace= self.__namespace__)124 self._delElements(node=nodename, namespace=RBMessagingNamespace) 122 125 123 126 for address in addresses: … … 139 142 def OnUpdateContent(self): 140 143 RootElementBase.OnUpdateContent(self) 141 if self._addr is None: 142 try: del self._attributes['addr'] 143 except KeyError: pass 144 else: self._attributes['addr'] = str(self._addr) 144 self._attributes['addr'] = str(self.addr) 145 145 146 146 #~ addr property ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py
r414 r415 32 32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 33 34 class ErrorElement(RBMElements.RootElementBase, XMLClassBuilder BaseMixin):34 class ErrorElement(RBMElements.RootElementBase, XMLClassBuilderObjectMixin): 35 35 NamespaceSynonyms = RBNamespaceSynonyms 36 36 DefaultNamespace = RBNamespaceSynonyms[None] … … 39 39 }) 40 40 41 def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 42 return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 41 _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 43 42 44 43 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 52 51 StreamPacketHandlers = ElementFactories.keys() 53 52 RoutedPacketHandlers = () 53 54 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 #~ Public Methods 56 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 57 58 def __init__(self, connection): 59 pass 54 60 55 61 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py
r414 r415 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import logging 27 import copy 28 26 29 from RBMBuilder import * 27 30 import RBMElements 31 import RBMStreamElements 32 from RBMessaging import ErrorTypes 28 33 29 34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 31 36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 32 37 33 class MessageElement(RBMElements.RouteableRootElement, RBM .StreamRootElement, XMLClassBuilderBaseMixin):38 class MessageElement(RBMElements.RouteableRootElement, RBMElements.StreamRootElement, XMLClassBuilderObjectMixin): 34 39 NamespaceSynonyms = RBNamespaceSynonyms 35 40 DefaultNamespace = RBNamespaceSynonyms[None] 36 41 ElementFactories = ElementFactorySet({ 37 (RBMessagingNamespace, 'to'): EF.Static(RBMElements.PacketChildElement), 38 (RBMessagingNamespace, 'from'): EF.Static(RBMElements.PacketChildElement), 39 (RBMessagingNamespace, 'stream'): EF.Static(RBMElements.PacketChildElement), 42 (RBMessagingNamespace, 'to'): EF.Static(RBMElements.URIAddressElement), 43 (RBMessagingNamespace, 'from'): EF.Static(RBMElements.URIAddressElement), 44 (RBMessagingNamespace, 'stream'): RBMStreamElements.StreamFormatFactory(), 45 (RBMessagingNamespace, ): EF.Static(RBMElements.PacketChildElement), 46 None: EF.Static(RBMElements.PacketChildElement), 40 47 }) 41 48 42 def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 43 return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 49 _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 44 50 45 51 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 46 52 47 class MessageHandler(object):53 class HostMessageHandler(object): 48 54 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49 55 #~ Constants / Variables / Etc. 50 56 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 51 57 52 ElementFactories = {(RBMessagingNamespace, 'message') ,EF.Static(MessageElement)}58 ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 53 59 StreamPacketHandlers = ElementFactories.keys() 54 RoutedPacketHandlers = () 60 RoutedPacketHandlers = ElementFactories.keys() 61 62 log = logging.getLogger('HostMessageHandler') 55 63 56 64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 65 #~ Public Methods 66 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 57 67 58 # XXX: OLD CODE 59 ##def OnRoutedPacket(self, packet, addresses): 60 ## # Copy the root level packet, so we can adjust it's addresses 61 ## packet = copy.copy(packet) 62 ## # Change the address lists in the packet 63 ## packet.SetAddresses(addresses) 64 ## self.log.debug('Sending routed packet to protocol') 65 ## # Send the packet to the stream protocol 66 ## self.protocol.SendPacket(packet) 68 def __init__(self, connection): 69 self.router = connection.model().GetRouter((RBMessagingNamespace, 'message')) 70 if self.router: 71 key = connection.loginaddr.authority 72 self.log.info('Registering %r with router', key) 73 self.router.AuthorityRoutes[key] = [connection] 67 74 68 ##def GetRouter(self): 69 ## try: return self.router 70 ## except AttributeError: 71 ## raise AttributeError, '%s has no connection to the router' % (self.__class__.__name__, ) 75 def OnRoutedPacket(self, connection, packet, addresses): 76 # Copy the root level packet, so we can adjust it's addresses 77 packet = copy.copy(packet) 78 # Change the address lists in the packet 79 packet.SetAddresses(addresses) 80 self.log.debug('Sending routed packet to protocol') 81 connection.SendPacket(packet) 72 82 73 ##def _PKT__message(self, packet): 74 ## # TODO: Flush out 75 ## #fromlist = packet.GetAddresses('from') 76 ## #if fromlist: 77 ## # raise ValueError, '"from" element not allowed on a user connection' 78 ## tolist = packet.GetAddresses('to') 79 ## self.log.info('Sending "%s" packet to Router', packet.__node__) 80 ## routecommands = self.GetRouter().RoutePacket(packet, tolist) 81 ## if routecommands: 82 ## self.log.debug('Sending routed packet "%s" to destination', packet.__node__) 83 ## return [routecmd() for routecmd in routecommands] 84 ## else: return () 83 def OnStreamPacket(self, connection, packet): 84 # TODO: Flush out 85 #fromlist = packet.GetAddresses('from') 86 #if fromlist: 87 # raise ValueError, '"from" element not allowed on a user connection' 88 tolist = packet.GetAddresses('to') 89 90 self.log.info('Sending "%s" packet to Router', packet.__node__) 91 if not self.router: 92 raise ErrorTypes.RoutingError, 'No router available' 93 routecommands = self.router.RoutePacket(packet, tolist) 94 if routecommands: 95 self.log.debug('Sending routed packet "%s" to destination', packet.__node__) 96 return [routecmd() for routecmd in routecommands] 97 else: return () 98 99 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 100 101 class ClientMessageHandler(object): 102 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 103 #~ Constants / Variables / Etc. 104 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 105 106 ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 107 StreamPacketHandlers = ElementFactories.keys() 108 RoutedPacketHandlers = ElementFactories.keys() 109 110 log = logging.getLogger('HostMessageHandler') 111 112 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 113 #~ Public Methods 114 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 115 116 def __init__(self, connection): 117 router = connection.model().Routers.get((RBMessagingNamespace, 'message'), None) 118 119 def OnRoutedPacket(self, connection, packet, addresses): 120 print '<!-- OnRoutedPacket -->' 121 print packet._toXML() 122 print 123 124 def OnStreamPacket(self, connection, packet): 125 print '<!-- OnStreamPacket -->' 126 print packet._toXML() 127 print 128 trunk/RBTelepathy/RBTelepathy/Routing/SimpleRouter.py
r406 r415 37 37 """Finds destination route(s) for address. 38 38 If multiple are routes are provided, the packet will be sent to all returned.""" 39 return self.AuthorityRoutes.get(address.authority) 39 result = self.AuthorityRoutes.get(address.authority) 40 return result 40 41
