# Path: snakemq/exceptions.py
# class SendNotFinished(SnakeMQException):
#     pass
# 
# Path: snakemq/poll.py
# def poll(self, timeout):
#     """
#     :param timeout: seconds
#     """
#     if len(self.fds) == 0:
#         time.sleep(timeout)
#         return []
# 
#     rlist = []
#     wlist = []
#     xlist = []
#     for fd, mask in self.fds.items():
#         fd = self._socket_to_fd(fd)
#         if mask & select.EPOLLIN:
#             rlist.append(fd)
#         if mask & select.EPOLLOUT:
#             wlist.append(fd)
#         xlist.append(fd)
# 
#     rlist, wlist, xlist = select.select(rlist, wlist, xlist, timeout)
# 
#     res = {}
#     for fd in rlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLIN
#     for fd in wlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLOUT
#     for fd in xlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLERR
# 
#     return res.items()
# 
# Path: snakemq/callbacks.py
# class Callback(object):
#     def __init__(self):
#         self.callbacks = []
# 
#     ####################################################
# 
#     def add(self, func):
#         self.callbacks.append(func)
# 
#     ####################################################
# 
#     def remove(self, func):
#         self.callbacks.remove(func)
# 
#     ####################################################
# 
#     def __call__(self, *args, **kwargs):
#         for callback in self.callbacks:
#             callback(*args, **kwargs)


import select
import socket
import errno
import time
import bisect
import logging
    import ssl
    import dummyssl as ssl
from snakemq.exceptions import SendNotFinished
from snakemq.poll import poll
from snakemq.pollbell import Bell
from snakemq.callbacks import Callback
        :see: python documentation - ssl.SSLSocket.getpeercert()
        :return: peer's SSL certificate if available or None
        """
        if self.ssl_config is None:
            return None
        else:
            return self.sock._sslobj.peer_certificate(binary_form)

############################################################################
############################################################################

class Link(object):
    """
    Just a bare wire stream communication. Keeper of opened (TCP) connections.
    **Not thread-safe** but you can synchronize with the loop using
    :meth:`~.wakeup_poll` and :attr:`~.on_loop_pass`.
    """

    def __init__(self):
        self.log = logging.getLogger("snakemq.link")

        self.reconnect_interval = RECONNECT_INTERVAL  #: in seconds
        self.recv_block_size = RECV_BLOCK_SIZE

        #{ callbacks
        self.on_connect = Callback()  #: ``func(conn_id)``
        self.on_disconnect = Callback()  #: ``func(conn_id)``
        #: ``func(conn_id, data)``
        self.on_recv = Callback()
        #: ``func(conn_id, last_send_size)``, last send was successful

# Path: snakemq/exceptions.py
# class SendNotFinished(SnakeMQException):
#     pass
# 
# Path: snakemq/poll.py
# def poll(self, timeout):
#     """
#     :param timeout: seconds
#     """
#     if len(self.fds) == 0:
#         time.sleep(timeout)
#         return []
# 
#     rlist = []
#     wlist = []
#     xlist = []
#     for fd, mask in self.fds.items():
#         fd = self._socket_to_fd(fd)
#         if mask & select.EPOLLIN:
#             rlist.append(fd)
#         if mask & select.EPOLLOUT:
#             wlist.append(fd)
#         xlist.append(fd)
# 
#     rlist, wlist, xlist = select.select(rlist, wlist, xlist, timeout)
# 
#     res = {}
#     for fd in rlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLIN
#     for fd in wlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLOUT
#     for fd in xlist:
#         res[fd] = res.get(fd, 0) | select.EPOLLERR
# 
#     return res.items()
# 
# Path: snakemq/callbacks.py
# class Callback(object):
#     def __init__(self):
#         self.callbacks = []
# 
#     ####################################################
# 
#     def add(self, func):
#         self.callbacks.append(func)
# 
#     ####################################################
# 
#     def remove(self, func):
#         self.callbacks.remove(func)
# 
#     ####################################################
# 
#     def __call__(self, *args, **kwargs):
#         for callback in self.callbacks:
#             callback(*args, **kwargs)


# Path: snakemq/link.py
import select
import socket
import errno
import time
import bisect
import logging
    import ssl
    import dummyssl as ssl
from snakemq.exceptions import SendNotFinished
from snakemq.poll import poll
from snakemq.pollbell import Bell
from snakemq.callbacks import Callback

        :see: python documentation - ssl.SSLSocket.getpeercert()
        :return: peer's SSL certificate if available or None
        """
        if self.ssl_config is None:
            return None
        else:
            return self.sock._sslobj.peer_certificate(binary_form)

############################################################################
############################################################################

class Link(object):
    """
    Just a bare wire stream communication. Keeper of opened (TCP) connections.
    **Not thread-safe** but you can synchronize with the loop using
    :meth:`~.wakeup_poll` and :attr:`~.on_loop_pass`.
    """

    def __init__(self):
        self.log = logging.getLogger("snakemq.link")

        self.reconnect_interval = RECONNECT_INTERVAL  #: in seconds
        self.recv_block_size = RECV_BLOCK_SIZE

        #{ callbacks
        self.on_connect = Callback()  #: ``func(conn_id)``
        self.on_disconnect = Callback()  #: ``func(conn_id)``
        #: ``func(conn_id, data)``
        self.on_recv = Callback()
        #: ``func(conn_id, last_send_size)``, last send was successful

        self.on_ready_to_send = Callback()