pyenet icon indicating copy to clipboard operation
pyenet copied to clipboard

Address() creation with non-byte host argument

Open noway opened this issue 8 years ago • 1 comments

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...

noway avatar Jan 08 '17 13:01 noway

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

noway avatar Jan 20 '17 08:01 noway