diff -r d7c8914a9c4d Lib/wsgiref/validate.py --- a/Lib/wsgiref/validate.py Sat Apr 21 18:32:56 2012 +0100 +++ b/Lib/wsgiref/validate.py Mon Apr 23 13:16:51 2012 -0400 @@ -77,7 +77,7 @@ * That wsgi.input is used properly: - - .read() is called with zero or one argument + - .read() is called with one argument - That it returns a string @@ -194,23 +194,24 @@ self.input = wsgi_input def read(self, *args): - assert_(len(args) == 1) + assert_(len(args) == 1, "read() takes one argument (%d given)" % (len(args),)) v = self.input.read(*args) - assert_(type(v) is bytes) + assert_(type(v) is bytes, "read() must return bytes, got %r" % (v,)) return v def readline(self, *args): - assert_(len(args) <= 1) + assert_(len(args) <= 1, "readline() takes zero or one arguments (%d given)" % (len(args),)) v = self.input.readline(*args) - assert_(type(v) is bytes) + assert_(type(v) is bytes, "readline() must return bytes, got %r" % (v,)) return v def readlines(self, *args): - assert_(len(args) <= 1) + assert_(len(args) <= 1, "readlines() takes zero or one arguments (%d given)" % (len(args),)) lines = self.input.readlines(*args) - assert_(type(lines) is list) + assert_(type(lines) is list, "readlines() must return a list, got %r" % (lines,)) for line in lines: - assert_(type(line) is bytes) + assert_(type(line) is bytes, + "Each line returned by readlines() must be of type bytes, got %r" % (line,)) return lines def __iter__(self): @@ -229,7 +230,7 @@ self.errors = wsgi_errors def write(self, s): - assert_(type(s) is str) + check_string_type(s, "Argument to write()") self.errors.write(s) def flush(self): @@ -248,7 +249,7 @@ self.writer = wsgi_writer def __call__(self, s): - assert_(type(s) is bytes) + assert_(type(s) is bytes, "write() must be called with bytes, got %r" % (s,)) self.writer(s) class PartialIteratorWrapper: @@ -395,7 +396,8 @@ assert_(type(item) is tuple, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) - assert_(len(item) == 2) + assert_(len(item) == 2, + "Individual headers must only have two items: %r" % (item,)) name, value = item name = check_string_type(name, "Header name") value = check_string_type(value, "Header value")