# Path: deepstreampy/client.py
# @gen.coroutine
# def connect(url, **options):
#     """Establish a connection to a deepstream.io server.
# 
#     Args:
#         url (string): URL to connect to
#         **options: The options for the client
# 
#     Returns:
#         tornado.concurrent.Future: A future that resolves with an instance of
#             ``deepstreampy.client.Client`` when a connection is established. If
#             the client is unable to connect, the future will have the
#             appropriate exception set.
#     """
#     client = Client(url, **options)
#     yield client.connect()
#     raise gen.Return(client)
# 
# Path: deepstreampy/rpc.py
# class RPCResponse(object):
# class RPCException(Exception):
# class RPC(object):
# class RPCHandler(object):
#     def __init__(self, connection, name, correlation_id):
#     def ack(self):
#     def reject(self):
#     def send(self, data):
#     def error(self, error_str):
#     def _perform_auto_ack(self):
#     def __init__(self, message):
#     def __init__(self, future, client, **options):
#     def ack(self):
#     def respond(self, data):
#     def error(self, error_msg):
#     def _complete(self):
#     def __init__(self, connection, client, **options):
#     def provide(self, name, callback):
#     def unprovide(self, name):
#     def make(self, name, data):
#     def _get_rpc(self, correlation_id, rpc_name, raw_message):
#     def _respond_to_rpc(self, message):
#     def handle(self, message):
#     def _reprovide(self):


from deepstreampy import connect
from deepstreampy import rpc
from tornado import gen
from tornado import ioloop
import signal
"""
An example showing how to use remote procedure calls with deepstreampy.
"""
from __future__ import absolute_import, division, print_function, with_statement
from __future__ import unicode_literals





def sq(x, response):
    """
    An RPC handler function that sends the square root of the input.
    """
    if isinstance(x, int):
        response.send(x * x)
    else:
        response.error("sq received unexpected input")


@gen.coroutine
def run():
    # First we set up the provider
    provider = yield connect("ws://localhost:6020/deepstream")
    yield provider.login({"username": "A"})
    provider.on('error', lambda msg, event, topic: print('a provider error occured'))

    yield provider.rpc.provide("sq", sq)

    # Then we set up the consumer

# Path: deepstreampy/client.py
# @gen.coroutine
# def connect(url, **options):
#     """Establish a connection to a deepstream.io server.
# 
#     Args:
#         url (string): URL to connect to
#         **options: The options for the client
# 
#     Returns:
#         tornado.concurrent.Future: A future that resolves with an instance of
#             ``deepstreampy.client.Client`` when a connection is established. If
#             the client is unable to connect, the future will have the
#             appropriate exception set.
#     """
#     client = Client(url, **options)
#     yield client.connect()
#     raise gen.Return(client)
# 
# Path: deepstreampy/rpc.py
# class RPCResponse(object):
# class RPCException(Exception):
# class RPC(object):
# class RPCHandler(object):
#     def __init__(self, connection, name, correlation_id):
#     def ack(self):
#     def reject(self):
#     def send(self, data):
#     def error(self, error_str):
#     def _perform_auto_ack(self):
#     def __init__(self, message):
#     def __init__(self, future, client, **options):
#     def ack(self):
#     def respond(self, data):
#     def error(self, error_msg):
#     def _complete(self):
#     def __init__(self, connection, client, **options):
#     def provide(self, name, callback):
#     def unprovide(self, name):
#     def make(self, name, data):
#     def _get_rpc(self, correlation_id, rpc_name, raw_message):
#     def _respond_to_rpc(self, message):
#     def handle(self, message):
#     def _reprovide(self):


# Path: examples/rpc_example.py
from deepstreampy import connect
from deepstreampy import rpc
from tornado import gen
from tornado import ioloop
import signal

"""
An example showing how to use remote procedure calls with deepstreampy.
"""
from __future__ import absolute_import, division, print_function, with_statement
from __future__ import unicode_literals





def sq(x, response):
    """
    An RPC handler function that sends the square root of the input.
    """
    if isinstance(x, int):
        response.send(x * x)
    else:
        response.error("sq received unexpected input")


@gen.coroutine
def run():
    # First we set up the provider
    provider = yield connect("ws://localhost:6020/deepstream")
    yield provider.login({"username": "A"})
    provider.on('error', lambda msg, event, topic: print('a provider error occured'))

    yield provider.rpc.provide("sq", sq)

    # Then we set up the consumer

    consumer = yield connect("ws://localhost:6020/deepstream")