Browse Source

Fixed initialize() method in PubSubManager subclasses

Fixes #406
pull/117/head
Miguel Grinberg 8 years ago
parent
commit
5e1391d80e
  1. 13
      socketio/kombu_manager.py
  2. 13
      socketio/redis_manager.py
  3. 4
      tox.ini

13
socketio/kombu_manager.py

@ -47,19 +47,20 @@ class KombuManager(PubSubManager): # pragma: no cover
self.url = url self.url = url
self.producer = self._producer() self.producer = self._producer()
def initialize(self, server): def initialize(self):
super(KombuManager, self).initialize(server) super(KombuManager, self).initialize()
monkey_patched = True monkey_patched = True
if server.async_mode == 'eventlet': if self.server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket') monkey_patched = is_monkey_patched('socket')
elif 'gevent' in server.async_mode: elif 'gevent' in self.server.async_mode:
from gevent.monkey import is_module_patched from gevent.monkey import is_module_patched
monkey_patched = is_module_patched('socket') monkey_patched = is_module_patched('socket')
if not monkey_patched: if not monkey_patched:
raise RuntimeError('Redis requires a monkey patched socket ' raise RuntimeError(
'library to work with ' + server.async_mode) 'Redis requires a monkey patched socket library to work '
'with ' + self.server.async_mode)
def _connection(self): def _connection(self):
return kombu.Connection(self.url) return kombu.Connection(self.url)

13
socketio/redis_manager.py

@ -43,19 +43,20 @@ class RedisManager(PubSubManager): # pragma: no cover
super(RedisManager, self).__init__(channel=channel, super(RedisManager, self).__init__(channel=channel,
write_only=write_only) write_only=write_only)
def initialize(self, server): def initialize(self):
super(RedisManager, self).initialize(server) super(RedisManager, self).initialize()
monkey_patched = True monkey_patched = True
if server.async_mode == 'eventlet': if self.server.async_mode == 'eventlet':
from eventlet.patcher import is_monkey_patched from eventlet.patcher import is_monkey_patched
monkey_patched = is_monkey_patched('socket') monkey_patched = is_monkey_patched('socket')
elif 'gevent' in server.async_mode: elif 'gevent' in self.server.async_mode:
from gevent.monkey import is_module_patched from gevent.monkey import is_module_patched
monkey_patched = is_module_patched('socket') monkey_patched = is_module_patched('socket')
if not monkey_patched: if not monkey_patched:
raise RuntimeError('Redis requires a monkey patched socket ' raise RuntimeError(
'library to work with ' + server.async_mode) 'Redis requires a monkey patched socket library to work '
'with ' + self.server.async_mode)
def _publish(self, data): def _publish(self, data):
return self.redis.publish(self.channel, pickle.dumps(data)) return self.redis.publish(self.channel, pickle.dumps(data))

4
tox.ini

@ -18,7 +18,7 @@ basepython =
pypy: pypy pypy: pypy
[testenv:flake8] [testenv:flake8]
basepython=python basepython=python3.6
deps= deps=
flake8 flake8
commands= commands=
@ -35,7 +35,7 @@ commands=
make html make html
[testenv:coverage] [testenv:coverage]
basepython=python basepython=python3.6
commands= commands=
coverage run --branch --source=socketio setup.py test coverage run --branch --source=socketio setup.py test
coverage html coverage html

Loading…
Cancel
Save