[issue12523] 'str' object has no attribute 'more' [/usr/lib/python3.2/asynchat.py|initiate_send|245]

Giampaolo Rodola' report at bugs.python.org
Wed Apr 16 20:42:28 CEST 2014


Giampaolo Rodola' added the comment:

The part of the code where that is more likely to happen is the push() method.
One might also submit a producer (push_with_producer()) erroneously returning strings on more() though; how to properly fix this one is not clear to me because of the bad asynchat design. I'd be for simply raising an exception in push() as in:

diff --git a/Lib/asynchat.py b/Lib/asynchat.py
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -181,6 +181,8 @@
         self.close()
 
     def push (self, data):
+        if not isinstance(data, bytes):
+            raise TypeError("data must be a bytes object")
         sabs = self.ac_out_buffer_size
         if len(data) > sabs:
             for i in range(0, len(data), sabs):

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12523>
_______________________________________


More information about the Python-bugs-list mailing list