Lawouach / WebSocket-for-Python

WebSocket client and server library for Python 2 and 3 as well as PyPy (ws4py 0.5.1)
https://ws4py.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
1.12k stars 288 forks source link

fix issue #235: change from type() to isinstance()) #236

Closed noam-graetz closed 6 years ago

noam-graetz commented 6 years ago

type() check for exact match, which failed to detect the subclass used by WS4PY

Lawouach commented 6 years ago

Thanks for the report and fix proposal.

That code was never nice but CherryPy isn't exposing its internals cleanly unfortunately (hence this hack).

The failing build is for Python 3.4 which I'm not is worth supporting long run.

I wonder if that fix is backward compatible with older CherryPy however.

webknjaz commented 6 years ago

I wonder if that fix is backward compatible with older CherryPy however.

It should be. It looks, it implies equality check + takes into account subclass instances

Lawouach commented 6 years ago

Alright, tried with older CherryPy versions and for some reason it only works from 9.0.0, up to 8.9.1, it fails with the error (on Python 3.6.3):

Traceback (most recent call last):
  File "/home/sylvain/dev/.venvs/throwaway/lib/python3.6/site-packages/cherrypy/wsgiserver/__init__.py", line 1398, in communicate
    req.parse_request()
  File "/home/sylvain/dev/.venvs/throwaway/lib/python3.6/site-packages/cherrypy/wsgiserver/__init__.py", line 601, in parse_request
    success = self.read_request_line()
  File "/home/sylvain/dev/.venvs/throwaway/lib/python3.6/site-packages/cherrypy/wsgiserver/__init__.py", line 634, in read_request_line
    request_line = self.rfile.readline()
  File "/home/sylvain/dev/.venvs/throwaway/lib/python3.6/site-packages/cherrypy/wsgiserver/__init__.py", line 303, in readline
    data = self.rfile.readline(256)
  File "/usr/lib/python3.6/_pyio.py", line 511, in readline
    b = self.read(nreadahead())
  File "/usr/lib/python3.6/_pyio.py", line 495, in nreadahead
    readahead = self.peek(1)
  File "/usr/lib/python3.6/_pyio.py", line 1063, in peek
    return self._peek_unlocked(size)
  File "/usr/lib/python3.6/_pyio.py", line 1070, in _peek_unlocked
    current = self.raw.read(to_read)
AttributeError: 'NoneType' object has no attribute 'read'
Lawouach commented 6 years ago

Scratch that.

It only failed because I had cheroot still installed and that took over the import of the cherrypy classes (which broke with CherryPy 8.9.1- that was not yet relying on cheroot).

All looks good.

h3llrais3r commented 6 years ago

I've just tried the fix on my cherrypy 8.1.0 installation and this works (on Python 2.7.9)