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

Allow passing additional args to constructors of Namespace classes #184

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ sdist
# Vim
*.sw[op]
*~
.idea
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ install:
- pip install -U coverage requests six websocket-client
- npm install -G socket.io
before_script:
- DEBUG=* node socketIO_client/tests/serve.js &
- DEBUG=* node socketIO_client_nexus/tests/serve.js &
- sleep 1
script: nosetests
36 changes: 16 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
.. image:: https://travis-ci.org/invisibleroads/socketIO-client.svg?branch=master
:target: https://travis-ci.org/invisibleroads/socketIO-client


socketIO-client
socketIO-client-nexus
===============
Here is a `socket.io <http://socket.io>`_ client library for Python. You can use it to write test code for your socket.io server.

Please note that this version implements `socket.io protocol 1.x <https://github.com/automattic/socket.io-protocol>`_, which is not backwards compatible. If you want to communicate using `socket.io protocol 0.9 <https://github.com/learnboost/socket.io-spec>`_ (which is compatible with `gevent-socketio <https://github.com/abourget/gevent-socketio>`_), please use `socketIO-client 0.5.7.2 <https://pypi.python.org/pypi/socketIO-client/0.5.7.2>`_.
This is a forked version to implement the Socket.io 2.x changes. You can find the original `here <https://github.com/invisibleroads/socketIO-client>`_.


Installation
Expand All @@ -22,7 +18,7 @@ Install the package in an isolated environment. ::
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
pip install -U socketIO-client-nexus


Usage
Expand All @@ -34,8 +30,8 @@ Activate isolated environment. ::

Launch your socket.io server. ::

cd $(python -c "import os, socketIO_client;\
print(os.path.dirname(socketIO_client.__file__))")
cd $(python -c "import os, socketIO_client_nexus;\
print(os.path.dirname(socketIO_client_nexus.__file__))")

DEBUG=* node tests/serve.js # Start socket.io server in terminal one
DEBUG=* node tests/proxy.js # Start proxy server in terminal two
Expand All @@ -44,20 +40,20 @@ Launch your socket.io server. ::
For debugging information, run these commands first. ::

import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.getLogger('socketIO-client-nexus').setLevel(logging.DEBUG)
logging.basicConfig()

Emit. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
socketIO.emit('aaa')
socketIO.wait(seconds=1)

Emit with callback. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

def on_bbb_response(*args):
print('on_bbb_response', args)
Expand All @@ -68,7 +64,7 @@ Emit with callback. ::

Define events. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

def on_connect():
print('connect')
Expand Down Expand Up @@ -106,7 +102,7 @@ Define events. ::

Define events in a namespace. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

Expand All @@ -120,7 +116,7 @@ Define events in a namespace. ::

Define standard events. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

Expand All @@ -138,7 +134,7 @@ Define standard events. ::

Define different namespaces on a single socket. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class ChatNamespace(BaseNamespace):

Expand All @@ -160,7 +156,7 @@ Define different namespaces on a single socket. ::

Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

# Skip server certificate verification
SocketIO('https://localhost', verify=False)
Expand All @@ -172,7 +168,7 @@ Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). :

Specify params, headers, cookies, proxies thanks to the `requests <http://python-requests.org>`_ library. ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO
from base64 import b64encode

SocketIO(
Expand All @@ -184,15 +180,15 @@ Specify params, headers, cookies, proxies thanks to the `requests <http://python

Wait forever. ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

socketIO = SocketIO('localhost', 8000)
socketIO.wait()

Don't wait forever. ::

from requests.exceptions import ConnectionError
from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

try:
socket = SocketIO('localhost', 8000, wait_for_connection=False)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
'CHANGES.rst',
])
setup(
name='socketIO-client',
version='0.7.2',
name='socketIO-client-nexus',
version='0.7.6',
description='A socket.io client library',
long_description=DESCRIPTION,
license='MIT',
Expand All @@ -24,7 +24,7 @@
keywords='socket.io node.js',
author='Roy Hyunjin Han',
author_email='[email protected]',
url='https://github.com/invisibleroads/socketIO-client',
url='https://github.com/nexus-devs/socketIO-client',
install_requires=[
'requests>=2.7.0',
'six',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 6 additions & 11 deletions socketIO_client/parsers.py → socketIO_client_nexus/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,15 @@ def _make_packet_prefix(packet):


def _read_packet_length(content, content_index):
while get_byte(content, content_index) != 0:
start = content_index
while content.decode()[content_index] != ':':
content_index += 1
content_index += 1
packet_length_string = ''
byte = get_byte(content, content_index)
while byte != 255:
packet_length_string += str(byte)
content_index += 1
byte = get_byte(content, content_index)
packet_length_string = content.decode()[start:content_index]
return content_index, int(packet_length_string)


def _read_packet_text(content, content_index, packet_length):
while get_byte(content, content_index) == 255:
while content.decode()[content_index] == ':':
content_index += 1
packet_text = content[content_index:content_index + packet_length]
return content_index + packet_length, packet_text
packet_text = content.decode()[content_index:content_index + packet_length]
return content_index + packet_length, packet_text.encode()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.