Skip to content

Commit

Permalink
Merge pull request #46 from aio-libs/stream
Browse files Browse the repository at this point in the history
Zmq streams
  • Loading branch information
asvetlov committed Feb 13, 2015
2 parents e5085be + a49c863 commit c878bb6
Show file tree
Hide file tree
Showing 16 changed files with 853 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ install:
- test $USE_MSGPACK == 1 && pip install msgpack-python || true
- pip install pyflakes
- pip install pep8
- pip install docutils
- pip install coveralls

script:
- python -c "import zmq; print('ZMQ version:', zmq.zmq_version())"
- pep8 aiozmq examples tests benchmarks
- pyflakes .
- python setup.py check -rms
- python runtests.py --coverage -v

after_success:
Expand Down
10 changes: 3 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ Documentation

See http://aiozmq.readthedocs.org

RPC Example
-----------

Simple client-server RPC example

.. code-block:: python
Simple client-server RPC example::

import asyncio
import aiozmq.rpc
Expand Down Expand Up @@ -44,6 +39,7 @@ Simple client-server RPC example

asyncio.get_event_loop().run_until_complete(go())


Requirements
------------

Expand All @@ -59,7 +55,7 @@ License

aiozmq is offered under the BSD license.

.. _python: https://www.python.org/downloads/
.. _python: https://www.python.org/
.. _pyzmq: https://pypi.python.org/pypi/pyzmq
.. _asyncio: https://pypi.python.org/pypi/asyncio
.. _msgpack-python: https://pypi.python.org/pypi/msgpack-python
10 changes: 8 additions & 2 deletions aiozmq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from collections import namedtuple
import re
import sys
from collections import namedtuple

import zmq

from .selector import ZmqSelector
from .core import ZmqEventLoop, ZmqEventLoopPolicy, create_zmq_connection
from .interface import ZmqTransport, ZmqProtocol
from .selector import ZmqSelector
from .stream import (ZmqStream, ZmqStreamProtocol, ZmqStreamClosed,
create_zmq_stream)


__all__ = ('ZmqSelector', 'ZmqEventLoop', 'ZmqEventLoopPolicy',
'ZmqTransport', 'ZmqProtocol',
'ZmqStream', 'ZmqStreamProtocol', 'create_zmq_stream',
'ZmqStreamClosed',
'create_zmq_connection',
'version_info', 'version')

Expand Down Expand Up @@ -50,4 +55,5 @@ def _parse_version(ver):

# make pyflakes happy
(ZmqSelector, ZmqEventLoop, ZmqEventLoopPolicy, ZmqTransport, ZmqProtocol,
ZmqStream, ZmqStreamProtocol, ZmqStreamClosed, create_zmq_stream,
create_zmq_connection)
2 changes: 1 addition & 1 deletion aiozmq/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging


logger = logging.getLogger(__name__)
logger = logging.getLogger(__package__)
16 changes: 8 additions & 8 deletions aiozmq/rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
"""ZeroMQ RPC/Pipeline/PubSub services"""

_MSGPACK_VERSION = (0, 4, 0)
_MSGPACK_VERSION_STR = '.'.join(map(str, _MSGPACK_VERSION))

try:
from msgpack import version as msgpack_version
except ImportError: # pragma: no cover
msgpack_version = (0,)

if msgpack_version < _MSGPACK_VERSION: # pragma: no cover
raise ImportError("aiozmq.rpc requires msgpack-python package"
" (version >= {})".format(_MSGPACK_VERSION_STR))


from .base import (
method,
AbstractHandler,
Expand All @@ -39,6 +31,14 @@

from .log import logger

_MSGPACK_VERSION = (0, 4, 0)
_MSGPACK_VERSION_STR = '.'.join(map(str, _MSGPACK_VERSION))

if msgpack_version < _MSGPACK_VERSION: # pragma: no cover
raise ImportError("aiozmq.rpc requires msgpack-python package"
" (version >= {})".format(_MSGPACK_VERSION_STR))


__all__ = [
'method',
'connect_rpc',
Expand Down
5 changes: 2 additions & 3 deletions aiozmq/rpc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import inspect
import pprint
import textwrap

from aiozmq import interface
from types import MethodType

from .packer import _Packer
from .log import logger
from .packer import _Packer
from aiozmq import interface


class Error(Exception):
Expand Down
1 change: 0 additions & 1 deletion aiozmq/rpc/packer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Private utility functions."""

from collections import ChainMap
from datetime import datetime, date, time, timedelta, tzinfo
from functools import partial
Expand Down
6 changes: 2 additions & 4 deletions aiozmq/rpc/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import asyncio
import zmq

from functools import partial

import zmq
from aiozmq import create_zmq_connection

from .log import logger

from .base import (
NotFoundError,
ParametersError,
Expand All @@ -15,6 +12,7 @@
_BaseProtocol,
_BaseServerProtocol,
)
from .log import logger
from .util import (
_MethodCall,
)
Expand Down
7 changes: 4 additions & 3 deletions aiozmq/rpc/pubsub.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio
import zmq
from functools import partial
from collections import Iterable
from functools import partial

import zmq

from aiozmq import create_zmq_connection

from .log import logger
from .base import (
NotFoundError,
ParametersError,
Expand All @@ -14,6 +14,7 @@
_BaseProtocol,
_BaseServerProtocol,
)
from .log import logger


@asyncio.coroutine
Expand Down
11 changes: 3 additions & 8 deletions aiozmq/rpc/rpc.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
"""ZeroMQ RPC"""

import asyncio
import os
import random
import struct
import time
import sys

import zmq


import time
from collections import ChainMap
from functools import partial

import zmq
from aiozmq import create_zmq_connection

from .log import logger

from .base import (
GenericError,
NotFoundError,
Expand All @@ -26,6 +20,7 @@
_BaseProtocol,
_BaseServerProtocol,
)
from .log import logger
from .util import (
_MethodCall,
_fill_error_table,
Expand Down
11 changes: 6 additions & 5 deletions aiozmq/selector.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""ZMQ pooler for asyncio."""
import math
from collections import Mapping
from errno import EINTR

from zmq import (ZMQError, POLLIN, POLLOUT, POLLERR,
Socket as ZMQSocket, Poller as ZMQPoller)


__all__ = ['ZmqSelector']

import math

try:
from asyncio.selectors import (BaseSelector, SelectorKey,
EVENT_READ, EVENT_WRITE)
except ImportError: # pragma: no cover
from selectors import BaseSelector, SelectorKey, EVENT_READ, EVENT_WRITE
from collections import Mapping
from errno import EINTR
from zmq import (ZMQError, POLLIN, POLLOUT, POLLERR,
Socket as ZMQSocket, Poller as ZMQPoller)


def _fileobj_to_fd(fileobj):
Expand Down

0 comments on commit c878bb6

Please sign in to comment.