# Path: deepstreampy/constants/actions.py
# PING = 'PI'
# PONG = 'PO'
# ACK = 'A'
# REDIRECT = 'RED'
# CHALLENGE = 'CH'
# CHALLENGE_RESPONSE = 'CHR'
# READ = 'R'
# CREATE = 'C'
# UPDATE = 'U'
# PATCH = 'P'
# DELETE = 'D'
# SUBSCRIBE = 'S'
# UNSUBSCRIBE = 'US'
# HAS = 'H'
# SNAPSHOT = 'SN'
# INVOKE = 'I'
# SUBSCRIPTION_FOR_PATTERN_FOUND = 'SP'
# SUBSCRIPTION_FOR_PATTERN_REMOVED = 'SR'
# SUBSCRIPTION_HAS_PROVIDER = 'SH'
# LISTEN = 'L'
# UNLISTEN = 'UL'
# LISTEN_ACCEPT = 'LA'
# LISTEN_REJECT = 'LR'
# PROVIDER_UPDATE = 'PU'
# QUERY = 'Q'
# CREATEORREAD = 'CR'
# EVENT = 'EVT'
# ERROR = 'E'
# REQUEST = 'REQ'
# RESPONSE = 'RES'
# REJECTION = 'REJ'
# PRESENCE_JOIN = 'PNJ'
# PRESENCE_LEAVE = 'PNL'
# QUERY = 'Q'
# WRITE_ACKNOWLEDGEMENT = 'WA'
# def reverse_lookup(action):
# 
# Path: deepstreampy/constants/event.py
# CONNECTION_ERROR = 'connectionError'
# CONNECTION_STATE_CHANGED = 'connectionStateChanged'
# MAX_RECONNECTION_ATTEMPTS_REACHED = 'MAX_RECONNECTION_ATTEMPTS_REACHED'
# CONNECTION_AUTHENTICATION_TIMEOUT = 'CONNECTION_AUTHENTICATION_TIMEOUT'
# ACK_TIMEOUT = 'ACK_TIMEOUT'
# NO_RPC_PROVIDER = 'NO_RPC_PROVIDER'
# RESPONSE_TIMEOUT = 'RESPONSE_TIMEOUT'
# DELETE_TIMEOUT = 'DELETE_TIMEOUT'
# UNSOLICITED_MESSAGE = 'UNSOLICITED_MESSAGE'
# MESSAGE_DENIED = 'MESSAGE_DENIED'
# MESSAGE_PARSE_ERROR = 'MESSAGE_PARSE_ERROR'
# VERSION_EXISTS = 'VERSION_EXISTS'
# NOT_AUTHENTICATED = 'NOT_AUTHENTICATED'
# MESSAGE_PERMISSION_ERROR = 'MESSAGE_PERMISSION_ERROR'
# LISTENER_EXISTS = 'LISTENER_EXISTS'
# NOT_LISTENING = 'NOT_LISTENING'
# TOO_MANY_AUTH_ATTEMPTS = 'TOO_MANY_AUTH_ATTEMPTS'
# IS_CLOSED = 'IS_CLOSED'
# RECORD_NOT_FOUND = 'RECORD_NOT_FOUND'
# NOT_SUBSCRIBED = 'NOT_SUBSCRIBED'
# INVALID_RPC_CORRELATION_ID = 'INVALID_RPC_CORRELATION_ID'
# 
# Path: deepstreampy/constants/connection_state.py
# CLOSED = 'CLOSED'
# AWAITING_AUTHENTICATION = 'AWAITING_AUTHENTICATION'
# AWAITING_CONNECTION = 'AWAITING_CONNECTION'
# AUTHENTICATING = 'AUTHENTICATING'
# OPEN = 'OPEN'
# ERROR = 'ERROR'
# RECONNECTING = 'RECONNECTING'
# CHALLENGING = 'CHALLENGING'


