Skip to content

Commit

Permalink
Merge pull request #73 from noisyboiler/remove-async-ref-as-now-a-key…
Browse files Browse the repository at this point in the history
…word

Remove async ref as now a keyword. Drop Python3.3.
  • Loading branch information
noisyboiler committed Oct 15, 2018
2 parents 7acf4dd + 83dc9ca commit 1cc127c
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 110 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sudo: false

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
.. |Python27| image:: https://img.shields.io/badge/python-2.7-blue.svg
.. _Python27: https://pypi.python.org/pypi/wampy/

.. |Python33| image:: https://img.shields.io/badge/python-3.3-blue.svg
.. _Python33: https://pypi.python.org/pypi/wampy/

.. |Python34| image:: https://img.shields.io/badge/python-3.4-blue.svg
.. _Python34: https://pypi.python.org/pypi/wampy/

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eventlet==0.20.1",
"six==1.10.0",
"simplejson==3.11.1",
"gevent>=1.1"
"gevent>1.1", # fixes infinite SSL recursion bug
],
extras_require={
'dev': [
Expand All @@ -52,6 +52,7 @@
"flake8==3.5.0",
"gevent-websocket==0.10.1",
"coverage>=3.7.1",
"Twisted==17.9.0",
],
'docs': [
"Sphinx==1.4.5",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from wampy.async import async_adapter
from wampy.backends import async_adapter


def assert_stops_raising(
Expand Down
2 changes: 1 addition & 1 deletion test/transports/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from mock import ANY
from mock import call, patch

from wampy.async import async_adapter
from wampy.backends import async_adapter
from wampy.constants import GEVENT
from wampy.errors import ConnectionError
from wampy.peers.clients import Client
Expand Down
5 changes: 0 additions & 5 deletions wampy/async/__init__.py

This file was deleted.

94 changes: 0 additions & 94 deletions wampy/async/async.py

This file was deleted.

26 changes: 26 additions & 0 deletions wampy/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from wampy.config.defaults import async_name
from wampy.constants import EVENTLET, GEVENT
from wampy.errors import WampyError


def get_async_adapter():
if async_name == GEVENT:
from . gevent_ import Gevent
_adapter = Gevent()
return _adapter

if async_name == EVENTLET:
from . eventlet_ import Eventlet
_adapter = Eventlet()
return _adapter

raise WampyError(
'only gevent and eventlet are supported, sorry. help out??'
)


async_adapter = get_async_adapter()
File renamed without changes.
43 changes: 43 additions & 0 deletions wampy/backends/eventlet_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import eventlet

from wampy.errors import WampProtocolError
from wampy.interfaces import Async


class Eventlet(Async):

def __init__(self):
self.message_queue = eventlet.Queue()

def Timeout(self, timeout):
return eventlet.Timeout(timeout)

def receive_message(self, timeout):
try:
message = self._wait_for_message(timeout)
except eventlet.Timeout:
raise WampProtocolError(
"no message returned (timed-out in {})".format(timeout)
)
return message

def spawn(self, *args, **kwargs):
gthread = eventlet.spawn(*args, **kwargs)
return gthread

def sleep(self, time):
return eventlet.sleep(time)

def _wait_for_message(self, timeout):
q = self.message_queue

with eventlet.Timeout(timeout):
while q.qsize() == 0:
eventlet.sleep()

message = q.get()
return message
35 changes: 35 additions & 0 deletions wampy/backends/gevent_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import gevent
import gevent.queue
import gevent.monkey

from wampy.errors import WampProtocolError
from wampy.interfaces import Async


class Gevent(Async):

def __init__(self):
self.message_queue = gevent.queue.Queue()

def Timeout(self, timeout):
return gevent.Timeout(timeout)

def receive_message(self, timeout):
try:
message = self.message_queue.get(timeout=timeout)
except gevent.queue.Empty:
raise WampProtocolError(
"no message returned (timed-out in {})".format(timeout)
)
return message

def spawn(self, *args, **kwargs):
gthread = gevent.spawn(*args, **kwargs)
return gthread

def sleep(self, time):
return gevent.sleep(time)
2 changes: 1 addition & 1 deletion wampy/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

from wampy.async import async_adapter
from wampy.backends import async_adapter
from wampy.errors import ConnectionError, WampProtocolError
from wampy.messages import MESSAGE_TYPE_MAP
from wampy.messages.hello import Hello
Expand Down
2 changes: 1 addition & 1 deletion wampy/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json

from wampy.async import async_adapter
from wampy.backends import async_adapter
from wampy.message_handler import MessageHandler

TIMEOUT = 5
Expand Down
4 changes: 2 additions & 2 deletions wampy/transports/websocket/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from base64 import encodestring
from socket import error as socket_error

from wampy.async import async_adapter
from wampy.async.errors import WampyTimeOut
from wampy.backends import async_adapter
from wampy.backends.errors import WampyTimeOut
from wampy.constants import WEBSOCKET_SUBPROTOCOLS, WEBSOCKET_VERSION
from wampy.errors import (
IncompleteFrameError, ConnectionError, WampProtocolError, WampyError)
Expand Down

0 comments on commit 1cc127c

Please sign in to comment.