Skip to content

Commit

Permalink
Make BaseMQTTProtocol compatible with python 3.6;
Browse files Browse the repository at this point in the history
  • Loading branch information
mitu committed Jul 24, 2020
1 parent a741c27 commit da0624f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion gmqtt/mqtt/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@
import logging
import time

import sys

from . import package
from .constants import MQTTv50, MQTTCommands

logger = logging.getLogger(__name__)


class BaseMQTTProtocol(asyncio.StreamReaderProtocol):
class _StreamReaderProtocolCompatibilityMixin:
def __init__(self, *args, **kwargs):
if sys.version_info < (3, 7):
self._closed = asyncio.get_event_loop().create_future()
super(_StreamReaderProtocolCompatibilityMixin, self).__init__(*args, **kwargs)

def connection_lost(self, exc):
super(_StreamReaderProtocolCompatibilityMixin, self).connection_lost(exc)

if sys.version_info[:2] >= (3, 7):
return

if not self._closed.done():
if exc is None:
self._closed.set_result(None)
else:
self._closed.set_exception(exc)


class BaseMQTTProtocol(_StreamReaderProtocolCompatibilityMixin, asyncio.StreamReaderProtocol):
def __init__(self, buffer_size=2**16, loop=None):
if not loop:
loop = asyncio.get_event_loop()
Expand Down

0 comments on commit da0624f

Please sign in to comment.