Merge remote-tracking branch 'origin/master' into 0.6.0
This commit is contained in:
commit
5f27c22681
4 changed files with 33 additions and 24 deletions
|
|
@ -122,6 +122,7 @@ Specify params, headers, cookies, proxies thanks to the `requests`_ library. ::
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
SocketIO('localhost', 8000,
|
SocketIO('localhost', 8000,
|
||||||
|
resource='my.io',
|
||||||
params={'q': 'qqq'},
|
params={'q': 'qqq'},
|
||||||
headers={'Authorization': 'Basic ' + b64encode('username:password')},
|
headers={'Authorization': 'Basic ' + b64encode('username:password')},
|
||||||
cookies={'a': 'aaa'},
|
cookies={'a': 'aaa'},
|
||||||
|
|
@ -175,8 +176,8 @@ Credits
|
||||||
.. _Lucas Klein: https://github.com/lukashed
|
.. _Lucas Klein: https://github.com/lukashed
|
||||||
.. _Rui Chicoria: https://github.com/rchicoria
|
.. _Rui Chicoria: https://github.com/rchicoria
|
||||||
.. _Travis Odom: https://github.com/burstaholic
|
.. _Travis Odom: https://github.com/burstaholic
|
||||||
|
|
||||||
.. _Eric Chen: https://github.com/taiyangc
|
.. _Eric Chen: https://github.com/taiyangc
|
||||||
.. _Denis Zinevich: https://github.com/dzinevich
|
.. _Denis Zinevich: https://github.com/dzinevich
|
||||||
.. _Thiago Hersan: https://github.com/thiagohersan
|
.. _Thiago Hersan: https://github.com/thiagohersan
|
||||||
.. _Nayef Copty: https://github.com/nayefc
|
.. _Nayef Copty: https://github.com/nayefc
|
||||||
|
.. _Patrick Huber: https://github.com/stackmagic
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -9,7 +9,7 @@ CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='socketIO-client',
|
name='socketIO-client',
|
||||||
version='0.5.3',
|
version='0.5.3.2',
|
||||||
description='A socket.io client library',
|
description='A socket.io client library',
|
||||||
long_description=README + '\n\n' + CHANGES,
|
long_description=README + '\n\n' + CHANGES,
|
||||||
license='MIT',
|
license='MIT',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@ import json
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from urlparse import urlparse
|
try:
|
||||||
|
from urllib import parse as parse_url
|
||||||
|
except ImportError:
|
||||||
|
from urlparse import urlparse as parse_url
|
||||||
|
|
||||||
from .exceptions import ConnectionError, TimeoutError, PacketError
|
from .exceptions import ConnectionError, TimeoutError, PacketError
|
||||||
from .transports import _get_response, _negotiate_transport, TRANSPORTS
|
from .transports import _get_response, _negotiate_transport, TRANSPORTS
|
||||||
|
|
@ -20,6 +23,7 @@ RETRY_INTERVAL_IN_SECONDS = 1
|
||||||
|
|
||||||
|
|
||||||
class BaseNamespace(object):
|
class BaseNamespace(object):
|
||||||
|
|
||||||
'Define client behavior'
|
'Define client behavior'
|
||||||
|
|
||||||
def __init__(self, _transport, path):
|
def __init__(self, _transport, path):
|
||||||
|
|
@ -109,6 +113,7 @@ class BaseNamespace(object):
|
||||||
|
|
||||||
|
|
||||||
class SocketIO(object):
|
class SocketIO(object):
|
||||||
|
|
||||||
"""Create a socket.io client that connects to a socket.io server
|
"""Create a socket.io client that connects to a socket.io server
|
||||||
at the specified host and port.
|
at the specified host and port.
|
||||||
|
|
||||||
|
|
@ -119,6 +124,7 @@ class SocketIO(object):
|
||||||
- Pass query params, headers, cookies, proxies as keyword arguments.
|
- Pass query params, headers, cookies, proxies as keyword arguments.
|
||||||
|
|
||||||
SocketIO('localhost', 8000,
|
SocketIO('localhost', 8000,
|
||||||
|
resource='my.io',
|
||||||
params={'q': 'qqq'},
|
params={'q': 'qqq'},
|
||||||
headers={'Authorization': 'Basic ' + b64encode('username:password')},
|
headers={'Authorization': 'Basic ' + b64encode('username:password')},
|
||||||
cookies={'a': 'aaa'},
|
cookies={'a': 'aaa'},
|
||||||
|
|
@ -127,8 +133,8 @@ class SocketIO(object):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host, port=None, Namespace=BaseNamespace,
|
self, host, port=None, Namespace=BaseNamespace,
|
||||||
wait_for_connection=True, transports=TRANSPORTS, **kw):
|
wait_for_connection=True, transports=TRANSPORTS, resource='socket.io', **kw):
|
||||||
self.is_secure, self.base_url = _parse_host(host, port)
|
self.is_secure, self.base_url = _parse_host(host, port, resource)
|
||||||
self.wait_for_connection = wait_for_connection
|
self.wait_for_connection = wait_for_connection
|
||||||
self._namespace_by_path = {}
|
self._namespace_by_path = {}
|
||||||
self.client_supported_transports = transports
|
self.client_supported_transports = transports
|
||||||
|
|
@ -167,16 +173,16 @@ class SocketIO(object):
|
||||||
|
|
||||||
- Omit seconds, i.e. call wait() without arguments, to wait forever.
|
- Omit seconds, i.e. call wait() without arguments, to wait forever.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
warning_screen = _yield_warning_screen(seconds)
|
warning_screen = _yield_warning_screen(seconds)
|
||||||
for elapsed_time in warning_screen:
|
for elapsed_time in warning_screen:
|
||||||
|
try:
|
||||||
|
if self._stop_waiting(for_callbacks):
|
||||||
|
break
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
self._process_events()
|
self._process_events()
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
pass
|
pass
|
||||||
if self._stop_waiting(for_callbacks):
|
|
||||||
break
|
|
||||||
self.heartbeat_pacemaker.send(elapsed_time)
|
self.heartbeat_pacemaker.send(elapsed_time)
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
try:
|
try:
|
||||||
|
|
@ -254,13 +260,13 @@ class SocketIO(object):
|
||||||
# Initialize heartbeat_pacemaker
|
# Initialize heartbeat_pacemaker
|
||||||
self.heartbeat_pacemaker = self._make_heartbeat_pacemaker(
|
self.heartbeat_pacemaker = self._make_heartbeat_pacemaker(
|
||||||
heartbeat_interval=socketIO_session.heartbeat_timeout / 2)
|
heartbeat_interval=socketIO_session.heartbeat_timeout / 2)
|
||||||
self.heartbeat_pacemaker.next()
|
next(self.heartbeat_pacemaker)
|
||||||
# Negotiate transport
|
# Negotiate transport
|
||||||
transport = _negotiate_transport(
|
transport = _negotiate_transport(
|
||||||
self.client_supported_transports, socketIO_session,
|
self.client_supported_transports, socketIO_session,
|
||||||
self.is_secure, self.base_url, **self.kw)
|
self.is_secure, self.base_url, **self.kw)
|
||||||
# Update namespaces
|
# Update namespaces
|
||||||
for path, namespace in self._namespace_by_path.iteritems():
|
for path, namespace in self._namespace_by_path.items():
|
||||||
namespace._transport = transport
|
namespace._transport = transport
|
||||||
transport.connect(path)
|
transport.connect(path)
|
||||||
return transport
|
return transport
|
||||||
|
|
@ -361,14 +367,14 @@ def find_callback(args, kw=None):
|
||||||
return None, args
|
return None, args
|
||||||
|
|
||||||
|
|
||||||
def _parse_host(host, port):
|
def _parse_host(host, port, resource):
|
||||||
if not host.startswith('http'):
|
if not host.startswith('http'):
|
||||||
host = 'http://' + host
|
host = 'http://' + host
|
||||||
url_pack = urlparse(host)
|
url_pack = parse_url(host)
|
||||||
is_secure = url_pack.scheme == 'https'
|
is_secure = url_pack.scheme == 'https'
|
||||||
port = port or url_pack.port or (443 if is_secure else 80)
|
port = port or url_pack.port or (443 if is_secure else 80)
|
||||||
base_url = '%s:%d%s/socket.io/%s' % (
|
base_url = '%s:%d%s/%s/%s' % (
|
||||||
url_pack.hostname, port, url_pack.path, PROTOCOL_VERSION)
|
url_pack.hostname, port, url_pack.path, resource, PROTOCOL_VERSION)
|
||||||
return is_secure, base_url
|
return is_secure, base_url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import six
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import websocket
|
import websocket
|
||||||
from itertools import izip
|
|
||||||
|
|
||||||
from .exceptions import SocketIOError, ConnectionError, TimeoutError
|
from .exceptions import SocketIOError, ConnectionError, TimeoutError
|
||||||
|
|
||||||
|
|
@ -151,6 +150,9 @@ class _WebsocketTransport(_AbstractTransport):
|
||||||
except websocket.WebSocketTimeoutException as e:
|
except websocket.WebSocketTimeoutException as e:
|
||||||
raise TimeoutError(e)
|
raise TimeoutError(e)
|
||||||
except websocket.SSLError as e:
|
except websocket.SSLError as e:
|
||||||
|
if 'timed out' in e.message:
|
||||||
|
raise TimeoutError(e)
|
||||||
|
else:
|
||||||
raise ConnectionError(e)
|
raise ConnectionError(e)
|
||||||
except websocket.WebSocketConnectionClosedException as e:
|
except websocket.WebSocketConnectionClosedException as e:
|
||||||
raise ConnectionError('connection closed (%s)' % e)
|
raise ConnectionError('connection closed (%s)' % e)
|
||||||
|
|
@ -295,7 +297,7 @@ def _negotiate_transport(
|
||||||
|
|
||||||
def _yield_text_from_framed_data(framed_data, parse=lambda x: x):
|
def _yield_text_from_framed_data(framed_data, parse=lambda x: x):
|
||||||
parts = [parse(x) for x in framed_data.split(BOUNDARY)]
|
parts = [parse(x) for x in framed_data.split(BOUNDARY)]
|
||||||
for text_length, text in izip(parts[1::2], parts[2::2]):
|
for text_length, text in zip(parts[1::2], parts[2::2]):
|
||||||
if text_length != str(len(text)):
|
if text_length != str(len(text)):
|
||||||
warning = 'invalid declared length=%s for packet_text=%s' % (
|
warning = 'invalid declared length=%s for packet_text=%s' % (
|
||||||
text_length, text)
|
text_length, text)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue