Changeset 415

Show
Ignore:
Timestamp:
01/23/03 01:47:44 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/URIparser.py

    r414 r415  
    119119 
    120120    def __repr__(self): 
    121         return '<%s>' % (self.geturi(),
     121        return repr(self.geturi()
    122122 
    123123    def __str__(self): 
  • trunk/RBFoundation/RBFoundation/XMLObjectify.py

    r406 r415  
    265265        """Removes all elements matching node.""" 
    266266        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 
    271276        if len(lst) != len(self._elements): 
    272277            self._elements = lst 
  • trunk/RBMessaging/RBMessaging/Model.py

    r413 r415  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26import weakref 
     27 
    2628import Connection 
    2729from RBFoundation import SmartSelect 
     
    3941        self.Connections = {} 
    4042        self.Routers = {} 
     43 
     44    def GetRouter(self, key): 
     45        try: 
     46            return weakref.proxy(self.Routers[key]) 
     47        except KeyError: 
     48            return None 
    4149 
    4250    def Process(self, timeout): 
  • trunk/RBTelepathy/RBTelepathy/Packet/AuthenticationHandler.py

    r414 r415  
    4242            (RBMessagingNamespace, ): EF.Static(RBMElements.PacketChildElement), 
    4343        }) 
    44  
    45     def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 
    46         return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 
     44    _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 
    4745 
    4846#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    6159    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    6260 
    63     def __init__(self): 
     61    def __init__(self, connection): 
    6462        self._ValidTypes = {} 
    6563 
     
    9694#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    9795 
    98 class ServerAuthenticationHandler(AuthenticationBaseHandler): 
     96class HostAuthenticationHandler(AuthenticationBaseHandler): 
    9997    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    10098    #~ Constants / Variables / Etc.  
    10199    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    102100 
    103     log = logging.getLogger('ServerAuthenticationHandler') 
     101    log = logging.getLogger('HostAuthenticationHandler') 
    104102 
    105103    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    107105    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    108106 
    109     def __init__(self): 
    110         AuthenticationBaseHandler.__init__(self
     107    def __init__(self, connection): 
     108        AuthenticationBaseHandler.__init__(self, connection
    111109        self._EnableType('query') 
    112110        self._EnableType('select') 
     
    139137            self._reply_success(connection, packet, *args, **kw) 
    140138        else: 
    141             connection.OnAuthenticated(False, None
     139            connection.OnAuthenticated(False, simple.addr
    142140            self._reply_failure(connection, packet, *args, **kw) 
    143141 
  • trunk/RBTelepathy/RBTelepathy/Packet/Elements.py

    r412 r415  
    2727from RBFoundation.XMLClassBuilder import XMLClassBuilderObjectMixin 
    2828from RBFoundation.XMLObjectify import BaseObjectifiedXML, AttributedObjectifiedXML, ObjectifiedXML 
     29 
     30from RBMBuilder import RBMessagingNamespace 
    2931import URIAddress 
    3032 
     
    105107class RouteableRootElement(RootElementBase): 
    106108    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 
    109112 
    110113    def SetAddresses(self, addresses, nodename='to'): 
    111114        # 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
    113116        if existing: 
    114117            idxAddresses = self._getElementIndex(existing[0]) 
     
    119122 
    120123        # Remove all existing addresses 
    121         self._delElements(node=nodename, namespace=self.__namespace__
     124        self._delElements(node=nodename, namespace=RBMessagingNamespace
    122125 
    123126        for address in addresses: 
     
    139142    def OnUpdateContent(self): 
    140143        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) 
    145145 
    146146    #~ addr property ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBTelepathy/RBTelepathy/Packet/ErrorHandler.py

    r414 r415  
    3232#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3333 
    34 class ErrorElement(RBMElements.RootElementBase, XMLClassBuilderBaseMixin): 
     34class ErrorElement(RBMElements.RootElementBase, XMLClassBuilderObjectMixin): 
    3535    NamespaceSynonyms = RBNamespaceSynonyms 
    3636    DefaultNamespace = RBNamespaceSynonyms[None] 
     
    3939        }) 
    4040 
    41     def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 
    42         return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 
     41    _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 
    4342 
    4443#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    5251    StreamPacketHandlers = ElementFactories.keys() 
    5352    RoutedPacketHandlers = () 
     53 
     54    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     55    #~ Public Methods  
     56    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     57 
     58    def __init__(self, connection): 
     59        pass 
    5460 
    5561#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBTelepathy/RBTelepathy/Packet/MessageHandler.py

    r414 r415  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26import logging 
     27import copy 
     28 
    2629from RBMBuilder import * 
    2730import RBMElements 
     31import RBMStreamElements 
     32from RBMessaging import ErrorTypes 
    2833 
    2934#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    3136#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3237 
    33 class MessageElement(RBMElements.RouteableRootElement, RBM.StreamRootElement, XMLClassBuilderBaseMixin): 
     38class MessageElement(RBMElements.RouteableRootElement, RBMElements.StreamRootElement, XMLClassBuilderObjectMixin): 
    3439    NamespaceSynonyms = RBNamespaceSynonyms 
    3540    DefaultNamespace = RBNamespaceSynonyms[None] 
    3641    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), 
    4047        }) 
    4148 
    42     def _xmlChildFactory(self, owner, parent, node, attributes, namespacemap): 
    43         return self.ElementFactorySet._GetElementFactory(owner, parent, node, attributes, namespacemap) 
     49    _xmlChildFactory = XMLClassBuilderObjectMixin._xmlChildFactory 
    4450 
    4551#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4652 
    47 class MessageHandler(object): 
     53class HostMessageHandler(object): 
    4854    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4955    #~ Constants / Variables / Etc.  
    5056    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5157 
    52     ElementFactories = {(RBMessagingNamespace, 'message'), EF.Static(MessageElement)} 
     58    ElementFactories = {(RBMessagingNamespace, 'message'): EF.Static(MessageElement)} 
    5359    StreamPacketHandlers = ElementFactories.keys() 
    54     RoutedPacketHandlers = () 
     60    RoutedPacketHandlers = ElementFactories.keys() 
     61 
     62    log = logging.getLogger('HostMessageHandler') 
    5563 
    5664    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     65    #~ Public Methods  
     66    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5767 
    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] 
    6774 
    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) 
    7282 
    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 
     101class 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  
    3737        """Finds destination route(s) for address. 
    3838        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 
    4041