summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-12-26 20:39:00 -0500
committerChris McDonough <chrism@plope.com>2011-12-26 20:39:00 -0500
commit62e63d9ce9ac7c28f31523a12860303a43930c98 (patch)
treeb020562b797f29ac687d2eca103cfdb80477ff58
parent7a319952c1de84d55721bbcacd5bce6edc89c429 (diff)
downloadwaitress-62e63d9ce9ac7c28f31523a12860303a43930c98.tar.gz
channel.write no longer accept non-byte-sequences.
-rw-r--r--README.txt2
-rw-r--r--TODO.txt3
-rw-r--r--setup.py3
-rw-r--r--waitress/channel.py27
-rw-r--r--waitress/task.py4
-rw-r--r--waitress/tests/test_channel.py19
6 files changed, 17 insertions, 41 deletions
diff --git a/README.txt b/README.txt
index e822647..7cb20e5 100644
--- a/README.txt
+++ b/README.txt
@@ -178,5 +178,7 @@ Differences from ``zope.server``
- Raise an exception if start_response isnt called before any body write.
+- channel.write does not accept non-byte-sequences.
+
.. _PasteDeploy: http://pythonpaste.org/deploy/
diff --git a/TODO.txt b/TODO.txt
index 035d03a..d5a0cee 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -19,3 +19,6 @@
- SERVER_IDENT -> ident
- Logging.
+
+- Warn instead of relog in task.py.
+
diff --git a/setup.py b/setup.py
index 99b0644..6d55516 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,6 @@ from setuptools import setup, find_packages
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
setup(
name='waitress',
version='0.0',
@@ -32,7 +31,7 @@ setup(
read('CHANGES.txt')
),
license='ZPL 2.1',
- keywords=('waitress wsgi server http'),
+ keywords='waitress wsgi server http',
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
diff --git a/waitress/channel.py b/waitress/channel.py
index b09733b..50001ef 100644
--- a/waitress/channel.py
+++ b/waitress/channel.py
@@ -222,6 +222,13 @@ class HTTPServerChannel(asyncore.dispatcher, object):
# Ignore socket errors.
self.close()
+ def close(self):
+ # Always close in asynchronous mode. If the connection is
+ # closed in a thread, the main loop can end up with a bad file
+ # descriptor.
+ assert self.async_mode
+ self.connected = False
+ asyncore.dispatcher.close(self)
#
# SYNCHRONOUS METHODS
@@ -242,15 +249,9 @@ class HTTPServerChannel(asyncore.dispatcher, object):
def write(self, data):
wrote = 0
- if isinstance(data, bytes):
- if data:
- self.outbuf.append(data)
- wrote = len(data)
- else:
- for v in data:
- if v:
- self.outbuf.append(v)
- wrote += len(v)
+ if data:
+ self.outbuf.append(data)
+ wrote = len(data)
while len(self.outbuf) >= self.adj.send_bytes:
# Send what we can without blocking.
@@ -285,14 +286,6 @@ class HTTPServerChannel(asyncore.dispatcher, object):
self.async_mode = True
self.server.pull_trigger()
- def close(self):
- # Always close in asynchronous mode. If the connection is
- # closed in a thread, the main loop can end up with a bad file
- # descriptor.
- assert self.async_mode
- self.connected = False
- asyncore.dispatcher.close(self)
-
def queue_task(self, task):
"""Queue a channel-related task to be executed in another thread."""
start = False
diff --git a/waitress/task.py b/waitress/task.py
index 281e67b..a63615a 100644
--- a/waitress/task.py
+++ b/waitress/task.py
@@ -22,13 +22,11 @@ from waitress.utilities import (
)
from waitress.compat import (
- PY3,
tobytes,
Queue,
Empty,
thread,
reraise,
- tostr,
)
rename_headers = {
@@ -230,7 +228,7 @@ class HTTPTask(object):
if k == 'Content-Length':
self.content_length = int(v)
- # Return the write method used to write the response data.
+ # Return a method used to write the response data.
return self.write
# Call the application to handle the request and write a response
diff --git a/waitress/tests/test_channel.py b/waitress/tests/test_channel.py
index 5f99a4b..e2540d5 100644
--- a/waitress/tests/test_channel.py
+++ b/waitress/tests/test_channel.py
@@ -175,16 +175,6 @@ class TestHTTPServerChannel(unittest.TestCase):
wrote = inst.write(b'a')
self.assertEqual(wrote, 1)
- def test_write_list_with_empty(self):
- inst, sock, map = self._makeOneWithMap()
- wrote = inst.write([b''])
- self.assertEqual(wrote, 0)
-
- def test_write_list_with_full(self):
- inst, sock, map = self._makeOneWithMap()
- wrote = inst.write([b'a', b'b'])
- self.assertEqual(wrote, 2)
-
def test_write_outbuf_gt_send_bytes_has_data(self):
from waitress.adjustments import Adjustments
class DummyAdj(Adjustments):
@@ -203,15 +193,6 @@ class TestHTTPServerChannel(unittest.TestCase):
wrote = inst.write(b'')
self.assertEqual(wrote, 0)
- def test_write_channels_accept_iterables(self):
- inst, sock, map = self._makeOneWithMap()
- self.assertEqual(inst.write(b'First'), 5)
- self.assertEqual(inst.write([b"\n", b"Second", b"\n", b"Third"]), 13)
- def count():
- yield b'\n1\n2\n3\n'
- yield b'I love to count. Ha ha ha.'
- self.assertEqual(inst.write(count()), 33)
-
def test__flush_some_notconnected(self):
inst, sock, map = self._makeOneWithMap()
inst.outbuf = b'123'