[Python-modules-commits] [python-websockets] 02/12: Import python-websockets_3.1.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Sat Nov 5 22:06:18 UTC 2016
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository python-websockets.
commit 2ec030b80f40af33a9106c35ef3769b7c067d80d
Author: Piotr Ożarowski <piotr at debian.org>
Date: Sun Jun 19 19:08:13 2016 +0200
Import python-websockets_3.1.orig.tar.gz
---
MANIFEST.in | 4 ++-
PKG-INFO | 3 ++-
setup.cfg | 6 ++---
setup.py | 9 ++++---
websockets.egg-info/PKG-INFO | 3 ++-
websockets.egg-info/SOURCES.txt | 12 ++++++---
websockets.egg-info/top_level.txt | 1 +
websockets/__init__.py | 14 +++++-----
websockets/client.py | 13 ++++-----
websockets/handshake.py | 10 +++----
websockets/http.py | 4 +--
websockets/protocol.py | 30 ++++++++++++++++-----
websockets/py35/__init__.py | 2 ++
.../py35/__pycache__/__init__.cpython-33.pyc | Bin 0 -> 158 bytes
.../py35/__pycache__/__init__.cpython-34.pyc | Bin 0 -> 146 bytes
.../py35/__pycache__/__init__.cpython-35.pyc | Bin 0 -> 146 bytes
websockets/py35/__pycache__/client.cpython-35.pyc | Bin 0 -> 1123 bytes
.../py35/__pycache__/client_server.cpython-35.pyc | Bin 0 -> 1460 bytes
websockets/{py35_client.py => py35/client.py} | 0
.../client_server.py} | 6 ++---
websockets/server.py | 4 +--
websockets/test_client_server.py | 28 ++++++++++++++++---
websockets/uri.py | 4 +--
websockets/version.py | 2 +-
24 files changed, 105 insertions(+), 50 deletions(-)
diff --git a/MANIFEST.in b/MANIFEST.in
index cc0d116..09205fb 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1 +1,3 @@
-include LICENSE
\ No newline at end of file
+include LICENSE
+
+graft websockets/py35
diff --git a/PKG-INFO b/PKG-INFO
index a8b75be..7f52534 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: websockets
-Version: 3.0
+Version: 3.1
Summary: An implementation of the WebSocket Protocol (RFC 6455)
Home-page: https://github.com/aaugustin/websockets
Author: Aymeric Augustin
@@ -43,3 +43,4 @@ Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
diff --git a/setup.cfg b/setup.cfg
index 5bc163c..481906a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,15 +1,15 @@
[bdist_wheel]
-python-tag = py33.py34
+python-tag = py33.py34.py35
[flake8]
-ignore = F403
+ignore = E731,F403
[isort]
known_standard_library = asyncio
lines_after_imports = 2
[egg_info]
-tag_build =
tag_date = 0
tag_svn_revision = 0
+tag_build =
diff --git a/setup.py b/setup.py
index 4f9eaa8..06ff24b 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,10 @@ py_version = sys.version_info[:2]
if py_version < (3, 3):
raise Exception("websockets requires Python >= 3.3.")
+packages = ['websockets']
+if py_version >= (3, 5):
+ packages.append('websockets/py35')
+
setuptools.setup(
name='websockets',
version=version,
@@ -36,9 +40,7 @@ setuptools.setup(
description=description,
long_description=long_description,
download_url='https://pypi.python.org/pypi/websockets',
- packages=[
- 'websockets',
- ],
+ packages=packages,
extras_require={
':python_version=="3.3"': ['asyncio'],
},
@@ -52,6 +54,7 @@ setuptools.setup(
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
+ "Programming Language :: Python :: 3.5",
],
platforms='all',
license='BSD'
diff --git a/websockets.egg-info/PKG-INFO b/websockets.egg-info/PKG-INFO
index a8b75be..7f52534 100644
--- a/websockets.egg-info/PKG-INFO
+++ b/websockets.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: websockets
-Version: 3.0
+Version: 3.1
Summary: An implementation of the WebSocket Protocol (RFC 6455)
Home-page: https://github.com/aaugustin/websockets
Author: Aymeric Augustin
@@ -43,3 +43,4 @@ Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
diff --git a/websockets.egg-info/SOURCES.txt b/websockets.egg-info/SOURCES.txt
index 43435b4..6acd883 100644
--- a/websockets.egg-info/SOURCES.txt
+++ b/websockets.egg-info/SOURCES.txt
@@ -11,8 +11,6 @@ websockets/framing.py
websockets/handshake.py
websockets/http.py
websockets/protocol.py
-websockets/py35_client.py
-websockets/py35_test_client_server.py
websockets/server.py
websockets/test_client_server.py
websockets/test_framing.py
@@ -26,4 +24,12 @@ websockets.egg-info/PKG-INFO
websockets.egg-info/SOURCES.txt
websockets.egg-info/dependency_links.txt
websockets.egg-info/requires.txt
-websockets.egg-info/top_level.txt
\ No newline at end of file
+websockets.egg-info/top_level.txt
+websockets/py35/__init__.py
+websockets/py35/client.py
+websockets/py35/client_server.py
+websockets/py35/__pycache__/__init__.cpython-33.pyc
+websockets/py35/__pycache__/__init__.cpython-34.pyc
+websockets/py35/__pycache__/__init__.cpython-35.pyc
+websockets/py35/__pycache__/client.cpython-35.pyc
+websockets/py35/__pycache__/client_server.cpython-35.pyc
\ No newline at end of file
diff --git a/websockets.egg-info/top_level.txt b/websockets.egg-info/top_level.txt
index 14774b4..51d7526 100644
--- a/websockets.egg-info/top_level.txt
+++ b/websockets.egg-info/top_level.txt
@@ -1 +1,2 @@
websockets
+websockets/py35
diff --git a/websockets/__init__.py b/websockets/__init__.py
index 60bc9c5..b394c56 100644
--- a/websockets/__init__.py
+++ b/websockets/__init__.py
@@ -5,13 +5,13 @@ from .exceptions import *
from .protocol import *
from .server import *
from .uri import *
+from .version import version as __version__ # noqa
+
__all__ = (
- client.__all__
- + exceptions.__all__
- + protocol.__all__
- + server.__all__
- + uri.__all__
+ client.__all__ +
+ exceptions.__all__ +
+ protocol.__all__ +
+ server.__all__ +
+ uri.__all__
)
-
-from .version import version as __version__ # noqa
diff --git a/websockets/client.py b/websockets/client.py
index ea74461..12cfa24 100644
--- a/websockets/client.py
+++ b/websockets/client.py
@@ -3,8 +3,6 @@ The :mod:`websockets.client` module defines a simple WebSocket client API.
"""
-__all__ = ['connect', 'WebSocketClientProtocol']
-
import asyncio
import collections.abc
import email.message
@@ -16,6 +14,9 @@ from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol
from .uri import parse_uri
+__all__ = ['connect', 'WebSocketClientProtocol']
+
+
class WebSocketClientProtocol(WebSocketCommonProtocol):
"""
Complete WebSocket client implementation as an :class:`asyncio.Protocol`.
@@ -88,8 +89,8 @@ class WebSocketClientProtocol(WebSocketCommonProtocol):
check_response(get_header, key)
self.subprotocol = headers.get('Sec-WebSocket-Protocol', None)
- if (self.subprotocol is not None
- and self.subprotocol not in subprotocols):
+ if (self.subprotocol is not None and
+ self.subprotocol not in subprotocols):
raise InvalidHandshake(
"Unknown subprotocol: {}".format(self.subprotocol))
@@ -160,8 +161,8 @@ def connect(uri, *,
try:
- from .py35_client import Connect
-except SyntaxError: # pragma: no cover
+ from .py35.client import Connect
+except (SyntaxError, ImportError): # pragma: no cover
pass
else:
Connect.__wrapped__ = connect
diff --git a/websockets/handshake.py b/websockets/handshake.py
index e2ed644..0b99242 100644
--- a/websockets/handshake.py
+++ b/websockets/handshake.py
@@ -34,11 +34,6 @@ To open a connection, a client must:
"""
-__all__ = [
- 'build_request', 'check_request',
- 'build_response', 'check_response',
-]
-
import base64
import hashlib
import random
@@ -46,6 +41,11 @@ import random
from .exceptions import InvalidHandshake
+__all__ = [
+ 'build_request', 'check_request',
+ 'build_response', 'check_response',
+]
+
GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
diff --git a/websockets/http.py b/websockets/http.py
index 1452d0a..561e798 100644
--- a/websockets/http.py
+++ b/websockets/http.py
@@ -7,8 +7,6 @@ imported from :mod:`websockets.http`.
"""
-__all__ = ['read_request', 'read_response', 'USER_AGENT']
-
import asyncio
import email.parser
import io
@@ -17,6 +15,8 @@ import sys
from .version import version as websockets_version
+__all__ = ['read_request', 'read_response', 'USER_AGENT']
+
MAX_HEADERS = 256
MAX_LINE = 4096
diff --git a/websockets/protocol.py b/websockets/protocol.py
index 51cfd62..4b5cbcd 100644
--- a/websockets/protocol.py
+++ b/websockets/protocol.py
@@ -6,8 +6,6 @@ frames as specified in `sections 4 to 8 of RFC 6455`_.
"""
-__all__ = ['WebSocketCommonProtocol']
-
import asyncio
import asyncio.queues
import codecs
@@ -23,6 +21,8 @@ from .framing import *
from .handshake import *
+__all__ = ['WebSocketCommonProtocol']
+
logger = logging.getLogger(__name__)
@@ -62,6 +62,22 @@ class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
raise :exc:`~websockets.exceptions.ConnectionClosed` and the connection
will be closed with status code 1009.
+ The ``max_queue`` parameter sets the maximum length of the queue that holds
+ incoming messages. The default value is 32. 0 disables the limit. Messages
+ are added to an in-memory queue when they're received; then :meth:`recv()`
+ pops from that queue. In order to prevent excessive memory consumption when
+ messages are received faster than they can be processed, the queue must be
+ bounded. If the queue fills up, the protocol stops processing incoming data
+ until :meth:`recv()` is called. In this situation, various receive buffers
+ (at least in ``asyncio`` and in the OS) will fill up, then the TCP receive
+ window will shrink, slowing down transmission to avoid packet loss.
+
+ Since Python can use up to 4 bytes of memory to represent a single
+ character, each websocket connection may use up to ``4 * max_size *
+ max_queue`` bytes of memory to store incoming messages. By default,
+ this is 128MB. You may want to lower the limits, depending on your
+ application's requirements.
+
Once the handshake is complete, request and response HTTP headers are
available:
@@ -87,8 +103,8 @@ class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
def __init__(self, *,
host=None, port=None, secure=None,
- timeout=10, max_size=2 ** 20, loop=None,
- legacy_recv=False):
+ timeout=10, max_size=2 ** 20, max_queue=2 ** 5,
+ loop=None, legacy_recv=False):
self.host = host
self.port = port
self.secure = secure
@@ -128,7 +144,7 @@ class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
self.connection_closed = asyncio.Future(loop=loop)
# Queue of received messages.
- self.messages = asyncio.queues.Queue(loop=loop)
+ self.messages = asyncio.queues.Queue(max_queue, loop=loop)
# Mapping of ping IDs to waiters, in chronological order.
self.pings = collections.OrderedDict()
@@ -395,7 +411,7 @@ class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
msg = yield from self.read_message()
if msg is None:
break
- self.messages.put_nowait(msg)
+ yield from self.messages.put(msg)
except asyncio.CancelledError:
break
except WebSocketProtocolError:
@@ -631,6 +647,8 @@ class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
def connection_lost(self, exc):
# 7.1.4. The WebSocket Connection is Closed
self.state = CLOSED
+ if not self.opening_handshake.done():
+ self.opening_handshake.set_result(False)
if not self.closing_handshake.done():
self.close_code, self.close_reason = 1006, ''
self.closing_handshake.set_result(False)
diff --git a/websockets/py35/__init__.py b/websockets/py35/__init__.py
new file mode 100644
index 0000000..9612d9d
--- /dev/null
+++ b/websockets/py35/__init__.py
@@ -0,0 +1,2 @@
+# This package contains code using async / await syntax added in Python 3.5.
+# It cannot be imported on Python < 3.5 because it triggers syntax errors.
diff --git a/websockets/py35/__pycache__/__init__.cpython-33.pyc b/websockets/py35/__pycache__/__init__.cpython-33.pyc
new file mode 100644
index 0000000..74713d0
Binary files /dev/null and b/websockets/py35/__pycache__/__init__.cpython-33.pyc differ
diff --git a/websockets/py35/__pycache__/__init__.cpython-34.pyc b/websockets/py35/__pycache__/__init__.cpython-34.pyc
new file mode 100644
index 0000000..5a4332b
Binary files /dev/null and b/websockets/py35/__pycache__/__init__.cpython-34.pyc differ
diff --git a/websockets/py35/__pycache__/__init__.cpython-35.pyc b/websockets/py35/__pycache__/__init__.cpython-35.pyc
new file mode 100644
index 0000000..a68386e
Binary files /dev/null and b/websockets/py35/__pycache__/__init__.cpython-35.pyc differ
diff --git a/websockets/py35/__pycache__/client.cpython-35.pyc b/websockets/py35/__pycache__/client.cpython-35.pyc
new file mode 100644
index 0000000..adda8d6
Binary files /dev/null and b/websockets/py35/__pycache__/client.cpython-35.pyc differ
diff --git a/websockets/py35/__pycache__/client_server.cpython-35.pyc b/websockets/py35/__pycache__/client_server.cpython-35.pyc
new file mode 100644
index 0000000..27acd0d
Binary files /dev/null and b/websockets/py35/__pycache__/client_server.cpython-35.pyc differ
diff --git a/websockets/py35_client.py b/websockets/py35/client.py
similarity index 100%
rename from websockets/py35_client.py
rename to websockets/py35/client.py
diff --git a/websockets/py35_test_client_server.py b/websockets/py35/client_server.py
similarity index 90%
rename from websockets/py35_test_client_server.py
rename to websockets/py35/client_server.py
index 0b40df9..bfafa39 100644
--- a/websockets/py35_test_client_server.py
+++ b/websockets/py35/client_server.py
@@ -3,9 +3,9 @@
import asyncio
-from .client import *
-from .server import *
-from .test_client_server import handler
+from ..client import *
+from ..server import *
+from ..test_client_server import handler
class ClientServerContextManager:
diff --git a/websockets/server.py b/websockets/server.py
index 763d6ff..c81fa3f 100644
--- a/websockets/server.py
+++ b/websockets/server.py
@@ -3,8 +3,6 @@ The :mod:`websockets.server` module defines a simple WebSocket server API.
"""
-__all__ = ['serve', 'WebSocketServerProtocol']
-
import asyncio
import collections.abc
import email.message
@@ -17,6 +15,8 @@ from .http import USER_AGENT, read_request
from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol
+__all__ = ['serve', 'WebSocketServerProtocol']
+
logger = logging.getLogger(__name__)
diff --git a/websockets/test_client_server.py b/websockets/test_client_server.py
index 657723c..08d141a 100644
--- a/websockets/test_client_server.py
+++ b/websockets/test_client_server.py
@@ -59,11 +59,19 @@ class ClientServerTests(unittest.TestCase):
self.client = self.loop.run_until_complete(client)
def stop_client(self):
- self.loop.run_until_complete(self.client.worker)
+ try:
+ self.loop.run_until_complete(
+ asyncio.wait_for(self.client.worker, timeout=1))
+ except asyncio.TimeoutError: # pragma: no cover
+ self.fail("Client failed to stop")
def stop_server(self):
self.server.close()
- self.loop.run_until_complete(self.server.wait_closed())
+ try:
+ self.loop.run_until_complete(
+ asyncio.wait_for(self.server.wait_closed(), timeout=1))
+ except asyncio.TimeoutError: # pragma: no cover
+ self.fail("Server failed to stop")
def test_basic(self):
self.start_server()
@@ -322,6 +330,18 @@ class ClientServerTests(unittest.TestCase):
# Connection ends with an abnormal closure.
self.assertEqual(self.client.close_code, 1006)
+ @unittest.mock.patch.object(WebSocketClientProtocol, 'handshake')
+ def test_client_closes_connection_before_handshake(self, handshake):
+ self.start_server()
+ self.start_client()
+ # We have mocked the handshake() method to prevent the client from
+ # performing the opening handshake. Force it to close the connection.
+ self.loop.run_until_complete(self.client.close_connection(force=True))
+ self.stop_client()
+ # The server should stop properly anyway. It used to hang because the
+ # worker handling the connection was waiting for the opening handshake.
+ self.stop_server()
+
@unittest.skipUnless(os.path.exists(testcert), "test certificate is missing")
class SSLClientServerTests(ClientServerTests):
@@ -405,8 +425,8 @@ class ClientServerOriginTests(unittest.TestCase):
try:
- from .py35_test_client_server import ClientServerContextManager
-except SyntaxError: # pragma: no cover
+ from .py35.client_server import ClientServerContextManager
+except (SyntaxError, ImportError): # pragma: no cover
pass
else:
class ClientServerContextManagerTests(ClientServerContextManager,
diff --git a/websockets/uri.py b/websockets/uri.py
index 6e27a7c..48c39c1 100644
--- a/websockets/uri.py
+++ b/websockets/uri.py
@@ -6,14 +6,14 @@ according to `section 3 of RFC 6455`_.
"""
-__all__ = ['parse_uri', 'WebSocketURI']
-
import collections
import urllib.parse
from .exceptions import InvalidURI
+__all__ = ['parse_uri', 'WebSocketURI']
+
WebSocketURI = collections.namedtuple(
'WebSocketURI', ('secure', 'host', 'port', 'resource_name'))
WebSocketURI.__doc__ = """WebSocket URI.
diff --git a/websockets/version.py b/websockets/version.py
index 25c8403..8d35e0a 100644
--- a/websockets/version.py
+++ b/websockets/version.py
@@ -1 +1 @@
-version = '3.0'
+version = '3.1'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-websockets.git
More information about the Python-modules-commits
mailing list