Ticket #6083 defect new
TLS writeSequence() behaves differently from the vanilla TCP one
| Reported by: | hynek | Owned by: | |
|---|---|---|---|
| Priority: | lowest | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | ||
| Author: | Launchpad Bug: |
Description (last modified by exarkun) (diff)
I'm not 100% sure which part here you consider a bug, but it definitely is rather unfortunate how it's right now:
If transport.writeSequence() is called with a generator on a vanilla TCP transport, it silently does nothing. The reason is that the iterable is checked for unicode strings first in a for-loop. When it tries to reuse the iterable for actually sending data, it’s exhausted so nothing is written: http://twistedmatrix.com/trac/browser/tags/releases/twisted-12.2.0/twisted/internet/abstract.py#L340
OTOH the TLS version doesn't check for unicode but does a simple ''.join(iovec) instead, therefor it works perfectly: http://twistedmatrix.com/trac/browser/tags/releases/twisted-12.2.0/twisted/protocols/tls.py#L532
The situation means that if you write your code for TLS and start testing for vanilla, your protocols freeze and you have no idea why.
My preferred solution would be to teach writeSequence() generators (if generator: iovec = list(iovec)) but I suppose that would be too invasive. So a check for iterators together with an exception would be fine.
Also please note, that TLS doesn't check for unicode, so that's a bug on its self.
Opinions?
