Ejemplo n.º 1
0
    def _finishInit(self, resp):
        def handleJSON(jsonStr):
            json = simplejson.loads(jsonStr)[0]
            if not json["authSuccessful"]:
                log.err("authentication failure!")
                self.handshakeDeferred.errback(json)
                return

            if json["version"] < self.minimumVersion:
                log.err(
                    "cometd protocol version mismatch. We wanted", self.minimumVersion, "but got", str(json["version"])
                )
                self.handshakeDeferred.errback(json)
                return

            if not "mime-message-block" in json["supportedConnectionTypes"]:
                log.err("desired transport type (mime-message-block) not supported by server")
                self.handshakeDeferred.errback(json)
                return

            self.clientId = json["clientId"]
            self.initialized = True
            self.handshakeDeferred.callback(json)
            # print json

        stream.readStream(resp.stream, handleJSON)
Ejemplo n.º 2
0
    def gotResp(resp, num):
        def print_(n):
            print "DATA %s: %r" % (num, n)

        def printdone(n):
            print "DONE %s" % num

        print "GOT RESPONSE %s: %s" % (num, resp)
        stream_mod.readStream(resp.stream, print_).addCallback(printdone)
Ejemplo n.º 3
0
    def http_POST(self, request):
        def trapNotFound(failure):
            err = failure.trap(*self.errorMap.keys())
            code, msg = self.errorMap[err]
            return http.StatusResponse(code, msg)

        def respond(result):
            return http.Response(responsecode.NO_CONTENT)

        def gotRequest(result):
            uri = self.params['uri']
            callback = self.params['callback']

            jid, nodeIdentifier = getServiceAndNode(uri)
            method = getattr(self.service, self.serviceMethod)
            d = method(jid, nodeIdentifier, callback)
            return d

        def storeParams(data):
            self.params = simplejson.loads(data)

        def trapXMPPURIParseError(failure):
            failure.trap(XMPPURIParseError)
            return http.StatusResponse(responsecode.BAD_REQUEST,
                    "Malformed XMPP URI: %s" % failure.value)

        d = readStream(request.stream, storeParams)
        d.addCallback(gotRequest)
        d.addCallback(respond)
        d.addErrback(trapNotFound)
        d.addErrback(trapXMPPURIParseError)
        return d
Ejemplo n.º 4
0
    def http_POST(self, request):
        def gotRequest(result):
            url = result['url']
            handle = result['handle']
            d = self.service.setFeed(handle, url)
            d.addCallback(lambda _: self.service.handler.checkNode(handle))
            return d

        def createResponse(result):
            response = {'uri': 'xmpp:%s?;node=%s' % (
                self.service.handler.service.full(),
                result)}
            return http.Response(responsecode.OK, stream=simplejson.dumps(response))

        def trapInvalidHandle(failure):
            failure.trap(InvalidHandleError)
            return http.StatusResponse(responsecode.BAD_REQUEST,
                                       """Invalid handle""")

        data = []
        d = readStream(request.stream, data.append)
        d.addCallback(lambda _: ''.join(data))
        d.addCallback(simplejson.loads)
        d.addCallback(gotRequest)
        d.addCallback(createResponse)
        d.addErrback(trapInvalidHandle)
        return d
Ejemplo n.º 5
0
    def http_POST(self, request):
        def gotRequest(result):
            url = result['url']
            handle = result['handle']
            d = self.service.setFeed(handle, url)
            d.addCallback(lambda _: self.service.handler.checkNode(handle))
            return d

        def createResponse(result):
            response = {
                'uri':
                'xmpp:%s?;node=%s' %
                (self.service.handler.service.full(), result)
            }
            return http.Response(responsecode.OK,
                                 stream=simplejson.dumps(response))

        def trapInvalidHandle(failure):
            failure.trap(InvalidHandleError)
            return http.StatusResponse(responsecode.BAD_REQUEST,
                                       """Invalid handle""")

        data = []
        d = readStream(request.stream, data.append)
        d.addCallback(lambda _: ''.join(data))
        d.addCallback(simplejson.loads)
        d.addCallback(gotRequest)
        d.addCallback(createResponse)
        d.addErrback(trapInvalidHandle)
        return d
