Пример #1
0
    def __init__(self, code=None, headers=None, stream=None):
        """
        @param code: The HTTP status code for this Response
        @type code: C{int}
        
        @param headers: Headers to be sent to the client.
        @type headers: C{dict}, L{twisted.web2.http_headers.Headers}, or 
            C{None}
        
        @param stream: Content body to send to the HTTP client
        @type stream: L{twisted.web2.stream.IByteStream}
        """

        if code is not None:
            self.code = int(code)

        if headers is not None:
            if isinstance(headers, dict):
                headers = http_headers.Headers(headers)
            self.headers=headers
        else:
            self.headers = http_headers.Headers()

        if stream is not None:
            self.stream = IByteStream(stream)
Пример #2
0
    def __init__(self, method, uri, headers, stream):
        """
        @param method: The HTTP method to for this request, ex: 'GET', 'HEAD',
            'POST', etc.
        @type method: C{str}

        @param uri: The URI of the resource to request, this may be absolute or
            relative, however the interpretation of this URI is left up to the
            remote server.
        @type uri: C{str}

        @param headers: Headers to be sent to the server.  It is important to
            note that this object does not create any implicit headers.  So it
            is up to the HTTP Client to add required headers such as 'Host'.
        @type headers: C{dict}, L{twisted.web2.http_headers.Headers}, or
            C{None}

        @param stream: Content body to send to the remote HTTP server.
        @type stream: L{twisted.web2.stream.IByteStream}
        """

        self.method = method
        self.uri = uri
        if isinstance(headers, Headers):
            self.headers = headers
        else:
            self.headers = Headers(headers or {})

        if stream is not None:
            self.stream = IByteStream(stream)
        else:
            self.stream = None
Пример #3
0
class StreamAdapterInmemTest(unittest.TestCase):
    def setUp(self):
        root = inmem.FakeDirectory()
        self.ned = ned = inmem.FakeDirectory('ned', root)
        self.f = f = inmem.FakeFile('file.txt', root, 'wobble\n')
        root._children = { 'ned' : ned, 'file.txt' : f }
        self.bs = IByteStream(self.f, None)

    def test_adapt(self):
        self.assertNotEquals(self.bs, None,
                          "Could not adapt %r to IByteStream" % (self.f))

    def test_read(self):
        self.assertEquals(self.bs.read(), 'wobble\n')

    def test_readOutofData(self):
        self.bs.read()
        self.assertEquals(self.bs.read(), None)
Пример #4
0
class StreamAdapterInmemTest(unittest.TestCase):
    def setUp(self):
        root = inmem.FakeDirectory()
        self.ned = ned = inmem.FakeDirectory('ned', root)
        self.f = f = inmem.FakeFile('file.txt', root, 'wobble\n')
        root._children = {'ned': ned, 'file.txt': f}
        self.bs = IByteStream(self.f, None)

    def test_adapt(self):
        self.assertNotEquals(self.bs, None,
                             "Could not adapt %r to IByteStream" % (self.f))

    def test_read(self):
        self.assertEquals(self.bs.read(), 'wobble\n')

    def test_readOutofData(self):
        self.bs.read()
        self.assertEquals(self.bs.read(), None)
Пример #5
0
 def setUp(self):
     self.tmpdir = self.mktemp()
     os.mkdir(self.tmpdir)
     os.mkdir(os.path.join(self.tmpdir, 'ned'))
     f = open(os.path.join(self.tmpdir, 'file.txt'), 'wb')
     f.write('wobble\n')
     f.close()
     root = osfs.OSDirectory(self.tmpdir)
     self.f = root.child('file.txt')
     self.bs = IByteStream(self.f, None)
Пример #6
0
 def setUp(self):
     root = inmem.FakeDirectory()
     self.ned = ned = inmem.FakeDirectory('ned', root)
     self.f = f = inmem.FakeFile('file.txt', root, 'wobble\n')
     root._children = { 'ned' : ned, 'file.txt' : f }
     self.bs = IByteStream(self.f, None)
Пример #7
0
 def send(self, consumer):
     """
     Start producing data using L{StreamProducer}.
     """
     return StreamProducer(IByteStream(self.node)).beginProducing(consumer)
Пример #8
0
 def setUp(self):
     root = inmem.FakeDirectory()
     self.ned = ned = inmem.FakeDirectory('ned', root)
     self.f = f = inmem.FakeFile('file.txt', root, 'wobble\n')
     root._children = {'ned': ned, 'file.txt': f}
     self.bs = IByteStream(self.f, None)