Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unnecessary try/except and cleaned for some PEP8 #155

Merged
merged 1 commit into from Jan 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 17 additions & 18 deletions ws4py/server/geventserver.py
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