# Path: opendiamond/xdr.py
# class XDR(object):
#     '''Class containing static factory functions for XDR type handlers.'''
#     def __init__(self):
#         raise RuntimeError('Class cannot be instantiated')
# 
#     @staticmethod
#     def int():
#         return _XDRPrimitiveHandler('int')
# 
#     @staticmethod
#     def uint():
#         return _XDRPrimitiveHandler('uint')
# 
#     @staticmethod
#     def hyper():
#         return _XDRPrimitiveHandler('hyper')
# 
#     @staticmethod
#     def double():
#         return _XDRPrimitiveHandler('double')
# 
#     @staticmethod
#     def string():
#         return _XDRStringHandler()
# 
#     @staticmethod
#     def opaque():
#         return _XDRPrimitiveHandler('opaque')
# 
#     @staticmethod
#     def fopaque(length):
#         return _XDRFOpaqueHandler(length)
# 
#     @staticmethod
#     def array(item_handler):
#         return _XDRArrayHandler(item_handler)
# 
#     @staticmethod
#     def optional(item_handler):
#         return _XDROptionalHandler(item_handler)
# 
#     @staticmethod
#     def constant(item_handler, value):
#         return _XDRConstantHandler(item_handler, value)
# 
#     @staticmethod
#     def struct(struct_class):
#         return _XDRStructHandler(struct_class)
# 
# class XDRStruct(object):
#     '''Base class for an XDR struct.'''
# 
#     members = ()
# 
#     def __init__(self, *args, **kwargs):
#         attrs = [a for a, _h in self._members() if a is not None]
#         for attr in attrs:
#             setattr(self, attr, None)
#         for attr, arg in zip(attrs, args):
#             setattr(self, attr, arg)
#         for k, v in kwargs.items():
#             if k not in attrs:
#                 raise TypeError('No such keyword argument: %s' % k)
#             setattr(self, k, v)
# 
#     @classmethod
#     def _members(cls):
#         '''cls.members, converted into a list of 2-tuples (attr, handler).'''
#         return list(zip(cls.members[::2], cls.members[1::2]))
# 
#     def encode(self):
#         '''Return the serialized bytes for the object.'''
#         with _convert_exceptions():
#             xdr = Packer()
#             self.encode_xdr(xdr)
#             return xdr.get_buffer()
# 
#     @classmethod
#     def decode(cls, data):
#         '''Deserialize the data and return an object.'''
#         with _convert_exceptions():
#             xdr = Unpacker(data)
#             ret = cls.decode_xdr(xdr)
#             xdr.done()
#             return ret
# 
#     def encode_xdr(self, xdr):
#         '''Serialize the object into an XDR stream.'''
#         for attr, handler in self._members():
#             if attr is not None:
#                 value = getattr(self, attr)
#             else:
#                 value = None
#             try:
#                 handler.pack(xdr, value)
#             except Exception as e:
#                 raise XDREncodingError('Failed to encode attr {}'.format(attr)) from e
# 
#     @classmethod
#     def decode_xdr(cls, xdr):
#         '''Deserialize the object from an XDR stream.'''
#         kwargs = {}
#         for attr, handler in cls._members():
#             value = handler.unpack(xdr)
#             if attr is not None:
#                 kwargs[attr] = value
#         return cls(**kwargs)
# 
# class XDREncodingError(Exception):
#     pass


from builtins import str
from builtins import object
from opendiamond.xdr import XDR, XDRStruct, XDREncodingError
from future.utils import with_metaclass
import logging
import multiprocessing as mp
import socket
import threading
                else:
                    ret_obj = handler()

                # Encode reply
                if ret_obj is None:
                    assert handler.rpc_reply_class is None
                    ret = b''
                else:
                    assert isinstance(ret_obj, handler.rpc_reply_class)
                    ret = ret_obj.encode()

                # Send reply
                self._reply(req, body=ret)
                if handlers.log_rpcs:
                    _log.debug('%s => success', handler_name)
            except RPCError as e:
                self._reply(req, status=e.code)
                if handlers.log_rpcs:
                    _log.debug('%s => %s', handler_name, e.__class__.__name__)


# _RPCMeta accesses a protected member of the classes it controls
# pylint: disable=protected-access
class _RPCMeta(type):
    '''Metaclass for RPCHandlers that collects the methods tagged with
    @RPCHandlers.handler into a dictionary.'''

    def __new__(mcs, name, bases, dct):
        obj = type.__new__(mcs, name, bases, dct)
        obj._cmds = dict()