Ejemplo n.º 6
0
    def renderHTTP(self, request):
        """
        Authenticate the request then return the result of calling renderHTTP
        on C{self.wrappedResource}
        """
        if request.method not in self.allowedMethods():
            response = http.Response(responsecode.NOT_ALLOWED)
            response.headers.setHeader("allow", self.allowedMethods())
            return response

        def _renderResource(resource):
            return resource.renderHTTP(request)

        def _finished_reading(ignore, result):
            data = ''.join(result)
            request.attachment = data
            d = self.authenticate(request)
            d.addCallback(_renderResource)
            return d

        if request.method in ('PUT', 'DELETE'):
            # we need to authenticate the request after all the attachment stream
            # has been read
            # QQQ DELETE doesn't have any attachments, does it? nor does GET.
            # QQQ Reading attachment when there isn't one won't hurt, will it?
            # QQQ So why don't we just do it all the time for all requests?
            data = []
            d = stream.readStream(request.stream, data.append)
            d.addCallback(_finished_reading, data)
            return d
        else:
            d = self.authenticate(request)
            d.addCallback(_renderResource)

        return d
Ejemplo n.º 7
0
    def renderHTTP(self, request):
        """
        Authenticate the request then return the result of calling renderHTTP
        on C{self.wrappedResource}
        """
        if request.method not in self.allowedMethods():
            response = http.Response(responsecode.NOT_ALLOWED)
            response.headers.setHeader("allow", self.allowedMethods())
            return response

        def _renderResource(resource):
            return resource.renderHTTP(request)

        def _finished_reading(ignore, result):
            data = "".join(result)
            request.attachment = data
            d = self.authenticate(request)
            d.addCallback(_renderResource)
            return d

        if request.method in ("PUT", "DELETE"):
            # we need to authenticate the request after all the attachment stream
            # has been read
            # QQQ DELETE doesn't have any attachments, does it? nor does GET.
            # QQQ Reading attachment when there isn't one won't hurt, will it?
            # QQQ So why don't we just do it all the time for all requests?
            data = []
            d = stream.readStream(request.stream, data.append)
            d.addCallback(_finished_reading, data)
            return d
        else:
            d = self.authenticate(request)
            d.addCallback(_renderResource)

        return d
Ejemplo n.º 8
0
 def http_POST(self, request):
     parser, unmarshaller = xmlrpclib.getparser()
     deferred = stream.readStream(request.stream, parser.feed)
     deferred.addCallback(lambda x: self._cbDispatch(request, parser, unmarshaller))
     deferred.addErrback(self._ebRender)
     deferred.addCallback(self._cbRender, request)
     return deferred
Ejemplo n.º 9
0
	def http_POST(self, request):
		# we override the upstream version because it doesn't handle
		# JSON mime types
		from twisted.web2 import http, fileupload, responsecode, stream
		
		if request.stream.length == 0:
			d = defer.succeed(None)
		else:
			parser = None
			ctype = request.headers.getHeader('content-type')

			if ctype is None:
				d = defer.succeed(None)
			else:
				def updateArgs(data):
					args = data
					request.args.update(args)
				
				def updateJson(data):
					request.args['message'] = [data]
				
				def error(f):
					raise http.HTTPError(responsecode.BAD_REQUEST)
				
				if ctype.mediaType == 'application' and ctype.mediaSubtype == 'x-www-form-urlencoded':
					d = fileupload.parse_urlencoded(request.stream)
					d.addCallbacks(updateArgs, error)
				elif ctype.mediaType in ('application','text') and ctype.mediaSubtype == 'json':
					d = stream.readStream(request.stream, updateJson)
					d.addErrback(error)
				else:
					raise http.HTTPError(responsecode.BAD_REQUEST)
		
		return d.addCallback(lambda res: self.render(request))
Ejemplo n.º 10
0
    def run(self):
        """Start the streaming.

        @rtype: L{twisted.internet.defer.Deferred}
        """
        self.doneDefer = stream.readStream(self.stream, self._gotData)
        self.doneDefer.addCallbacks(self._done, self._error)
        return self.doneDefer
Ejemplo n.º 11
0
 def test_output(self):
     p = self.runCode("import sys\nfor i in range(100): sys.stdout.write('x' * 1000)")
     l = []
     d = stream.readStream(p.outStream, l.append)
     def verify(_):
         self.assertEquals("".join(l), ("x" * 1000) * 100)
     d2 = p.run()
     return d.addCallback(verify).addCallback(lambda _: d2)
