Python 3.5 compatibility

Close #1 and #3
This commit is contained in:
Pedro Ferreira 2017-08-01 22:34:06 +02:00
parent ad8d1b89ae
commit 9fc910c37d
5 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,6 @@
language: python language: python
python: python:
- "3.5"
- "3.6.1" - "3.6.1"
- "3.7-dev" - "3.7-dev"
install: install:

View File

@ -35,7 +35,8 @@ tests_require = [
'pytest>=3.1.1', 'pytest>=3.1.1',
'pytest-asyncio==0.6.0', 'pytest-asyncio==0.6.0',
'asynctest==0.10.0', 'asynctest==0.10.0',
'pytest-mock==1.6.2' 'pytest-mock==1.6.2',
'async-generator==1.8'
] ]
extras_require = { extras_require = {

View File

@ -1,5 +1,7 @@
from functools import wraps from functools import wraps
from async_generator import async_generator, yield_
from ssb.packet_stream import PSMessageType from ssb.packet_stream import PSMessageType
@ -28,11 +30,12 @@ class MuxRPCSourceHandler(MuxRPCHandler):
def __init__(self, ps_handler): def __init__(self, ps_handler):
self.ps_handler = ps_handler self.ps_handler = ps_handler
@async_generator
async def __aiter__(self): async def __aiter__(self):
async for msg in self.ps_handler: async for msg in self.ps_handler:
try: try:
self.check_message(msg) self.check_message(msg)
yield msg await yield_(msg)
except MuxRPCAPIException: except MuxRPCAPIException:
raise raise

View File

@ -4,9 +4,10 @@ from asyncio import Event, Queue
from enum import Enum from enum import Enum
from time import time from time import time
from secret_handshake import SHSClient, SHSServer
import simplejson import simplejson
from async_generator import async_generator, yield_
from secret_handshake import SHSClient, SHSServer
logger = logging.getLogger('packet_stream') logger = logging.getLogger('packet_stream')
@ -30,12 +31,13 @@ class PSStreamHandler(object):
async def stop(self): async def stop(self):
await self.queue.put(None) await self.queue.put(None)
@async_generator
async def __aiter__(self): async def __aiter__(self):
while True: while True:
elem = await self.queue.get() elem = await self.queue.get()
if not elem: if not elem:
return return
yield elem await yield_(elem)
class PSRequestHandler(object): class PSRequestHandler(object):
@ -154,6 +156,7 @@ class PSConnection(object):
def register_handler(self, handler): def register_handler(self, handler):
self._event_map[handler.req] = (time(), handler) self._event_map[handler.req] = (time(), handler)
@async_generator
async def __aiter__(self): async def __aiter__(self):
while True: while True:
msg = await self.read() msg = await self.read()
@ -161,7 +164,7 @@ class PSConnection(object):
return return
# filter out replies # filter out replies
if msg.req >= 0: if msg.req >= 0:
yield msg await yield_(msg)
def _write(self, msg): def _write(self, msg):
logger.info('SEND [%d]: %r', msg.req, msg) logger.info('SEND [%d]: %r', msg.req, msg)

View File

@ -1,5 +1,7 @@
import pytest import json
from asyncio import ensure_future, gather, Event from asyncio import ensure_future, gather, Event
import pytest
from asynctest import patch from asynctest import patch
from nacl.signing import SigningKey from nacl.signing import SigningKey