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

Changed package name to 'wspy'

parent 02204dd3
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
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
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
......@@ -29,8 +29,8 @@ Installation
Use Python's package manager:
easy_install twspy
pip install twspy
easy_install wspy
pip install wspy
Basic usage
......@@ -43,22 +43,22 @@ Basic usage
Server example:
import twspy, socket
sock = twspy.websocket()
import wspy, socket
sock = wspy.websocket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 8000))
sock.listen(5)
client = sock.accept()
client.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Client!'))
client.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Client!'))
frame = client.recv()
Client example:
import twspy
sock = twspy.websocket(location='/my/path')
import wspy
sock = wspy.websocket(location='/my/path')
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
on a `websocket` instance. A connection handles control frames properly, and
......@@ -69,20 +69,20 @@ Basic usage
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):
print 'Connection opened at %s:%d' % self.sock.getpeername()
def onmessage(self, message):
print 'Received message "%s"' % message.payload
self.send(twspy.TextMessage(message.payload))
self.send(wspy.TextMessage(message.payload))
def onclose(self, message):
print 'Connection closed'
server = twspy.websocket()
server = wspy.websocket()
server.bind(('', 8000))
server.listen(5)
......@@ -99,10 +99,10 @@ Basic usage
**Note:** For browser clients, you will probably want to use JSON encoding.
This could, for example, be implemented as follows:
import twspy, json
import wspy, json
def msg(**data):
return twspy.TextMessage(json.dumps(data))
return wspy.TextMessage(json.dumps(data))
# create some connection `conn`...
......@@ -120,15 +120,15 @@ Basic usage
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):
print 'Client %s connected' % client
def onmessage(self, client, message):
print 'Received message "%s"' % message.payload
client.send(twspy.TextMessage(message.payload))
client.send(wspy.TextMessage(message.payload))
def onclose(self, client):
print 'Client %s disconnected' % client
......
......@@ -17,20 +17,20 @@ class Connection(object):
class should implement the on*() event handlers.
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):
>>> print 'Connection opened at %s:%d' % self.sock.getpeername()
>>> def onmessage(self, message):
>>> print 'Received message "%s"' % message.payload
>>> self.send(twspy.TextMessage(message.payload))
>>> self.send(wspy.TextMessage(message.payload))
>>> def onclose(self, message):
>>> print 'Connection closed'
>>> server = twspy.websocket()
>>> server = wspy.websocket()
>>> server.bind(('', 8000))
>>> server.listen()
......@@ -214,7 +214,7 @@ class Connection(object):
For example, to add an automatic JSON conversion to messages and
eliminate the need to contruct TextMessage instances to all messages:
>>> import twspy, json
>>> import wspy, json
>>> conn = Connection(...)
>>> conn.add_hook(lambda data: tswpy.TextMessage(json.dumps(data)),
>>> lambda message: json.loads(message.payload))
......
......@@ -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.
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:
......
......@@ -15,15 +15,15 @@ class Server(object):
Websocket server, manages multiple client connections.
Example usage:
>>> import twspy
>>> import wspy
>>> class EchoServer(twspy.Server):
>>> class EchoServer(wspy.Server):
>>> def onopen(self, client):
>>> print 'Client %s connected' % client
>>> def onmessage(self, client, message):
>>> print 'Received message "%s"' % message.payload
>>> client.send(twspy.TextMessage(message.payload))
>>> client.send(wspy.TextMessage(message.payload))
>>> def onclose(self, client):
>>> print 'Client %s disconnected' % client
......
......@@ -2,12 +2,12 @@
from distutils.core import setup
setup(name='twspy',
version='0.8',
setup(name='wspy',
version='0.9',
description='A standalone implementation of websockets (RFC 6455).',
author='Taddeus Kroes',
author_email='taddeuskroes@gmail.com',
url='https://github.com/taddeus/twspy',
package_dir={'twspy': '.'},
packages=['twspy'],
url='https://github.com/taddeus/wspy',
package_dir={'wspy': '.'},
packages=['wspy'],
license='3-clause BSD License')
<!doctype html>
<html>
<head>
<title>twspy echo test client</title>
<title>wspy echo test client</title>
</head>
<body>
<textarea id="log" rows="20" cols="80" readonly="readonly"></textarea>
......
......@@ -20,21 +20,21 @@ class websocket(object):
illustrated by the examples below.
Server example:
>>> import twspy, socket
>>> sock = twspy.websocket()
>>> import wspy, socket
>>> sock = wspy.websocket()
>>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>>> sock.bind(('', 8000))
>>> sock.listen(5)
>>> client = sock.accept()
>>> client.send(twspy.Frame(twspy.OPCODE_TEXT, 'Hello, Client!'))
>>> client.send(wspy.Frame(wspy.OPCODE_TEXT, 'Hello, Client!'))
>>> frame = client.recv()
Client example:
>>> import twspy
>>> sock = twspy.websocket(location='/my/path')
>>> import wspy
>>> sock = wspy.websocket(location='/my/path')
>>> 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,
location='/', trusted_origins=[], locations=[], auth=None,
......@@ -179,7 +179,7 @@ class websocket(object):
For example, the following code creates a `Frame` instance for data
being sent and removes the instance for received data. This way, data
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),
>>> 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