Ejemplo n.º 12
0
    def run(self):
        """Start the streaming.

        @rtype: L{twisted.internet.defer.Deferred}
        """
        self.doneDefer = stream.readStream(self.stream, self._gotData)
        self.doneDefer.addCallbacks(self._done, self._error)
        return self.doneDefer
Ejemplo n.º 13
0
 def http_POST(self, request):
     parser, unmarshaller = xmlrpclib.getparser()
     deferred = stream.readStream(request.stream, parser.feed)
     deferred.addCallback(
         lambda x: self._cbDispatch(request, parser, unmarshaller))
     deferred.addErrback(self._ebRender)
     deferred.addCallback(self._cbRender, request)
     return deferred
Ejemplo n.º 14
0
 def test_errouput(self):
     p = self.runCode("import sys\nfor i in range(100): sys.stderr.write('x' * 1000)")
     l = []
     d = stream.readStream(p.errStream, l.append)
     def verify(_):
         self.assertEquals("".join(l), ("x" * 1000) * 100)
     p.run()
     return d.addCallback(verify)
Ejemplo n.º 15
0
    def test_pullException(self):
        class Failer:
            def read(self):
                raise RuntimeError

        return stream.readStream(
            Failer(),
            lambda _: None).addErrback(lambda _: _.trap(RuntimeError))
Ejemplo n.º 16
0
    def test_pullFailure(self):
        l = []
        s = TestStreamer(['abcd', defer.fail(RuntimeError()), 'ijkl'])

        def test(result):
            result.trap(RuntimeError)
            self.assertEquals(l, ["abcd"])

        return stream.readStream(s, l.append).addErrback(test)
Ejemplo n.º 17
0
    def test_pullFailure(self):
        l = []
        s = TestStreamer(["abcd", defer.fail(RuntimeError()), "ijkl"])

        def test(result):
            result.trap(RuntimeError)
            self.assertEquals(l, ["abcd"])

        return stream.readStream(s, l.append).addErrback(test)
Ejemplo n.º 18
0
    def parse(self, stream):
        def endOfStream(result):
            if not self.done:
                raise Exception("No more stuff?")
            else:
                return self.document

        d = readStream(stream, self.elementStream.parse)
        d.addCallback(endOfStream)
        return d
Ejemplo n.º 19
0
 def test_processclosedinput(self):
     p = self.runCode("import sys; sys.stdout.write(sys.stdin.read(3));" +
                      "sys.stdin.close(); sys.stdout.write('def')",
                      "abc123")
     l = []
     d = stream.readStream(p.outStream, l.append)
     def verify(_):
         self.assertEquals("".join(l), "abcdef")
     d2 = p.run()
     return d.addCallback(verify).addCallback(lambda _: d2)
Ejemplo n.º 20
0
 def test_inputerror(self):
     p = self.runCode("import sys\nsys.stdout.write(sys.stdin.read())",
                      TestStreamer(["hello", defer.fail(ZeroDivisionError())]))
     l = []
     d = stream.readStream(p.outStream, l.append)
     d2 = p.run()
     def verify(_):
         self.assertEquals("".join(l), "hello")
         return d2
     return d.addCallback(verify).addCallback(lambda _: log.flushErrors(ZeroDivisionError))
Ejemplo n.º 21
0
def allDataFromStream(stream, filter=None):
    data = []
    def gotAllData(_):
        if not data: return None
        result = "".join([str(x) for x in data])
        if filter is None:
            return result
        else:
            return filter(result)
    return readStream(stream, data.append).addCallback(gotAllData)
Ejemplo n.º 22
0
 def test_input(self):
     p = self.runCode("import sys\nsys.stdout.write(sys.stdin.read())",
                      "hello world")
     l = []
     d = stream.readStream(p.outStream, l.append)
     d2 = p.run()
     def verify(_):
         self.assertEquals("".join(l), "hello world")
         return d2
     return d.addCallback(verify)
Ejemplo n.º 23
0
 def http_POST(self, request):
     '''
     Handle post request
     '''
     parser = SimpleParser()
     deferred = stream.readStream(request.stream, parser.feed)
     deferred.addCallback(lambda x: self._cbDispatch(request, parser))
     deferred.addErrback(self._ebRender)
     deferred.addCallback(self._cbRender, request)
     return deferred
