# Path: opendiamond/protocol.py
# PORT = 5872
# NONCE_LEN = 16
# NULL_NONCE = b'\x00' * NONCE_LEN
# class DiamondRPCFailure(RPCError):
# class DiamondRPCFCacheMiss(RPCError):
# class DiamondRPCCookieExpired(RPCError):
# class DiamondRPCSchemeNotSupported(RPCError):
# class XDR_attribute(XDRStruct):
# class XDR_object(XDRStruct):
# class XDR_blob_list(XDRStruct):
# class XDR_filter_config(XDRStruct):
# class XDR_setup(XDRStruct):
# class XDR_blob_data(XDRStruct):
# class XDR_start(XDRStruct):
# class XDR_stat(XDRStruct):
# class XDR_filter_stats(XDRStruct):
# class XDR_search_stats(XDRStruct):
# class XDR_session_var(XDRStruct):
# class XDR_session_vars(XDRStruct):
# class XDR_reexecute(XDRStruct):
# class XDR_retrain(XDRStruct):
# class XDR_attribute_list(XDRStruct):
# 
# Path: opendiamond/rpc.py
# class RPCHeader(XDRStruct):
#     '''An RPC message header.'''
# 
#     ENCODED_LENGTH = 16
# 
#     members = (
#         'sequence', XDR.uint(),
#         'status', XDR.int(),
#         'cmd', XDR.int(),
#         'datalen', XDR.uint(),
#     )
# 
# RPC_PENDING = -1
# 
# class RPCError(Exception):
#     '''Base class for RPC error codes.'''
#     code = None
# 
#     # pylint doesn't know about __subclasses__
#     # pylint: disable=no-member
#     @classmethod
#     def get_class(cls, code):
#         '''Return the error subclass for the specified code.'''
#         for c in cls.__subclasses__():
#             if c.code == code:
#                 return c
#             try:
#                 return c.get_class(code)
#             except KeyError:
#                 pass
#         raise KeyError('Error code %d' % code)
#     # pylint: enable=no-member
# 
# class RPCEncodingError(RPCError):
#     '''Bad XDR structure.'''
#     code = -2
# 
# class ConnectionFailure(Exception):
#     '''RPC connection died.'''


from builtins import next
from builtins import str
from builtins import object
from tornado import gen, stack_context
from tornado.iostream import IOStream
from opendiamond import protocol
from opendiamond.rpc import (
    RPCHeader, RPC_PENDING, RPCError, RPCEncodingError, ConnectionFailure)
import itertools
import logging
import socket
            except KeyError:
                _log.warning('Received reply with no registered callback')
                # Drop on the floor
                continue

            try:
                callback(hdr.status, data)
            except Exception:
                # Don't crash the coroutine if the callback fails
                _log.exception('Reply callback raised exception')
    # pylint: enable=broad-except


# pylint doesn't understand that this is an instance method factory
# pylint: disable=protected-access
def _stub(cmd, request_class=None, reply_class=None):
    if request_class is not None:
        request_type = request_class
    else:
        request_type = type(None)

    def call(self, request=None, callback=None):
        if not isinstance(request, request_type):
            raise RPCEncodingError('Incorrect request type')
        self._call(cmd, request, reply_class, callback)
    return call
# pylint: enable=protected-access


class ControlConnection(_RPCClientConnection):

# Path: opendiamond/protocol.py
# PORT = 5872
# NONCE_LEN = 16
# NULL_NONCE = b'\x00' * NONCE_LEN
# class DiamondRPCFailure(RPCError):
# class DiamondRPCFCacheMiss(RPCError):
# class DiamondRPCCookieExpired(RPCError):
# class DiamondRPCSchemeNotSupported(RPCError):
# class XDR_attribute(XDRStruct):
# class XDR_object(XDRStruct):
# class XDR_blob_list(XDRStruct):
# class XDR_filter_config(XDRStruct):
# class XDR_setup(XDRStruct):
# class XDR_blob_data(XDRStruct):
# class XDR_start(XDRStruct):
# class XDR_stat(XDRStruct):
# class XDR_filter_stats(XDRStruct):
# class XDR_search_stats(XDRStruct):
# class XDR_session_var(XDRStruct):
# class XDR_session_vars(XDRStruct):
# class XDR_reexecute(XDRStruct):
# class XDR_retrain(XDRStruct):
# class XDR_attribute_list(XDRStruct):
# 
# Path: opendiamond/rpc.py
# class RPCHeader(XDRStruct):
#     '''An RPC message header.'''
# 
#     ENCODED_LENGTH = 16
# 
#     members = (
#         'sequence', XDR.uint(),
#         'status', XDR.int(),
#         'cmd', XDR.int(),
#         'datalen', XDR.uint(),
#     )
# 
# RPC_PENDING = -1
# 
# class RPCError(Exception):
#     '''Base class for RPC error codes.'''
#     code = None
# 
#     # pylint doesn't know about __subclasses__
#     # pylint: disable=no-member
#     @classmethod
#     def get_class(cls, code):
#         '''Return the error subclass for the specified code.'''
#         for c in cls.__subclasses__():
#             if c.code == code:
#                 return c
#             try:
#                 return c.get_class(code)
#             except KeyError:
#                 pass
#         raise KeyError('Error code %d' % code)
#     # pylint: enable=no-member
# 
# class RPCEncodingError(RPCError):
#     '''Bad XDR structure.'''
#     code = -2
# 
# class ConnectionFailure(Exception):
#     '''RPC connection died.'''


# Path: opendiamond/blaster/rpc.py
from builtins import next
from builtins import str
from builtins import object
from tornado import gen, stack_context
from tornado.iostream import IOStream
from opendiamond import protocol
from opendiamond.rpc import (
    RPCHeader, RPC_PENDING, RPCError, RPCEncodingError, ConnectionFailure)
import itertools
import logging
import socket

            except KeyError:
                _log.warning('Received reply with no registered callback')
                # Drop on the floor
                continue

            try:
                callback(hdr.status, data)
            except Exception:
                # Don't crash the coroutine if the callback fails
                _log.exception('Reply callback raised exception')
    # pylint: enable=broad-except


# pylint doesn't understand that this is an instance method factory
# pylint: disable=protected-access
def _stub(cmd, request_class=None, reply_class=None):
    if request_class is not None:
        request_type = request_class
    else:
        request_type = type(None)

    def call(self, request=None, callback=None):
        if not isinstance(request, request_type):
            raise RPCEncodingError('Incorrect request type')
        self._call(cmd, request, reply_class, callback)
    return call
# pylint: enable=protected-access


class ControlConnection(_RPCClientConnection):

    setup = _stub(25, protocol.XDR_setup, protocol.XDR_blob_list)