Skip to content

Commit 35e5859

Browse files
author
opiate
committed
On request removed tabs for spaces
Added license to top of each file
1 parent 6328c05 commit 35e5859

File tree

3 files changed

+676
-640
lines changed

3 files changed

+676
-640
lines changed

SimpleExampleServer.py

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
'''
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2013 Dave P.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
'''
12+
113
import signal, sys, ssl, logging
214
from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer, SimpleSSLWebSocketServer
315
from optparse import OptionParser
@@ -6,80 +18,80 @@
618

719
class SimpleEcho(WebSocket):
820

9-
def handleMessage(self):
10-
if self.data is None:
11-
self.data = ''
12-
13-
try:
14-
self.sendMessage(str(self.data))
15-
except Exception as n:
16-
print n
17-
18-
def handleConnected(self):
19-
print self.address, 'connected'
21+
def handleMessage(self):
22+
if self.data is None:
23+
self.data = ''
24+
25+
try:
26+
self.sendMessage(str(self.data))
27+
except Exception as n:
28+
print n
29+
30+
def handleConnected(self):
31+
print self.address, 'connected'
2032

21-
def handleClose(self):
22-
print self.address, 'closed'
33+
def handleClose(self):
34+
print self.address, 'closed'
2335

2436

2537
class SimpleChat(WebSocket):
2638

27-
def handleMessage(self):
28-
if self.data is None:
29-
self.data = ''
30-
31-
for client in self.server.connections.itervalues():
32-
if client != self:
33-
try:
34-
client.sendMessage(str(self.address[0]) + ' - ' + str(self.data))
35-
except Exception as n:
36-
print n
37-
38-
39-
def handleConnected(self):
40-
print self.address, 'connected'
41-
for client in self.server.connections.itervalues():
42-
if client != self:
43-
try:
44-
client.sendMessage(str(self.address[0]) + ' - connected')
45-
except Exception as n:
46-
print n
47-
48-
def handleClose(self):
49-
print self.address, 'closed'
50-
for client in self.server.connections.itervalues():
51-
if client != self:
52-
try:
53-
client.sendMessage(str(self.address[0]) + ' - disconnected')
54-
except Exception as n:
55-
print n
39+
def handleMessage(self):
40+
if self.data is None:
41+
self.data = ''
42+
43+
for client in self.server.connections.itervalues():
44+
if client != self:
45+
try:
46+
client.sendMessage(str(self.address[0]) + ' - ' + str(self.data))
47+
except Exception as n:
48+
print n
49+
50+
51+
def handleConnected(self):
52+
print self.address, 'connected'
53+
for client in self.server.connections.itervalues():
54+
if client != self:
55+
try:
56+
client.sendMessage(str(self.address[0]) + ' - connected')
57+
except Exception as n:
58+
print n
59+
60+
def handleClose(self):
61+
print self.address, 'closed'
62+
for client in self.server.connections.itervalues():
63+
if client != self:
64+
try:
65+
client.sendMessage(str(self.address[0]) + ' - disconnected')
66+
except Exception as n:
67+
print n
5668

5769

5870
if __name__ == "__main__":
5971

60-
parser = OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
61-
parser.add_option("--host", default='', type='string', action="store", dest="host", help="hostname (localhost)")
62-
parser.add_option("--port", default=8000, type='int', action="store", dest="port", help="port (8000)")
63-
parser.add_option("--example", default='echo', type='string', action="store", dest="example", help="echo, chat")
64-
parser.add_option("--ssl", default=0, type='int', action="store", dest="ssl", help="ssl (1: on, 0: off (default))")
65-
parser.add_option("--cert", default='./cert.pem', type='string', action="store", dest="cert", help="cert (./cert.pem)")
66-
parser.add_option("--ver", default=ssl.PROTOCOL_TLSv1, type=int, action="store", dest="ver", help="ssl version")
67-
68-
(options, args) = parser.parse_args()
72+
parser = OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
73+
parser.add_option("--host", default='', type='string', action="store", dest="host", help="hostname (localhost)")
74+
parser.add_option("--port", default=8000, type='int', action="store", dest="port", help="port (8000)")
75+
parser.add_option("--example", default='echo', type='string', action="store", dest="example", help="echo, chat")
76+
parser.add_option("--ssl", default=0, type='int', action="store", dest="ssl", help="ssl (1: on, 0: off (default))")
77+
parser.add_option("--cert", default='./cert.pem', type='string', action="store", dest="cert", help="cert (./cert.pem)")
78+
parser.add_option("--ver", default=ssl.PROTOCOL_TLSv1, type=int, action="store", dest="ver", help="ssl version")
79+
80+
(options, args) = parser.parse_args()
6981

70-
cls = SimpleEcho
71-
if options.example == 'chat':
72-
cls = SimpleChat
82+
cls = SimpleEcho
83+
if options.example == 'chat':
84+
cls = SimpleChat
7385

74-
if options.ssl == 1:
75-
server = SimpleSSLWebSocketServer(options.host, options.port, cls, options.cert, options.cert, version=options.ver)
76-
else:
77-
server = SimpleWebSocketServer(options.host, options.port, cls)
86+
if options.ssl == 1:
87+
server = SimpleSSLWebSocketServer(options.host, options.port, cls, options.cert, options.cert, version=options.ver)
88+
else:
89+
server = SimpleWebSocketServer(options.host, options.port, cls)
7890

79-
def close_sig_handler(signal, frame):
80-
server.close()
81-
sys.exit()
91+
def close_sig_handler(signal, frame):
92+
server.close()
93+
sys.exit()
8294

83-
signal.signal(signal.SIGINT, close_sig_handler)
95+
signal.signal(signal.SIGINT, close_sig_handler)
8496

85-
server.serveforever()
97+
server.serveforever()

SimpleHTTPSServer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
'''
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2013 Dave P.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
'''
12+
113
import BaseHTTPServer, SimpleHTTPServer
214
import ssl
315

0 commit comments

Comments
 (0)