Ejemplo n.º 24
0
    def test_errouput(self):
        p = self.runCode("import sys\nfor i in range(100): sys.stderr.write('x' * 1000)")
        l = []
        d = stream.readStream(p.errStream, l.append)

        def verify(_):
            self.assertEquals("".join(l), ("x" * 1000) * 100)

        p.run()
        return d.addCallback(verify)
Ejemplo n.º 25
0
    def test_output(self):
        p = self.runCode("import sys\nfor i in range(100): sys.stdout.write('x' * 1000)")
        l = []
        d = stream.readStream(p.outStream, l.append)

        def verify(_):
            self.assertEquals("".join(l), ("x" * 1000) * 100)

        d2 = p.run()
        return d.addCallback(verify).addCallback(lambda _: d2)
Ejemplo n.º 26
0
    def test_input(self):
        p = self.runCode("import sys\nsys.stdout.write(sys.stdin.read())", "hello world")
        l = []
        d = stream.readStream(p.outStream, l.append)
        d2 = p.run()

        def verify(_):
            self.assertEquals("".join(l), "hello world")
            return d2

        return d.addCallback(verify)
Ejemplo n.º 27
0
    def test_processclosedinput(self):
        p = self.runCode(
            "import sys; sys.stdout.write(sys.stdin.read(3));" + "sys.stdin.close(); sys.stdout.write('def')", "abc123"
        )
        l = []
        d = stream.readStream(p.outStream, l.append)

        def verify(_):
            self.assertEquals("".join(l), "abcdef")

        d2 = p.run()
        return d.addCallback(verify).addCallback(lambda _: d2)
Ejemplo n.º 28
0
 def http_POST(self, request):
   ctype = request.headers.getHeader('content-type')
   if ctype.mediaType == 'text' and ctype.mediaSubtype == 'json':
     out = []
     d = stream.readStream(request.stream, lambda x: out.append(x))
     d.addCallback(lambda _: simplejson.loads(''.join(out)))
     d.addCallback(lambda res: self.render(request, res))
   else:
     d = server.parsePOSTData(
         request, self.maxMem, self.maxFields, self.maxSize)
     d.addCallback(lambda res: self.render(request))
   return d
Ejemplo n.º 29
0
 def gotResp(self, resp, num, expect):
     self.failUnless(resp.code >= 200 and resp.code < 300, "Got a non-200 response: %r" % resp.code)
     if expect is not None:
         self.failUnless(resp.stream.length == expect, "Length was incorrect, got %r, expected %r" % (resp.stream.length, expect))
     while len(self.length) <= num:
         self.length.append(0)
     self.length[num] = 0
     def addData(data, self = self, num = num):
         self.length[num] += len(data)
     def checkLength(resp, self = self, num = num, length = resp.stream.length):
         self.failUnlessEqual(self.length[num], length)
         return resp
     df = stream_mod.readStream(resp.stream, addData)
     df.addCallback(checkLength)
     return df
Ejemplo n.º 30
0
 def test_render(self):
     """
     Test that the result from Data.render is acceptable, including the
     response code, the content-type header, and the actual response body
     itself.
     """
     response = iweb.IResponse(self.data.render(None))
     self.assertEqual(response.code, 200)
     self.assert_(response.headers.hasHeader("content-type"))
     self.assertEqual(response.headers.getHeader("content-type"),
                      http_headers.MimeType("text", "plain"))
     def checkStream(data):
         self.assertEquals(str(data), self.text)
     return stream.readStream(iweb.IResponse(self.data.render(None)).stream,
                              checkStream)
Ejemplo n.º 31
0
def readIntoFile(stream, outFile, maxlen):
    """Read the stream into a file, but not if it's longer than maxlen.
    Returns Deferred which will be triggered on finish.
    """
    curlen = [0]
    def done(_):
        return _
    def write(data):
        curlen[0] += len(data)
        if curlen[0] > maxlen:
            raise MimeFormatError("Maximum length of %d bytes exceeded." %
                                  maxlen)
        
        outFile.write(data)
    return readStream(stream, write).addBoth(done)
Ejemplo n.º 32
0
def readStreamToString(s):
    """
    Read all data from a stream into a string.

    @param s: a L{twisted.web2.stream.IByteStream} to read from.
    @return: a L{Deferred} results in a str
    """
    allData = []

    def gotData(data):
        allData.append(data)

    d = stream.readStream(s, gotData)
    d.addCallback(lambda ign: ''.join(allData))

    return d
