pyenet
pyenet copied to clipboard
Address() creation with non-byte host argument
When Address is being created with an argument which is not an instance of bytes
, pyenet will through and error.
Because of the following: https://github.com/aresch/pyenet/blob/master/enet.pyx#L226
bytes() only takes in 1 argument.
Also, there's no way to specify host as None
with this bytes() conversion...
Note: this happens only in Python 2, because in python 2 bytes()
function is just an alias for str
type cast.
I suggest doing something like the following:
if not isinstance(host, bytes):
host = host.encode('cp437')
For python2 it would give you:
- on str: will skip without any exceptions
- on unicode: will encode
For python3 it would give you
- on bytes: will skip
- on str: will encode
Note that cp437 is extended ASCII - the charset which covers every 256 value out of a byte. While ASCII might be only covering 127 values and give errors on upper ranges AFAIK