[ python-Bugs-1358186 ] Incorrect handling of unicode "strings" in asynchat.py

SourceForge.net noreply at sourceforge.net
Wed Nov 16 16:41:39 CET 2005


Bugs item #1358186, was opened at 2005-11-16 16:28
Message generated for change (Comment added) made by holle
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1358186&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Holger Lehmann (holle)
Assigned to: Nobody/Anonymous (nobody)
Summary: Incorrect handling of unicode "strings" in asynchat.py

Initial Comment:
While debugging my Zope installation using the   
DeadLockDebugger along with the threadframe module   
under Python 2.3 and 2.4 I stumbled upon a weird   
behaviour of the method refill_buffer ind the class   
async_chat in the file asynchat.py (Around line 198).  
  
There is a special handling for strings:  
[...]  
elif isinstance(p, str):  
  self.producer_fifo.pop()  
  self.ac_out_buffer = self.ac_out_buffer + p  
  return  
data = p.more()  
[...]  
Now, if p is an instance of string, it gets a special  
handling and the function returns.  
But if p is an instance of unicode, it does not get  
the special handling, but dies in the line  
data = p.more()  
with the error, that unicode does not have a function  
named more.  
  
I was able to program a workaround by testing for str  
or unicode. Please see the attached diff-file for  
details. The code now works as expected. 
 
I guess a better way would be to import types and 
change the if into a "type(p) in types.StringTypes", 
but I did not dare to do this. 
 
I have not checked the code to see if there are more 
conditionals broken the same way. 

----------------------------------------------------------------------

>Comment By: Holger Lehmann (holle)
Date: 2005-11-16 16:41

Message:
Logged In: YES 
user_id=332779

And here is the exception (sorry for the weird format of 
the traceback, I did not do it ;-) ): 
 
ZServer uncaptured python exception, closing channel 
<ZServer.HTTPServer.zhttp_channel connected 
192.168.2.60:58493 at 
0x45f1de6c channel#: 14145 requests:> 
(exceptions.AttributeError:'unicode' object has no 
attribute 'more'  
[/usr/lib/python2.3/asyncore.py|read|69]  
[/usr/lib/python2.3/asyncore.py|handle_read_event|390]  
[/usr/lib/python2.3/asynchat.py|handle_read|136]  
[/srv/zope_infotip_rts_skel/lib/python/ZServer/medusa/http_server.py|
found_terminator|510]  
[/srv/zope_infotip_rts_render2/Products/DeadlockDebugger/dumper.py|
match|88]  
[/srv/zope_infotip_rts_skel/lib/python/ZServer/HTTPServer.py|
push|305]  
[/usr/lib/python2.3/asynchat.py|initiate_send|213]  
[/usr/lib/python2.3/asynchat.py|refill_buffer|200]) 

----------------------------------------------------------------------

Comment By: Holger Lehmann (holle)
Date: 2005-11-16 16:38

Message:
Logged In: YES 
user_id=332779

I checked the current svn repository to see if the "bug" 
still remains, yes it does: 
 
http://svn.python.org/view/python/trunk/Lib/asynchat.py?rev=38980&view=markup 

----------------------------------------------------------------------

Comment By: Holger Lehmann (holle)
Date: 2005-11-16 16:34

Message:
Logged In: YES 
user_id=332779

Just for the record: 
 
I am using Linux 2.6.11 and Python 2.4 (SuSE 9.3) 
as well as Linux 2.6.5 and Python 2.3.3 (SLES 9 Beta 4). 
 
Both Python installations contain a sitecustomize.py with 
the following content: 
import sys 
sys.setdefaultencoding('iso-8859-1') 
 
The environment contains a variable LC_CTYPE set to: 
de_DE.UTF-8 
 
The Zope is a 2.7.3 compiled on both of the above machines 
by myself. 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1358186&group_id=5470


More information about the Python-bugs-list mailing list