Ejemplo n.º 33
0
def readStreamToString(s):
    """
    Read all data from a stream into a string.

    @param s: a L{twisted.web2.stream.IByteStream} to read from.
    @return: a L{Deferred} results in a str
    """
    allData = []

    def gotData(data):
        allData.append(data)

    d = stream.readStream(s, gotData)
    d.addCallback(lambda ign: ''.join(allData))

    return d
Ejemplo n.º 34
0
 def _getPeerPieces(self, response, key, site):
     """Process the retrieved response from the peer."""
     log.msg('Got a piece hash response %d from %r' % (response.code, site))
     if response.code != 200:
         # Request failed, try a different peer
         self.getPeerPieces(key, site)
     else:
         # Read the response stream to a string
         self.peers[site]['pieces'] = ''
         def _gotPeerPiece(data, self = self, site = site):
             log.msg('Peer %r got %d bytes of piece hashes' % (site, len(data)))
             self.peers[site]['pieces'] += data
         log.msg('Streaming piece hashes from peer')
         df = stream.readStream(response.stream, _gotPeerPiece)
         df.addCallbacks(self._gotPeerPieces, self._gotPeerError,
                         callbackArgs=(key, site), errbackArgs=(key, site))
Ejemplo n.º 35
0
    def test_render(self):
        """
        Test that the result from Data.render is acceptable, including the
        response code, the content-type header, and the actual response body
        itself.
        """
        response = iweb.IResponse(self.data.render(None))
        self.assertEqual(response.code, 200)
        self.assert_(response.headers.hasHeader("content-type"))
        self.assertEqual(response.headers.getHeader("content-type"),
                         http_headers.MimeType("text", "plain"))

        def checkStream(data):
            self.assertEquals(str(data), self.text)

        return stream.readStream(
            iweb.IResponse(self.data.render(None)).stream, checkStream)
Ejemplo n.º 36
0
    def test_inputerror(self):
        p = self.runCode(
            "import sys\nsys.stdout.write(sys.stdin.read())", TestStreamer(["hello", defer.fail(ZeroDivisionError())])
        )
        l = []
        d = stream.readStream(p.outStream, l.append)
        d2 = p.run()

        def verify(_):
            self.assertEquals("".join(l), "hello")
            return d2

        def cbVerified(ignored):
            excs = self.flushLoggedErrors(ZeroDivisionError)
            self.assertEqual(len(excs), 1)

        return d.addCallback(verify).addCallback(cbVerified)
Ejemplo n.º 37
0
    def test_inputerror(self):
        p = self.runCode(
            "import sys\nsys.stdout.write(sys.stdin.read())",
            TestStreamer(["hello", defer.fail(ZeroDivisionError())]))
        l = []
        d = stream.readStream(p.outStream, l.append)
        d2 = p.run()

        def verify(_):
            self.assertEquals("".join(l), "hello")
            return d2

        def cbVerified(ignored):
            excs = self.flushLoggedErrors(ZeroDivisionError)
            self.assertEqual(len(excs), 1)

        return d.addCallback(verify).addCallback(cbVerified)
Ejemplo n.º 38
0
    def http_POST(self, request):
        """
        Respond to a POST request to create a new node.
        """

        def gotStream(_):
            if request.args.get('uri'):
                jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0])
                return defer.succeed(nodeIdentifier)
            else:
                raise http.HTTPError(http.Response(responsecode.BAD_REQUEST,
                                                   "No URI given"))

        def doDelete(nodeIdentifier, data):
            if data:
                params = simplejson.loads(''.join(data))
                redirectURI = params.get('redirect_uri')
            else:
                redirectURI = None

            return self.backend.deleteNode(nodeIdentifier, self.owner,
                                           redirectURI)

        def respond(result):
            return http.Response(responsecode.NO_CONTENT)


        def trapNotFound(failure):
            failure.trap(error.NodeNotFound)
            return http.StatusResponse(responsecode.NOT_FOUND,
                                       "Node not found")

        def trapXMPPURIParseError(failure):
            failure.trap(XMPPURIParseError)
            return http.StatusResponse(responsecode.BAD_REQUEST,
                    "Malformed XMPP URI: %s" % failure.value)

        data = []
        d = readStream(request.stream, data.append)
        d.addCallback(gotStream)
        d.addCallback(doDelete, data)
        d.addCallback(respond)
        d.addErrback(trapNotFound)
        d.addErrback(trapXMPPURIParseError)
        return d
