When an extended ASCII character is sent and we process it through a method such as OnChanMsg(self, nick, channel, msg), a UnicodeDecodeError is thrown. Somewhere in the Swig process of converting the character from C++ to Python, a conversion from the byte string to unicode is made. The extended ascii characters not being valid unicode error out. You can repeat this easily by implementing a simple module and then sending characters such as:
¬ « € ÿ
An an example module:
defcatchfail(fn):"""Catch exceptions and get them onto the module channel."""defwrapper(*args,**kwargs):try:fn(*args,**kwargs)exceptExceptionase:s=_is_self(*args)ifs:trace=traceback.format_exc().split("\n")forlineintrace:s.PutModule(str(line))s.PutModule("Failed with %s"%(e))returnwrapperclassunicodeTest(znc.Module):@catchfaildefOnChanMsg(self,nick,channel,msg):self.PutModule(str(dir(msg)))self.PutModule(str(msg.__class__))self.PutModule(str(msg.s))returnznc.CONTINUE
The exception is:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
We should be prepared to decode the message as CP1252/ISO-8859-1.
When an extended ASCII character is sent and we process it through a method such as OnChanMsg(self, nick, channel, msg), a UnicodeDecodeError is thrown. Somewhere in the Swig process of converting the character from C++ to Python, a conversion from the byte string to unicode is made. The extended ascii characters not being valid unicode error out. You can repeat this easily by implementing a simple module and then sending characters such as:
`¬ « € ÿ`
An an example module:
``` python
def catchfail(fn):
"""Catch exceptions and get them onto the module channel."""
def wrapper(*args, **kwargs):
try:
fn(*args, **kwargs)
except Exception as e:
s = _is_self(*args)
if s:
trace=traceback.format_exc().split("\n")
for line in trace:
s.PutModule(str(line))
s.PutModule("Failed with %s" % (e))
return wrapper
class unicodeTest(znc.Module):
@catchfail
def OnChanMsg(self, nick, channel, msg):
self.PutModule(str(dir(msg)))
self.PutModule(str(msg.__class__))
self.PutModule(str(msg.s))
return znc.CONTINUE
```
The exception is:
```
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
```
We should be prepared to decode the message as CP1252/ISO-8859-1.
Further information on IRC encoding can be found here: http://hinrik.net/irc-and-character-encoding/
<!-- github-sync-id:15101910 -->
That should be handled not in modpython, but in ZNC core, see #151
Then modpython won't fail to convert proper UTF-8 string to python string
That should be handled not in modpython, but in ZNC core, see #151
Then modpython won't fail to convert proper UTF-8 string to python string
<!-- github-comment-id:18926486 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
When an extended ASCII character is sent and we process it through a method such as OnChanMsg(self, nick, channel, msg), a UnicodeDecodeError is thrown. Somewhere in the Swig process of converting the character from C++ to Python, a conversion from the byte string to unicode is made. The extended ascii characters not being valid unicode error out. You can repeat this easily by implementing a simple module and then sending characters such as:
¬ « € ÿAn an example module:
The exception is:
We should be prepared to decode the message as CP1252/ISO-8859-1.
Further information on IRC encoding can be found here: http://hinrik.net/irc-and-character-encoding/
That should be handled not in modpython, but in ZNC core, see #151
Then modpython won't fail to convert proper UTF-8 string to python string