from deepstreampy.constants import actions as action_constants
from deepstreampy.constants import event as event_constants
from deepstreampy.constants import connection_state
from pyee import EventEmitter
from tornado import concurrent
from functools import partial
from collections import namedtuple
import sys
import time
import random
        return self._connection.send_message(
            self._type, action_constants.LISTEN_REJECT, [self._pattern, name])

    def _create_callback_response(self, message):
        return CallbackResponse(
            accept=partial(self.accept, message['data'][1]),
            reject=partial(self.reject, message['data'][1]))

    def _on_message(self, message):
        action = message['action']
        data = message['data']
        if action == action_constants.ACK:
            self._connection._io_loop.remove_timeout(self._ack_timeout)
        elif action == action_constants.SUBSCRIPTION_FOR_PATTERN_FOUND:
            # TODO: Show deprecated message
            self._callback(data[1], True,
                           self._create_callback_response(message))
        elif action == action_constants.SUBSCRIPTION_FOR_PATTERN_REMOVED:
            self._callback(data[1], False)
        else:
            is_found = (message['action'] ==
                        action_constants.SUBSCRIPTION_FOR_PATTERN_FOUND)
            self._callback(message['data'][1], is_found)

    def _send_listen(self):
        self._send_future = self._connection.send_message(
            self._type, action_constants.LISTEN, [self._pattern])

    def _on_ack_timeout(self):
        self._client._on_error(

# Path: deepstreampy/constants/actions.py
# PING = 'PI'
# PONG = 'PO'
# ACK = 'A'
# REDIRECT = 'RED'
# CHALLENGE = 'CH'
# CHALLENGE_RESPONSE = 'CHR'
# READ = 'R'
# CREATE = 'C'
# UPDATE = 'U'
# PATCH = 'P'
# DELETE = 'D'
# SUBSCRIBE = 'S'
# UNSUBSCRIBE = 'US'
# HAS = 'H'
# SNAPSHOT = 'SN'
# INVOKE = 'I'
# SUBSCRIPTION_FOR_PATTERN_FOUND = 'SP'
# SUBSCRIPTION_FOR_PATTERN_REMOVED = 'SR'
# SUBSCRIPTION_HAS_PROVIDER = 'SH'
# LISTEN = 'L'
# UNLISTEN = 'UL'
# LISTEN_ACCEPT = 'LA'
# LISTEN_REJECT = 'LR'
# PROVIDER_UPDATE = 'PU'
# QUERY = 'Q'
# CREATEORREAD = 'CR'
# EVENT = 'EVT'
# ERROR = 'E'
# REQUEST = 'REQ'
# RESPONSE = 'RES'
# REJECTION = 'REJ'
# PRESENCE_JOIN = 'PNJ'
# PRESENCE_LEAVE = 'PNL'
# QUERY = 'Q'
# WRITE_ACKNOWLEDGEMENT = 'WA'
# def reverse_lookup(action):
# 
# Path: deepstreampy/constants/event.py
# CONNECTION_ERROR = 'connectionError'
# CONNECTION_STATE_CHANGED = 'connectionStateChanged'
# MAX_RECONNECTION_ATTEMPTS_REACHED = 'MAX_RECONNECTION_ATTEMPTS_REACHED'
# CONNECTION_AUTHENTICATION_TIMEOUT = 'CONNECTION_AUTHENTICATION_TIMEOUT'
# ACK_TIMEOUT = 'ACK_TIMEOUT'
# NO_RPC_PROVIDER = 'NO_RPC_PROVIDER'
# RESPONSE_TIMEOUT = 'RESPONSE_TIMEOUT'
# DELETE_TIMEOUT = 'DELETE_TIMEOUT'
# UNSOLICITED_MESSAGE = 'UNSOLICITED_MESSAGE'
# MESSAGE_DENIED = 'MESSAGE_DENIED'
# MESSAGE_PARSE_ERROR = 'MESSAGE_PARSE_ERROR'
# VERSION_EXISTS = 'VERSION_EXISTS'
# NOT_AUTHENTICATED = 'NOT_AUTHENTICATED'
# MESSAGE_PERMISSION_ERROR = 'MESSAGE_PERMISSION_ERROR'
# LISTENER_EXISTS = 'LISTENER_EXISTS'
# NOT_LISTENING = 'NOT_LISTENING'
# TOO_MANY_AUTH_ATTEMPTS = 'TOO_MANY_AUTH_ATTEMPTS'
# IS_CLOSED = 'IS_CLOSED'
# RECORD_NOT_FOUND = 'RECORD_NOT_FOUND'
# NOT_SUBSCRIBED = 'NOT_SUBSCRIBED'
# INVALID_RPC_CORRELATION_ID = 'INVALID_RPC_CORRELATION_ID'
# 
# Path: deepstreampy/constants/connection_state.py
# CLOSED = 'CLOSED'
# AWAITING_AUTHENTICATION = 'AWAITING_AUTHENTICATION'
# AWAITING_CONNECTION = 'AWAITING_CONNECTION'
# AUTHENTICATING = 'AUTHENTICATING'
# OPEN = 'OPEN'
# ERROR = 'ERROR'
# RECONNECTING = 'RECONNECTING'
# CHALLENGING = 'CHALLENGING'


# Path: deepstreampy/utils.py
from deepstreampy.constants import actions as action_constants
from deepstreampy.constants import event as event_constants
from deepstreampy.constants import connection_state
from pyee import EventEmitter
from tornado import concurrent
from functools import partial
from collections import namedtuple
import sys
import time
import random

        return self._connection.send_message(
            self._type, action_constants.LISTEN_REJECT, [self._pattern, name])

    def _create_callback_response(self, message):
        return CallbackResponse(
            accept=partial(self.accept, message['data'][1]),
            reject=partial(self.reject, message['data'][1]))

    def _on_message(self, message):
        action = message['action']
        data = message['data']
        if action == action_constants.ACK:
            self._connection._io_loop.remove_timeout(self._ack_timeout)
        elif action == action_constants.SUBSCRIPTION_FOR_PATTERN_FOUND:
            # TODO: Show deprecated message
            self._callback(data[1], True,
                           self._create_callback_response(message))
        elif action == action_constants.SUBSCRIPTION_FOR_PATTERN_REMOVED:
            self._callback(data[1], False)
        else:
            is_found = (message['action'] ==
                        action_constants.SUBSCRIPTION_FOR_PATTERN_FOUND)
            self._callback(message['data'][1], is_found)

    def _send_listen(self):
        self._send_future = self._connection.send_message(
            self._type, action_constants.LISTEN, [self._pattern])

    def _on_ack_timeout(self):
        self._client._on_error(

            self._type, event_constants.ACK_TIMEOUT,