Ejemplo n.º 39
0
def readIntoFile(stream, outFile, maxlen):
    """Read the stream into a file, but not if it's longer than maxlen.
    Returns Deferred which will be triggered on finish.
    """
    curlen = [0]

    def done(_):
        return _

    def write(data):
        curlen[0] += len(data)
        if curlen[0] > maxlen:
            raise MimeFormatError("Maximum length of %d bytes exceeded." %
                                  maxlen)

        outFile.write(data)

    return readStream(stream, write).addBoth(done)
Ejemplo n.º 40
0
    def _getPeerPieces(self, response, key, site):
        """Process the retrieved response from the peer."""
        log.msg('Got a piece hash response %d from %r' % (response.code, site))
        if response.code != 200:
            # Request failed, try a different peer
            self.getPeerPieces(key, site)
        else:
            # Read the response stream to a string
            self.peers[site]['pieces'] = ''

            def _gotPeerPiece(data, self=self, site=site):
                log.msg('Peer %r got %d bytes of piece hashes' %
                        (site, len(data)))
                self.peers[site]['pieces'] += data

            log.msg('Streaming piece hashes from peer')
            df = stream.readStream(response.stream, _gotPeerPiece)
            df.addCallbacks(self._gotPeerPieces,
                            self._gotPeerError,
                            callbackArgs=(key, site),
                            errbackArgs=(key, site))
Ejemplo n.º 41
0
    def http_POST(self, request):
        # we override the upstream version because it doesn't handle
        # JSON mime types
        from twisted.web2 import http, fileupload, responsecode, stream

        if request.stream.length == 0:
            d = defer.succeed(None)
        else:
            parser = None
            ctype = request.headers.getHeader('content-type')

            if ctype is None:
                d = defer.succeed(None)
            else:

                def updateArgs(data):
                    args = data
                    request.args.update(args)

                def updateJson(data):
                    request.args['message'] = [data]

                def error(f):
                    raise http.HTTPError(responsecode.BAD_REQUEST)

                if ctype.mediaType == 'application' and ctype.mediaSubtype == 'x-www-form-urlencoded':
                    d = fileupload.parse_urlencoded(request.stream)
                    d.addCallbacks(updateArgs, error)
                elif ctype.mediaType in ('application', 'text'
                                         ) and ctype.mediaSubtype == 'json':
                    d = stream.readStream(request.stream, updateJson)
                    d.addErrback(error)
                else:
                    raise http.HTTPError(responsecode.BAD_REQUEST)

        return d.addCallback(lambda res: self.render(request))
Ejemplo n.º 42
0
 def test_pull(self):
     l = []
     s = TestStreamer(['abcd', defer.succeed('efgh'), 'ijkl'])
     return stream.readStream(s, l.append).addCallback(
         lambda _: self.assertEquals(l, ["abcd", "efgh", "ijkl"]))
Ejemplo n.º 43
0
 def test_processingException(self):
     s = TestStreamer(['abcd', defer.succeed('efgh'), 'ijkl'])
     return stream.readStream(
         s, lambda x: 1 / 0).addErrback(lambda _: _.trap(ZeroDivisionError))
Ejemplo n.º 44
0
 def test_processingException(self):
     s = TestStreamer(["abcd", defer.succeed("efgh"), "ijkl"])
     return stream.readStream(s, lambda x: 1 / 0).addErrback(lambda _: _.trap(ZeroDivisionError))
Ejemplo n.º 45
0
            def _readResponse(resp):
                # print "_readResponse"
                def _print(data):
                    print data

                stream.readStream(resp.stream, _print)
Ejemplo n.º 46
0
 def test_pull(self):
     l = []
     s = TestStreamer(["abcd", defer.succeed("efgh"), "ijkl"])
     return stream.readStream(s, l.append).addCallback(lambda _: self.assertEquals(l, ["abcd", "efgh", "ijkl"]))
Ejemplo n.º 47
0
def noDataFromStream(stream):
    def gotData(data):
        if data: raise ValueError("Stream contains unexpected data.")
    return readStream(stream, gotData)
Ejemplo n.º 48
0
    def test_pullException(self):
        class Failer:
            def read(self):
                raise RuntimeError

        return stream.readStream(Failer(), lambda _: None).addErrback(lambda _: _.trap(RuntimeError))