diff --git a/.gitignore b/.gitignore index f8ee2b7..5592d61 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ sdist # Vim *.sw[op] *~ +.idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 079fe51..ef59bb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.rst b/README.rst index 8467512..b1711eb 100644 --- a/README.rst +++ b/README.rst @@ -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 `_ 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 `_, which is not backwards compatible. If you want to communicate using `socket.io protocol 0.9 `_ (which is compatible with `gevent-socketio `_), please use `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 `_. Installation @@ -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 @@ -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 @@ -44,12 +40,12 @@ 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') @@ -57,7 +53,7 @@ Emit. :: 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) @@ -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') @@ -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): @@ -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): @@ -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): @@ -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) @@ -172,7 +168,7 @@ Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). : Specify params, headers, cookies, proxies thanks to the `requests `_ library. :: - from socketIO_client import SocketIO + from socketIO_client_nexus import SocketIO from base64 import b64encode SocketIO( @@ -184,7 +180,7 @@ Specify params, headers, cookies, proxies thanks to the `requests =2.7.0', 'six', diff --git a/socketIO_client/__init__.py b/socketIO_client_nexus/__init__.py similarity index 100% rename from socketIO_client/__init__.py rename to socketIO_client_nexus/__init__.py diff --git a/socketIO_client/exceptions.py b/socketIO_client_nexus/exceptions.py similarity index 100% rename from socketIO_client/exceptions.py rename to socketIO_client_nexus/exceptions.py diff --git a/socketIO_client/heartbeats.py b/socketIO_client_nexus/heartbeats.py similarity index 100% rename from socketIO_client/heartbeats.py rename to socketIO_client_nexus/heartbeats.py diff --git a/socketIO_client/logs.py b/socketIO_client_nexus/logs.py similarity index 100% rename from socketIO_client/logs.py rename to socketIO_client_nexus/logs.py diff --git a/socketIO_client/namespaces.py b/socketIO_client_nexus/namespaces.py similarity index 100% rename from socketIO_client/namespaces.py rename to socketIO_client_nexus/namespaces.py diff --git a/socketIO_client/parsers.py b/socketIO_client_nexus/parsers.py similarity index 89% rename from socketIO_client/parsers.py rename to socketIO_client_nexus/parsers.py index 7e043a4..84fda3a 100644 --- a/socketIO_client/parsers.py +++ b/socketIO_client_nexus/parsers.py @@ -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() diff --git a/socketIO_client/symmetries.py b/socketIO_client_nexus/symmetries.py similarity index 100% rename from socketIO_client/symmetries.py rename to socketIO_client_nexus/symmetries.py diff --git a/socketIO_client/tests/__init__.py b/socketIO_client_nexus/tests/__init__.py similarity index 100% rename from socketIO_client/tests/__init__.py rename to socketIO_client_nexus/tests/__init__.py diff --git a/socketIO_client/tests/index.html b/socketIO_client_nexus/tests/index.html similarity index 100% rename from socketIO_client/tests/index.html rename to socketIO_client_nexus/tests/index.html diff --git a/socketIO_client/tests/package.json b/socketIO_client_nexus/tests/package.json similarity index 100% rename from socketIO_client/tests/package.json rename to socketIO_client_nexus/tests/package.json diff --git a/socketIO_client/tests/proxy.js b/socketIO_client_nexus/tests/proxy.js similarity index 100% rename from socketIO_client/tests/proxy.js rename to socketIO_client_nexus/tests/proxy.js diff --git a/socketIO_client/tests/serve.js b/socketIO_client_nexus/tests/serve.js similarity index 100% rename from socketIO_client/tests/serve.js rename to socketIO_client_nexus/tests/serve.js diff --git a/socketIO_client/tests/ssl.crt b/socketIO_client_nexus/tests/ssl.crt similarity index 100% rename from socketIO_client/tests/ssl.crt rename to socketIO_client_nexus/tests/ssl.crt diff --git a/socketIO_client/tests/ssl.key b/socketIO_client_nexus/tests/ssl.key similarity index 100% rename from socketIO_client/tests/ssl.key rename to socketIO_client_nexus/tests/ssl.key diff --git a/socketIO_client/transports.py b/socketIO_client_nexus/transports.py similarity index 100% rename from socketIO_client/transports.py rename to socketIO_client_nexus/transports.py