Beispiel #1
0
    def frombytes(cls, byte_string):
        """
        Parse an AWS request from a byte string.

        @param byte_string: The request as parsed from a C{.req} file.
        @type byte_string: L{bytes}

        @return: A request object.
        @rtype: L{_AWSRequest}
        """
        # Ensure there's a blank line so that status and header
        # parsing completes.
        blank_line = b'\n\n'
        if blank_line not in byte_string:
            byte_string += blank_line

        channel = HTTPChannel()
        channel.delimiter = b'\n'
        channel.makeConnection(StringTransport())
        channel.dataReceived(byte_string)
        channel.connectionLost(ConnectionDone())
        request = channel.requests[-1]

        method = request.method
        path = request.uri
        headers = dict(request.requestHeaders.getAllRawHeaders())
        # what comes after the empty line is a
        body = byte_string.split(blank_line, 1)[-1]

        return cls(method, path, headers, body)
Beispiel #2
0
class YaybuChannel(channel.SSHChannel):

    name = 'session'

    def __init__(self, task):
        channel.SSHChannel.__init__(self)
        self.protocol = HTTPChannel()
        self.protocol.requestFactory = self.request_factory
        self.protocol.transport = self
        self.disconnecting = False
        self.task = task

    def request_factory(self):
        return YaybuRequest(self.task)

    def openFailed(self, reason):
        print 'echo failed', reason

    def channelOpen(self, ignoredData):
        self.data = ''
        d = self.conn.sendRequest(self, 'exec', common.NS('yaybu --remote -'), wantReply = 1)
        #d.addCallback(self._cbRequest)

    def _cbRequest(self, ignored):
        #self.write('hello conch\n')
        #self.conn.sendEOF(self)
        pass

    def dataReceived(self, data):
        self.protocol.dataReceived(data)

    def closed(self):
        self.loseConnection()
        reactor.stop()
Beispiel #3
0
    def dataReceived(self, data):
        if data.startswith("<policy-file-request/>"):

            policy = (
                '<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM '
                '"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">'
                '<cross-domain-policy><allow-access-from domain="*" '
                'to-ports="*" /></cross-domain-policy>')
            self.transport.write(policy)
            self.transport.loseConnection()
        else:
            return HTTPChannel.dataReceived(self, data)
Beispiel #4
0
 def dataReceived(self, data):
     if self.client:
         self.client.write(data)
     else:
         HTTPChannel.dataReceived(self, data)