Skip to content

Commit

Permalink
Merge pull request #155 from warvariuc/master
Browse files Browse the repository at this point in the history
Removed unnecessary try/except and cleaned for some PEP8
  • Loading branch information
Lawouach committed Jan 11, 2015
2 parents 4b44a74 + 16f7bea commit 84e8589
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions ws4py/server/geventserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""
import logging
import sys

import gevent
from gevent.pywsgi import WSGIHandler, WSGIServer as _WSGIServer
Expand All @@ -25,11 +24,13 @@
from ws4py import format_addresses
from ws4py.server.wsgiutils import WebSocketWSGIApplication


logger = logging.getLogger('ws4py')

__all__ = ['WebSocketWSGIHandler', 'WSGIServer',
'GEventWebSocketPool']


class WebSocketWSGIHandler(WSGIHandler):
"""
A WSGI handler that will perform the :rfc:`6455`
Expand All @@ -43,24 +44,21 @@ class WebSocketWSGIHandler(WSGIHandler):
def run_application(self):
upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower()
if upgrade_header:
try:
# Build and start the HTTP response
self.environ['ws4py.socket'] = self.socket or self.environ['wsgi.input'].rfile._sock
self.result = self.application(self.environ, self.start_response) or []
self.process_result()
except:
raise
else:
del self.environ['ws4py.socket']
self.socket = None
self.rfile.close()

ws = self.environ.pop('ws4py.websocket', None)
if ws:
self.server.pool.track(ws)
# Build and start the HTTP response
self.environ['ws4py.socket'] = self.socket or self.environ['wsgi.input'].rfile._sock
self.result = self.application(self.environ, self.start_response) or []
self.process_result()
del self.environ['ws4py.socket']
self.socket = None
self.rfile.close()

ws = self.environ.pop('ws4py.websocket', None)
if ws:
self.server.pool.track(ws)
else:
gevent.pywsgi.WSGIHandler.run_application(self)


class GEventWebSocketPool(Pool):
"""
Simple pool of bound websockets.
Expand All @@ -85,7 +83,8 @@ def clear(self):
pass
finally:
self.discard(greenlet)



class WSGIServer(_WSGIServer):
handler_class = WebSocketWSGIHandler

Expand All @@ -106,8 +105,8 @@ def stop(self, *args, **kwargs):
self.pool.clear()
_WSGIServer.stop(self, *args, **kwargs)


if __name__ == '__main__':
import os

from ws4py import configure_logger
configure_logger()
Expand Down

0 comments on commit 84e8589

Please sign in to comment.