コード例 #1
0
ファイル: bigdemo.py プロジェクト: bizhan/notes
 def handleConnection(self, transport):
     transport = LineBuffer(transport)
     try:
         for line in transport:
             transport.writeLine(line)
     except twisted.internet.error.ConnectionClosed:
         return
コード例 #2
0
 def test_truncateDelimiter(self):
     """
     C{readLine} returns a full line without delimiter.
     """
     io = StringIO("Hello world\r\n")
     wrapper = LineBuffer(io)
     self.assertEquals(wrapper.readLine(), "Hello world")
コード例 #3
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_truncateDelimiter(self):
     """
     C{readLine} returns a full line without delimiter.
     """
     io = StringIO("Hello world\r\n")
     wrapper = LineBuffer(io)
     self.assertEquals(wrapper.readLine(), "Hello world")
コード例 #4
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_buffer(self):
     """
     If C{readLine} cannot immediately get a full line from
     C{transport.read}, it will buffer that data until the next read.
     """
     transport = BoringTransport(["a", "b\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "ab")
コード例 #5
0
 def test_buffer(self):
     """
     If C{readLine} cannot immediately get a full line from
     C{transport.read}, it will buffer that data until the next read.
     """
     transport = BoringTransport(["a", "b\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "ab")
コード例 #6
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_multipleLines(self):
     """
     Each call to C{readLine} returns the next line received.
     """
     transport = BoringTransport(["a\r\n", "b\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "a")
     self.assertEquals(wrapper.readLine(), "b")
コード例 #7
0
 def test_multipleLines(self):
     """
     Each call to C{readLine} returns the next line received.
     """
     transport = BoringTransport(["a\r\n", "b\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "a")
     self.assertEquals(wrapper.readLine(), "b")
コード例 #8
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_writeLineWithDelimiter(self):
     """
     C{writeLine} honors the specified delimiter.
     """
     io = StringIO()
     wrapper = LineBuffer(io, delimiter="Woot,")
     wrapper.writeLine("foo")
     wrapper.writeLine("bar")
     self.assertEquals(io.getvalue(), "fooWoot,barWoot,")
コード例 #9
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_delimiter(self):
     """
     The delimiter can be whatever you want it to be.
     """
     transport = BoringTransport(["helloxtharx", "yesx"])
     wrapper = LineBuffer(transport, delimiter="x")
     self.assertEquals(wrapper.readLine(), "hello")
     self.assertEquals(wrapper.readLine(), "thar")
     self.assertEquals(wrapper.readLine(), "yes")
コード例 #10
0
 def test_writeLineWithDelimiter(self):
     """
     C{writeLine} honors the specified delimiter.
     """
     io = StringIO()
     wrapper = LineBuffer(io, delimiter="Woot,")
     wrapper.writeLine("foo")
     wrapper.writeLine("bar")
     self.assertEquals(io.getvalue(), "fooWoot,barWoot,")
コード例 #11
0
 def test_delimiter(self):
     """
     The delimiter can be whatever you want it to be.
     """
     transport = BoringTransport(["helloxtharx", "yesx"])
     wrapper = LineBuffer(transport, delimiter="x")
     self.assertEquals(wrapper.readLine(), "hello")
     self.assertEquals(wrapper.readLine(), "thar")
     self.assertEquals(wrapper.readLine(), "yes")
コード例 #12
0
 def test_writeLine(self):
     """
     C{writeLine} is a convenience method for writing some data followed by
     a delimiter.
     """
     io = StringIO()
     wrapper = LineBuffer(io)
     wrapper.writeLine("foo")
     wrapper.writeLine("bar")
     self.assertEquals(io.getvalue(), "foo\r\nbar\r\n")
コード例 #13
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_writeLine(self):
     """
     C{writeLine} is a convenience method for writing some data followed by
     a delimiter.
     """
     io = StringIO()
     wrapper = LineBuffer(io)
     wrapper.writeLine("foo")
     wrapper.writeLine("bar")
     self.assertEquals(io.getvalue(), "foo\r\nbar\r\n")
コード例 #14
0
ファイル: test_protocol.py プロジェクト: radix/corotwine
 def test_multipleLinesInOnePacket(self):
     """
     C{readLine} handles multiple lines in one C{transport.read} result by
     only returning the first and saving the rest for the next call.
     """
     transport = BoringTransport(["foo\r\nbar\r\nbaz\r\n", "quux\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "foo")
     self.assertEquals(wrapper.readLine(), "bar")
     self.assertEquals(wrapper.readLine(), "baz")
     self.assertEquals(wrapper.readLine(), "quux")
コード例 #15
0
 def test_multipleLinesInOnePacket(self):
     """
     C{readLine} handles multiple lines in one C{transport.read} result by
     only returning the first and saving the rest for the next call.
     """
     transport = BoringTransport(["foo\r\nbar\r\nbaz\r\n", "quux\r\n"])
     wrapper = LineBuffer(transport)
     self.assertEquals(wrapper.readLine(), "foo")
     self.assertEquals(wrapper.readLine(), "bar")
     self.assertEquals(wrapper.readLine(), "baz")
     self.assertEquals(wrapper.readLine(), "quux")
コード例 #16
0
 def test_iterate(self):
     """
     The L{LineBuffer} is iterable, and acts as an infinite series of calls
     to C{readLine}.
     """
     transport = BoringTransport(["a\r\nb\r\nc\r\nd"])
     wrapper = LineBuffer(transport)
     iterable = iter(wrapper)
     self.assertEquals(iterable.next(), "a")
     self.assertEquals(iterable.next(), "b")
     self.assertEquals(iterable.next(), "c")
コード例 #17
0
 def handleConnection(self, transport):
     transport = LineBuffer(transport)
     self.clients.append(transport)
     try:
         try:
             for line in transport:
                 for client in self.clients:
                     if client is not transport:
                         client.writeLine(line)
         finally:
             self.clients.remove(transport)
     except ConnectionClosed:
         return