# Path: opendiamond/xdr.py
# class XDR(object):
#     '''Class containing static factory functions for XDR type handlers.'''
#     def __init__(self):
#         raise RuntimeError('Class cannot be instantiated')
# 
#     @staticmethod
#     def int():
#         return _XDRPrimitiveHandler('int')
# 
#     @staticmethod
#     def uint():
#         return _XDRPrimitiveHandler('uint')
# 
#     @staticmethod
#     def hyper():
#         return _XDRPrimitiveHandler('hyper')
# 
#     @staticmethod
#     def double():
#         return _XDRPrimitiveHandler('double')
# 
#     @staticmethod
#     def string():
#         return _XDRStringHandler()
# 
#     @staticmethod
#     def opaque():
#         return _XDRPrimitiveHandler('opaque')
# 
#     @staticmethod
#     def fopaque(length):
#         return _XDRFOpaqueHandler(length)
# 
#     @staticmethod
#     def array(item_handler):
#         return _XDRArrayHandler(item_handler)
# 
#     @staticmethod
#     def optional(item_handler):
#         return _XDROptionalHandler(item_handler)
# 
#     @staticmethod
#     def constant(item_handler, value):
#         return _XDRConstantHandler(item_handler, value)
# 
#     @staticmethod
#     def struct(struct_class):
#         return _XDRStructHandler(struct_class)
# 
# class XDRStruct(object):
#     '''Base class for an XDR struct.'''
# 
#     members = ()
# 
#     def __init__(self, *args, **kwargs):
#         attrs = [a for a, _h in self._members() if a is not None]
#         for attr in attrs:
#             setattr(self, attr, None)
#         for attr, arg in zip(attrs, args):
#             setattr(self, attr, arg)
#         for k, v in kwargs.items():
#             if k not in attrs:
#                 raise TypeError('No such keyword argument: %s' % k)
#             setattr(self, k, v)
# 
#     @classmethod
#     def _members(cls):
#         '''cls.members, converted into a list of 2-tuples (attr, handler).'''
#         return list(zip(cls.members[::2], cls.members[1::2]))
# 
#     def encode(self):
#         '''Return the serialized bytes for the object.'''
#         with _convert_exceptions():
#             xdr = Packer()
#             self.encode_xdr(xdr)
#             return xdr.get_buffer()
# 
#     @classmethod
#     def decode(cls, data):
#         '''Deserialize the data and return an object.'''
#         with _convert_exceptions():
#             xdr = Unpacker(data)
#             ret = cls.decode_xdr(xdr)
#             xdr.done()
#             return ret
# 
#     def encode_xdr(self, xdr):
#         '''Serialize the object into an XDR stream.'''
#         for attr, handler in self._members():
#             if attr is not None:
#                 value = getattr(self, attr)
#             else:
#                 value = None
#             try:
#                 handler.pack(xdr, value)
#             except Exception as e:
#                 raise XDREncodingError('Failed to encode attr {}'.format(attr)) from e
# 
#     @classmethod
#     def decode_xdr(cls, xdr):
#         '''Deserialize the object from an XDR stream.'''
#         kwargs = {}
#         for attr, handler in cls._members():
#             value = handler.unpack(xdr)
#             if attr is not None:
#                 kwargs[attr] = value
#         return cls(**kwargs)
# 
# class XDREncodingError(Exception):
#     pass


# Path: opendiamond/rpc.py
from builtins import str
from builtins import object
from opendiamond.xdr import XDR, XDRStruct, XDREncodingError
from future.utils import with_metaclass
import logging
import multiprocessing as mp
import socket
import threading

                else:
                    ret_obj = handler()

                # Encode reply
                if ret_obj is None:
                    assert handler.rpc_reply_class is None
                    ret = b''
                else:
                    assert isinstance(ret_obj, handler.rpc_reply_class)
                    ret = ret_obj.encode()

                # Send reply
                self._reply(req, body=ret)
                if handlers.log_rpcs:
                    _log.debug('%s => success', handler_name)
            except RPCError as e:
                self._reply(req, status=e.code)
                if handlers.log_rpcs:
                    _log.debug('%s => %s', handler_name, e.__class__.__name__)


# _RPCMeta accesses a protected member of the classes it controls
# pylint: disable=protected-access
class _RPCMeta(type):
    '''Metaclass for RPCHandlers that collects the methods tagged with
    @RPCHandlers.handler into a dictionary.'''

    def __new__(mcs, name, bases, dct):
        obj = type.__new__(mcs, name, bases, dct)
        obj._cmds = dict()

        for attribute in dir(obj):