Commit 0cb48c88 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Changed package name to 'wspy'

parent 02204dd3
About About
===== =====
*twspy* is a standalone implementation of web sockets for Python, defined by *wspy* is a standalone implementation of web sockets for Python, defined by
[RFC 6455](http://tools.ietf.org/html/rfc6455). The incentive for creating this [RFC 6455](http://tools.ietf.org/html/rfc6455). The incentive for creating this
library is the absence of a layered implementation of web sockets outside the library is the absence of a layered implementation of web sockets outside the
scope of web servers such as Apache or Nginx. *twspy* does not require any scope of web servers such as Apache or Nginx. *wspy* does not require any
third-party programs or libraries outside Python's standard library. It third-party programs or libraries outside Python's standard library. It
provides low-level access to sockets, as well as high-level functionalities to provides low-level access to sockets, as well as high-level functionalities to
easily set up a web server. Thus, it is both suited for quick server easily set up a web server. Thus, it is both suited for quick server
...@@ -29,8 +29,8 @@ Installation ...@@ -29,8 +29,8 @@ Installation
Use Python's package manager: Use Python's package manager:
easy_install twspy easy_install wspy
pip install twspy pip install wspy
Basic usage Basic usage
...@@ -43,22 +43,22 @@ Basic usage ...@@ -43,22 +43,22 @@ Basic usage
Server example: Server example:
import twspy, socket import wspy, socket
sock = twspy.websocket() sock = wspy.websocket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 8000)) sock.bind(('', 8000))
sock.listen(5) sock.listen(5)
client = sock.accept() client = sock.accept()
client.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Client!')) client.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Client!'))
frame = client.recv() frame = client.recv()
Client example: Client example:
import twspy import wspy
sock = twspy.websocket(location='/my/path') sock = wspy.websocket(location='/my/path')
sock.connect(('', 8000)) sock.connect(('', 8000))
sock.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Server!')) sock.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Server!'))
- A `Connection` instance represents a connection between two end points, based - A `Connection` instance represents a connection between two end points, based
on a `websocket` instance. A connection handles control frames properly, and on a `websocket` instance. A connection handles control frames properly, and
...@@ -69,20 +69,20 @@ Basic usage ...@@ -69,20 +69,20 @@ Basic usage
Example of an echo server (sends back what it receives): Example of an echo server (sends back what it receives):
import twspy import wspy
class EchoConnection(twspy.Connection): class EchoConnection(wspy.Connection):
def onopen(self): def onopen(self):
print 'Connection opened at %s:%d' % self.sock.getpeername() print 'Connection opened at %s:%d' % self.sock.getpeername()
def onmessage(self, message): def onmessage(self, message):
print 'Received message "%s"' % message.payload print 'Received message "%s"' % message.payload
self.send(twspy.TextMessage(message.payload)) self.send(wspy.TextMessage(message.payload))
def onclose(self, message): def onclose(self, message):
print 'Connection closed' print 'Connection closed'
server = twspy.websocket() server = wspy.websocket()
server.bind(('', 8000)) server.bind(('', 8000))
server.listen(5) server.listen(5)
...@@ -99,10 +99,10 @@ Basic usage ...@@ -99,10 +99,10 @@ Basic usage
**Note:** For browser clients, you will probably want to use JSON encoding. **Note:** For browser clients, you will probably want to use JSON encoding.
This could, for example, be implemented as follows: This could, for example, be implemented as follows:
import twspy, json import wspy, json
def msg(**data): def msg(**data):
return twspy.TextMessage(json.dumps(data)) return wspy.TextMessage(json.dumps(data))
# create some connection `conn`... # create some connection `conn`...
...@@ -120,15 +120,15 @@ Basic usage ...@@ -120,15 +120,15 @@ Basic usage
For example, the `EchoConnection` example above can be rewritten to: For example, the `EchoConnection` example above can be rewritten to:
import twspy import wspy
class EchoServer(twspy.Server): class EchoServer(wspy.Server):
def onopen(self, client): def onopen(self, client):
print 'Client %s connected' % client print 'Client %s connected' % client
def onmessage(self, client, message): def onmessage(self, client, message):
print 'Received message "%s"' % message.payload print 'Received message "%s"' % message.payload
client.send(twspy.TextMessage(message.payload)) client.send(wspy.TextMessage(message.payload))
def onclose(self, client): def onclose(self, client):
print 'Client %s disconnected' % client print 'Client %s disconnected' % client
......
...@@ -17,20 +17,20 @@ class Connection(object): ...@@ -17,20 +17,20 @@ class Connection(object):
class should implement the on*() event handlers. class should implement the on*() event handlers.
Example of an echo server (sends back what it receives): Example of an echo server (sends back what it receives):
>>> import twspy >>> import wspy
>>> class EchoConnection(twspy.Connection): >>> class EchoConnection(wspy.Connection):
>>> def onopen(self): >>> def onopen(self):
>>> print 'Connection opened at %s:%d' % self.sock.getpeername() >>> print 'Connection opened at %s:%d' % self.sock.getpeername()
>>> def onmessage(self, message): >>> def onmessage(self, message):
>>> print 'Received message "%s"' % message.payload >>> print 'Received message "%s"' % message.payload
>>> self.send(twspy.TextMessage(message.payload)) >>> self.send(wspy.TextMessage(message.payload))
>>> def onclose(self, message): >>> def onclose(self, message):
>>> print 'Connection closed' >>> print 'Connection closed'
>>> server = twspy.websocket() >>> server = wspy.websocket()
>>> server.bind(('', 8000)) >>> server.bind(('', 8000))
>>> server.listen() >>> server.listen()
...@@ -214,7 +214,7 @@ class Connection(object): ...@@ -214,7 +214,7 @@ class Connection(object):
For example, to add an automatic JSON conversion to messages and For example, to add an automatic JSON conversion to messages and
eliminate the need to contruct TextMessage instances to all messages: eliminate the need to contruct TextMessage instances to all messages:
>>> import twspy, json >>> import wspy, json
>>> conn = Connection(...) >>> conn = Connection(...)
>>> conn.add_hook(lambda data: tswpy.TextMessage(json.dumps(data)), >>> conn.add_hook(lambda data: tswpy.TextMessage(json.dumps(data)),
>>> lambda message: json.loads(message.payload)) >>> lambda message: json.loads(message.payload))
......
...@@ -26,7 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ...@@ -26,7 +26,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code was downloaded from https://github.com/dimagi/python-digest to avoid This code was downloaded from https://github.com/dimagi/python-digest to avoid
having to download python-digest as a dependency for twspy. having to download python-digest as a dependency for wspy.
''' '''
try: try:
......
...@@ -15,15 +15,15 @@ class Server(object): ...@@ -15,15 +15,15 @@ class Server(object):
Websocket server, manages multiple client connections. Websocket server, manages multiple client connections.
Example usage: Example usage:
>>> import twspy >>> import wspy
>>> class EchoServer(twspy.Server): >>> class EchoServer(wspy.Server):
>>> def onopen(self, client): >>> def onopen(self, client):
>>> print 'Client %s connected' % client >>> print 'Client %s connected' % client
>>> def onmessage(self, client, message): >>> def onmessage(self, client, message):
>>> print 'Received message "%s"' % message.payload >>> print 'Received message "%s"' % message.payload
>>> client.send(twspy.TextMessage(message.payload)) >>> client.send(wspy.TextMessage(message.payload))
>>> def onclose(self, client): >>> def onclose(self, client):
>>> print 'Client %s disconnected' % client >>> print 'Client %s disconnected' % client
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
from distutils.core import setup from distutils.core import setup
setup(name='twspy', setup(name='wspy',
version='0.8', version='0.9',
description='A standalone implementation of websockets (RFC 6455).', description='A standalone implementation of websockets (RFC 6455).',
author='Taddeus Kroes', author='Taddeus Kroes',
author_email='taddeuskroes@gmail.com', author_email='taddeuskroes@gmail.com',
url='https://github.com/taddeus/twspy', url='https://github.com/taddeus/wspy',
package_dir={'twspy': '.'}, package_dir={'wspy': '.'},
packages=['twspy'], packages=['wspy'],
license='3-clause BSD License') license='3-clause BSD License')
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title>twspy echo test client</title> <title>wspy echo test client</title>
</head> </head>
<body> <body>
<textarea id="log" rows="20" cols="80" readonly="readonly"></textarea> <textarea id="log" rows="20" cols="80" readonly="readonly"></textarea>
......
...@@ -20,21 +20,21 @@ class websocket(object): ...@@ -20,21 +20,21 @@ class websocket(object):
illustrated by the examples below. illustrated by the examples below.
Server example: Server example:
>>> import twspy, socket >>> import wspy, socket
>>> sock = twspy.websocket() >>> sock = wspy.websocket()
>>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) >>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>>> sock.bind(('', 8000)) >>> sock.bind(('', 8000))
>>> sock.listen(5) >>> sock.listen(5)
>>> client = sock.accept() >>> client = sock.accept()
>>> client.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Client!')) >>> client.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Client!'))
>>> frame = client.recv() >>> frame = client.recv()
Client example: Client example:
>>> import twspy >>> import wspy
>>> sock = twspy.websocket(location='/my/path') >>> sock = wspy.websocket(location='/my/path')
>>> sock.connect(('', 8000)) >>> sock.connect(('', 8000))
>>> sock.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Server!')) >>> sock.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Server!'))
""" """
def __init__(self, sock=None, protocols=[], extensions=[], origin=None, def __init__(self, sock=None, protocols=[], extensions=[], origin=None,
location='/', trusted_origins=[], locations=[], auth=None, location='/', trusted_origins=[], locations=[], auth=None,
...@@ -179,7 +179,7 @@ class websocket(object): ...@@ -179,7 +179,7 @@ class websocket(object):
For example, the following code creates a `Frame` instance for data For example, the following code creates a `Frame` instance for data
being sent and removes the instance for received data. This way, data being sent and removes the instance for received data. This way, data
can be sent and received as if on a regular socket. can be sent and received as if on a regular socket.
>>> import twspy >>> import wspy
>>> sock.add_hook(lambda data: tswpy.Frame(tswpy.OPCODE_TEXT, data), >>> sock.add_hook(lambda data: tswpy.Frame(tswpy.OPCODE_TEXT, data),
>>> lambda frame: frame.payload) >>> lambda frame: frame.payload)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment