Browse Source

remove unnecessary binary argument

pull/599/head
Miguel Grinberg 4 years ago
parent
commit
9270a5bcf8
No known key found for this signature in database GPG Key ID: 36848B262DF5F06C
  1. 26
      socketio/asyncio_client.py
  2. 15
      socketio/asyncio_server.py
  3. 29
      socketio/client.py
  4. 32
      socketio/server.py

26
socketio/asyncio_client.py

@ -37,12 +37,6 @@ class AsyncClient(client.Client):
use. To disable logging set to ``False``. The default is
``False``. Note that fatal errors are logged even when
``logger`` is ``False``.
:param binary: ``True`` to support binary payloads, ``False`` to treat all
payloads as text. On Python 2, if this is set to ``True``,
``unicode`` values are treated as text, and ``str`` and
``bytes`` values are treated as binary. This option has no
effect on Python 3, where text and binary payloads are
always automatically discovered.
:param json: An alternative json module to use for encoding and decoding
packets. Custom json modules must have ``dumps`` and ``loads``
functions that are compatible with the standard library
@ -168,10 +162,6 @@ class AsyncClient(client.Client):
id = self._generate_ack_id(namespace, callback)
else:
id = None
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
# tuples are expanded to multiple arguments, everything else is sent
# as a single argument
if isinstance(data, tuple):
@ -181,8 +171,7 @@ class AsyncClient(client.Client):
else:
data = []
await self._send_packet(packet.Packet(
packet.EVENT, namespace=namespace, data=[event] + data, id=id,
binary=binary))
packet.EVENT, namespace=namespace, data=[event] + data, id=id))
async def send(self, data, namespace=None, callback=None):
"""Send a message to one or more connected clients.
@ -297,12 +286,10 @@ class AsyncClient(client.Client):
"""Send a Socket.IO packet to the server."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
await self.eio.send(ep, binary=binary)
binary = True
await self.eio.send(ep)
else:
await self.eio.send(encoded_packet, binary=False)
await self.eio.send(encoded_packet)
async def _handle_connect(self, namespace):
namespace = namespace or '/'
@ -342,13 +329,8 @@ class AsyncClient(client.Client):
data = list(r)
else:
data = [r]
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
await self._send_packet(packet.Packet(
packet.ACK, namespace=namespace, id=id, data=data,
binary=binary))
packet.ACK, namespace=namespace, id=id, data=data))
async def _handle_ack(self, namespace, id, data):
namespace = namespace or '/'

15
socketio/asyncio_server.py

@ -73,8 +73,7 @@ class AsyncServer(server.Server):
if client_manager is None:
client_manager = asyncio_manager.AsyncManager()
super().__init__(client_manager=client_manager, logger=logger,
binary=False, json=json,
async_handlers=async_handlers, **kwargs)
json=json, async_handlers=async_handlers, **kwargs)
def is_asyncio_based(self):
return True
@ -395,19 +394,16 @@ class AsyncServer(server.Server):
else:
data = []
await self._send_packet(sid, packet.Packet(
packet.EVENT, namespace=namespace, data=[event] + data, id=id,
binary=None))
packet.EVENT, namespace=namespace, data=[event] + data, id=id))
async def _send_packet(self, sid, pkt):
"""Send a Socket.IO packet to a client."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
await self.eio.send(sid, ep, binary=binary)
binary = True
await self.eio.send(sid, ep)
else:
await self.eio.send(sid, encoded_packet, binary=False)
await self.eio.send(sid, encoded_packet)
async def _handle_connect(self, sid, namespace):
"""Handle a client connection request."""
@ -485,8 +481,7 @@ class AsyncServer(server.Server):
data = [r]
await server._send_packet(sid, packet.Packet(packet.ACK,
namespace=namespace,
id=id, data=data,
binary=None))
id=id, data=data))
async def _handle_ack(self, sid, namespace, id, data):
"""Handle ACK packets from the client."""

29
socketio/client.py

@ -58,12 +58,6 @@ class Client(object):
use. To disable logging set to ``False``. The default is
``False``. Note that fatal errors are logged even when
``logger`` is ``False``.
:param binary: ``True`` to support binary payloads, ``False`` to treat all
payloads as text. On Python 2, if this is set to ``True``,
``unicode`` values are treated as text, and ``str`` and
``bytes`` values are treated as binary. This option has no
effect on Python 3, where text and binary payloads are
always automatically discovered.
:param json: An alternative json module to use for encoding and decoding
packets. Custom json modules must have ``dumps`` and ``loads``
functions that are compatible with the standard library
@ -85,8 +79,7 @@ class Client(object):
"""
def __init__(self, reconnection=True, reconnection_attempts=0,
reconnection_delay=1, reconnection_delay_max=5,
randomization_factor=0.5, logger=False, binary=False,
json=None, **kwargs):
randomization_factor=0.5, logger=False, json=None, **kwargs):
global original_signal_handler
if original_signal_handler is None and \
threading.current_thread() == threading.main_thread():
@ -97,7 +90,6 @@ class Client(object):
self.reconnection_delay = reconnection_delay
self.reconnection_delay_max = reconnection_delay_max
self.randomization_factor = randomization_factor
self.binary = binary
engineio_options = kwargs
engineio_logger = engineio_options.pop('engineio_logger', None)
@ -334,10 +326,6 @@ class Client(object):
id = self._generate_ack_id(namespace, callback)
else:
id = None
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
# tuples are expanded to multiple arguments, everything else is sent
# as a single argument
if isinstance(data, tuple):
@ -347,8 +335,7 @@ class Client(object):
else:
data = []
self._send_packet(packet.Packet(packet.EVENT, namespace=namespace,
data=[event] + data, id=id,
binary=binary))
data=[event] + data, id=id))
def send(self, data, namespace=None, callback=None):
"""Send a message to one or more connected clients.
@ -459,12 +446,10 @@ class Client(object):
"""Send a Socket.IO packet to the server."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
self.eio.send(ep, binary=binary)
binary = True
self.eio.send(ep)
else:
self.eio.send(encoded_packet, binary=False)
self.eio.send(encoded_packet)
def _generate_ack_id(self, namespace, callback):
"""Generate a unique identifier for an ACK packet."""
@ -512,12 +497,8 @@ class Client(object):
data = list(r)
else:
data = [r]
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
self._send_packet(packet.Packet(packet.ACK, namespace=namespace,
id=id, data=data, binary=binary))
id=id, data=data))
def _handle_ack(self, namespace, id, data):
namespace = namespace or '/'

32
socketio/server.py

@ -25,12 +25,6 @@ class Server(object):
use. To disable logging set to ``False``. The default is
``False``. Note that fatal errors are logged even when
``logger`` is ``False``.
:param binary: ``True`` to support binary payloads, ``False`` to treat all
payloads as text. On Python 2, if this is set to ``True``,
``unicode`` values are treated as text, and ``str`` and
``bytes`` values are treated as binary. This option has no
effect on Python 3, where text and binary payloads are
always automatically discovered.
:param json: An alternative json module to use for encoding and decoding
packets. Custom json modules must have ``dumps`` and ``loads``
functions that are compatible with the standard library
@ -97,9 +91,8 @@ class Server(object):
fatal errors are logged even when
``engineio_logger`` is ``False``.
"""
def __init__(self, client_manager=None, logger=False, binary=False,
json=None, async_handlers=True, always_connect=False,
**kwargs):
def __init__(self, client_manager=None, logger=False, json=None,
async_handlers=True, always_connect=False, **kwargs):
engineio_options = kwargs
engineio_logger = engineio_options.pop('engineio_logger', None)
if engineio_logger is not None:
@ -112,7 +105,6 @@ class Server(object):
self.eio.on('connect', self._handle_eio_connect)
self.eio.on('message', self._handle_eio_message)
self.eio.on('disconnect', self._handle_eio_disconnect)
self.binary = binary
self.environ = {}
self.handlers = {}
@ -591,10 +583,6 @@ class Server(object):
def _emit_internal(self, sid, event, data, namespace=None, id=None):
"""Send a message to a client."""
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
# tuples are expanded to multiple arguments, everything else is sent
# as a single argument
if isinstance(data, tuple):
@ -604,19 +592,16 @@ class Server(object):
else:
data = []
self._send_packet(sid, packet.Packet(packet.EVENT, namespace=namespace,
data=[event] + data, id=id,
binary=binary))
data=[event] + data, id=id))
def _send_packet(self, sid, pkt):
"""Send a Socket.IO packet to a client."""
encoded_packet = pkt.encode()
if isinstance(encoded_packet, list):
binary = False
for ep in encoded_packet:
self.eio.send(sid, ep, binary=binary)
binary = True
self.eio.send(sid, ep)
else:
self.eio.send(sid, encoded_packet, binary=False)
self.eio.send(sid, encoded_packet)
def _handle_connect(self, sid, namespace):
"""Handle a client connection request."""
@ -692,14 +677,9 @@ class Server(object):
data = list(r)
else:
data = [r]
if six.PY2 and not self.binary:
binary = False # pragma: nocover
else:
binary = None
server._send_packet(sid, packet.Packet(packet.ACK,
namespace=namespace,
id=id, data=data,
binary=binary))
id=id, data=data))
def _handle_ack(self, sid, namespace, id, data):
"""Handle ACK packets from the client."""

Loading…
Cancel
Save