From: SourceForge.net <no...@so...> - 2007-05-21 17:42:57
|
Bugs item #1722306, was opened at 2007-05-20 16:24 Message generated for change (Comment added) made by additv You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1722306&group_id=12867 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: Library Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: additv (additv) Assigned to: Nobody/Anonymous (nobody) Summary: OverflowError in UDP Socket Implementation Initial Comment: When using UDP sockets in Jython, calling sendto (socket.py:356) will raise "OverflowError: value too large for byte" The problematic line is 361: bytes = jarray.array(map(ord, data), 'b') This seems to be due to a difference between the results of a call to "ord" and the java defintion of a byte. Ord returns values between 0 and 255, while a java byte is a value between -128 and 127. Thus if a character has an ascii code > 127 this error occurs. ---------------------------------------------------------------------- >Comment By: additv (additv) Date: 2007-05-21 13:42 Message: Logged In: YES user_id=1797677 Originator: YES The same bug is in the new socket code, and the same fix can fix it. Here's the patch for the updated socket code: 28a29 > import java.lang.String 656c657 < bytes = jarray.array(map(ord, data), 'b') --- > bytes = java.lang.String(data).getBytes("ISO-8859-1") ---------------------------------------------------------------------- Comment By: Charles Groves (cgroves) Date: 2007-05-21 13:20 Message: Logged In: YES user_id=1174327 Originator: NO We're replacing socket with a new implementation based on java.nio in 2.2rc1. It'd be quite helpful if you tested your code with the new version. You can drop it in as explained in http://wiki.python.org/jython/NewSocketModule or just wait for rc1 to come out. It should be in a week or two. ---------------------------------------------------------------------- Comment By: additv (additv) Date: 2007-05-21 13:10 Message: Logged In: YES user_id=1797677 Originator: YES Here's the patch: 13a14 > import java.lang.String 361c362 < bytes = jarray.array(map(ord, data), 'b') --- > bytes = java.lang.String(data).getBytes("ISO-8859-1") ---------------------------------------------------------------------- Comment By: additv (additv) Date: 2007-05-21 12:59 Message: Logged In: YES user_id=1797677 Originator: YES Update: Using java.lang.String mangles characters > 127 if you run: print java.lang.String('\x80') it returns 63 running: ord('\x80') returns 128 (as it should) running print java.lang.String('\x81') it looks like using: bytes = java.lang.String(data).getBytes("ISO-8859-1") works though ---------------------------------------------------------------------- Comment By: additv (additv) Date: 2007-05-21 12:18 Message: Logged In: YES user_id=1797677 Originator: YES For some reason the recommended change gives me errors in the data. I have found that adding: import java.lang.String at the beginning of the file, and changing the line to: bytes = java.lang.String(data).getBytes() seems to fix the problem however. ---------------------------------------------------------------------- Comment By: Pekka Laukkanen (laukpe) Date: 2007-05-21 03:13 Message: Logged In: YES user_id=1379331 Originator: NO Assuming that the describtion of the problem in the summary is correct it should be pretty simple to fix this. All that is needed would be changing the mentioned line to following. bytes = jarray.array(map(lambda d : ord(d)-128, data), 'b') Could you try this with your original data? If it works this could perhaps be fixed already for 2.2. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1722306&group_id=12867 |