예제 #1
0
    def test_putNamedChild_duplicate(self):
        "check that duplicate resources work"
        with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi:
            request = DummyRequest(['path', 'to', 'child'])
            actual_res = getChildForRequest(self.hr, request)
            self.assertEqual(actual_res, self.res)  # Before duplicate

            duplicate = NamedResource(self.res.namespace)
            self.hr.putNamedChild(duplicate)
            request = DummyRequest(['path', 'to', 'child'])
            actual_duplicate_res = getChildForRequest(self.hr, request)
            self.assertEqual(duplicate,
                             actual_duplicate_res)  # After duplicate
예제 #2
0
import sys

from autobahn.twisted.websocket import WebSocketServerFactory
from hendrix.contrib. async .messaging import hxdispatcher
from hendrix.deploy.base import HendrixDeploy
from hendrix.experience import hey_joe
from hendrix.facilities.resources import NamedResource
from twisted.python import log

message_resource = NamedResource('hendrix-demo')

from twisted.conch.telnet import TelnetTransport, TelnetProtocol
from twisted.internet.protocol import ServerFactory


class TelnetToWebsocket(TelnetProtocol):
    def dataReceived(self, data):
        hxdispatcher.send('noodly_messages', data)


telnet_server_factory = ServerFactory()
telnet_server_factory.protocol = lambda: TelnetTransport(TelnetToWebsocket)

deployer = HendrixDeploy(options={'wsgi': 'hendrix_demo.wsgi.application'})
deployer.resources.append(message_resource)

log.startLogging(sys.stdout)

factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
factory.protocol = hey_joe.MyServerProtocol
예제 #3
0
 def setUp(self):
     path = '/path/to/child/'
     self.res = NamedResource(path)
     self.hr = HendrixResource(None, None, None)
     self.hr.putNamedChild(self.res)
예제 #4
0
파일: resources.py 프로젝트: leanhd/hendrix
            self.dispatcher.send(address, data)

        except Exception as e:
            raise
            self.dispatcher.send(
                self.guid,
                {'message': data, 'error': str(e)}
            )

    def connectionMade(self):
        """
        establish the address of this new connection and add it to the list of
        sockets managed by the dispatcher

        reply to the transport with a "setup_connection" notice
        containing the recipient's address for use by the client as a return
        address for future communications
        """
        self.transport.uid = str(uuid.uuid1())

        self.guid = self.dispatcher.add(self.transport)
        self.dispatcher.send(self.guid, {'setup_connection': self.guid})

    def connectionLost(self, something):
        "clean up the no longer useful socket in the dispatcher"
        self.dispatcher.remove(self.transport)


MessageResource = NamedResource('messages')