Skip to content

Commit 88fe146

Browse files
committed
remove unused imports and trailing spaces.
1 parent 97ab1f8 commit 88fe146

6 files changed

Lines changed: 34 additions & 51 deletions

File tree

ws4py/framing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import array
3-
import os
42
from struct import pack, unpack
53

64
from ws4py.exc import FrameTooLargeException, ProtocolException
@@ -257,7 +255,7 @@ def mask(self, data):
257255
Performs the masking or unmasking operation on data
258256
using the simple masking algorithm:
259257
260-
..
258+
..
261259
j = i MOD 4
262260
transformed-octet-i = original-octet-i XOR masking-key-octet-j
263261

ws4py/messaging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import os
33
import struct
4-
import copy
54

65
from ws4py.framing import Frame, OPCODE_CONTINUATION, OPCODE_TEXT, \
76
OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG

ws4py/server/cherrypyserver.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ def ws(self):
6161
meaning you could also dynamically change the class based
6262
on other envrionmental settings (is the user authenticated for ex).
6363
"""
64-
import sys
6564
import base64
6665
from hashlib import sha1
6766
import inspect
68-
import socket
6967
import threading
7068

7169
import cherrypy

ws4py/server/geventserver.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,45 @@
1010

1111
class UpgradableWSGIHandler(gevent.pywsgi.WSGIHandler):
1212
"""Upgradable version of gevent.pywsgi.WSGIHandler class
13-
13+
1414
This is a drop-in replacement for gevent.pywsgi.WSGIHandler that supports
1515
protocol upgrades via WSGI environment. This means you can create upgraders
1616
as WSGI apps or WSGI middleware.
17-
17+
1818
If an HTTP request comes in that includes the Upgrade header, it will add
1919
to the environment two items:
20-
20+
2121
``upgrade.protocol``
2222
The protocol to upgrade to. Checking for this lets you know the request
23-
wants to be upgraded and the WSGI server supports this interface.
24-
23+
wants to be upgraded and the WSGI server supports this interface.
24+
2525
``upgrade.socket``
2626
The raw Python socket object for the connection. From this you can do any
2727
upgrade negotiation and hand it off to the proper protocol handler.
28-
28+
2929
The upgrade must be signalled by starting a response using the 101 status
3030
code. This will inform the server to flush the headers and response status
31-
immediately, not to expect the normal WSGI app return value, and not to
32-
look for more HTTP requests on this connection.
33-
31+
immediately, not to expect the normal WSGI app return value, and not to
32+
look for more HTTP requests on this connection.
33+
3434
To use this handler with gevent.pywsgi.WSGIServer, you can pass it to the
3535
constructor:
36-
36+
3737
.. code-block:: python
3838
:linenos:
3939
40-
server = WSGIServer(('127.0.0.1', 80), app,
40+
server = WSGIServer(('127.0.0.1', 80), app,
4141
handler_class=UpgradableWSGIHandler)
42-
43-
Alternatively, you can specify it as a class variable for a WSGIServer
42+
43+
Alternatively, you can specify it as a class variable for a WSGIServer
4444
subclass:
45-
45+
4646
.. code-block:: python
4747
:linenos:
4848
4949
class UpgradableWSGIServer(gevent.pywsgi.WSGIServer):
5050
handler_class = UpgradableWSGIHandler
51-
51+
5252
"""
5353
def run_application(self):
5454
upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower()
@@ -65,12 +65,12 @@ def start_response_for_upgrade(status, headers, exc_info=None):
6565
sline = '%s %s\r\n' % (self.request_version, self.status)
6666
write(sline)
6767
self.response_length += len(sline)
68-
68+
6969
for header in headers:
7070
hline = '%s: %s\r\n' % header
7171
write(hline)
7272
self.response_length += len(hline)
73-
73+
7474
write('\r\n')
7575
self.response_length += 2
7676
else:
@@ -93,17 +93,17 @@ def start_response_for_upgrade(status, headers, exc_info=None):
9393

9494
class WebSocketServer(gevent.pywsgi.WSGIServer):
9595
handler_class = UpgradableWSGIHandler
96-
96+
9797
def __init__(self, address, *args, **kwargs):
9898
protocols = kwargs.pop('websocket_protocols', [])
9999
extensions = kwargs.pop('websocket_extensions', [])
100100
websocket = kwargs.pop('websocket_class', WebSocket)
101-
101+
102102
gevent.pywsgi.WSGIServer.__init__(self, address, *args, **kwargs)
103103
self.application = WebSocketUpgradeMiddleware(app=self.handler,
104104
protocols=protocols,
105105
extensions=extensions,
106-
websocket_class=websocket)
106+
websocket_class=websocket)
107107

108108
def handler(self, websocket):
109109
g = gevent.spawn(websocket.run)
@@ -112,7 +112,6 @@ def handler(self, websocket):
112112

113113
if __name__ == '__main__':
114114
import logging
115-
import sys
116115
logging.basicConfig(format='%(asctime)s %(message)s')
117116
logger = logging.getLogger()
118117
logger.setLevel(logging.DEBUG)
@@ -123,4 +122,3 @@ def handler(self, websocket):
123122
from ws4py.websocket import EchoWebSocket
124123
server = WebSocketServer(('127.0.0.1', 9001), websocket_class=EchoWebSocket)
125124
server.serve_forever()
126-

ws4py/server/wsgi/middleware.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# -*- coding: utf-8 -*-
2-
import copy
32
import base64
43
from hashlib import sha1
5-
import types
6-
import socket
74

85
from ws4py import WS_KEY, WS_VERSION
9-
from ws4py.exc import HandshakeError, StreamClosed
10-
from ws4py.streaming import Stream
6+
from ws4py.exc import HandshakeError
117
from ws4py.websocket import WebSocket
128

139
class WebSocketUpgradeMiddleware(object):
1410
def __init__(self, app, fallback_app=None, protocols=None, extensions=None,
15-
websocket_class=WebSocket, versions=WS_VERSION):
11+
websocket_class=WebSocket, versions=WS_VERSION):
1612
"""
1713
WSGI middleware that performs the WebSocket upgrade handshake.
1814
@@ -23,7 +19,7 @@ def ws_handler(websocket):
2319
...
2420
2521
app = WebSocketUpgradeMiddleware(ws_handler)
26-
22+
2723
2824
If the handshake succeeds, it calls ``app`` with an instance of
2925
``websocket_class`` with a copy of the environ dictionary.
@@ -49,31 +45,31 @@ def ws_handler(websocket):
4945
self.websocket_class = websocket_class
5046
self.versions = versions
5147
self.supported_versions = ', '.join([str(v) for v in versions])
52-
53-
def __call__(self, environ, start_response):
48+
49+
def __call__(self, environ, start_response):
5450
# Initial handshake validation
5551
try:
5652
if 'websocket' not in environ.get('upgrade.protocol', environ.get('HTTP_UPGRADE', '')).lower():
5753
raise HandshakeError("Upgrade protocol is not websocket")
58-
54+
5955
if environ.get('REQUEST_METHOD') != 'GET':
6056
raise HandshakeError('Method is not GET')
61-
57+
6258
key = environ.get('HTTP_SEC_WEBSOCKET_KEY')
6359
if key:
6460
ws_key = base64.b64decode(key)
6561
if len(ws_key) != 16:
6662
raise HandshakeError("WebSocket key's length is invalid")
6763
else:
6864
raise HandshakeError("Not a valid HyBi WebSocket request")
69-
65+
7066
version = environ.get('HTTP_SEC_WEBSOCKET_VERSION')
7167
version_is_valid = False
7268
if version:
7369
try: version = int(version)
7470
except: pass
7571
else: version_is_valid = version in self.versions
76-
72+
7773
if not version_is_valid:
7874
raise HandshakeError('Unsupported WebSocket version: %s' % version)
7975

@@ -85,7 +81,7 @@ def __call__(self, environ, start_response):
8581
start_response("400 Bad Handshake",
8682
[('Sec-WebSocket-Version', self.supported_versions)])
8783
return [str(e)]
88-
84+
8985
# Collect supported subprotocols
9086
protocols = self.protocols or []
9187
subprotocols = environ.get('HTTP_SEC_WEBSOCKET_PROTOCOL')
@@ -105,7 +101,7 @@ def __call__(self, environ, start_response):
105101
ext = ext.strip()
106102
if ext in exts:
107103
ws_extensions.append(ext)
108-
104+
109105
# Build and start the HTTP response
110106
headers = [
111107
('Upgrade', 'websocket'),
@@ -117,14 +113,14 @@ def __call__(self, environ, start_response):
117113
headers.append(('Sec-WebSocket-Protocol', ', '.join(ws_protocols)))
118114
if ws_extensions:
119115
headers.append(('Sec-WebSocket-Extensions', ','.join(ws_extensions)))
120-
116+
121117
start_response("101 Web Socket Hybi Handshake", headers)
122118

123119
if 'upgrade.socket' in environ:
124120
upgrade_socket = environ['upgrade.socket']
125121
else:
126122
upgrade_socket = environ['wsgi.input']._sock
127-
123+
128124
return self.app(self.websocket_class(upgrade_socket,
129125
ws_protocols,
130126
ws_extensions,

ws4py/websocket.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
import base64
3-
import copy
4-
import errno
5-
import logging
62
import socket
7-
from sys import exc_info
83
import time
9-
import traceback
104
import threading
115
import types
126

0 commit comments

Comments
 (0)