# 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
                                      ssl_version=self.ssl_config.ssl_version,
                                      keyfile=self.ssl_config.keyfile,
                                      certfile=self.ssl_config.certfile,
                                      cert_reqs=self.ssl_config.cert_reqs,
                                      ca_certs=self.ssl_config.ca_certs)
        newsock = LinkSocket(newsock, self.ssl_config)
        newsock.remote_peer = addr
        return newsock, addr

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

    def connect(self):
        self.is_connector = True
        if self.ssl_config is not None:
            self.sock = ssl.wrap_socket(self.sock, server_side=False,
                                      do_handshake_on_connect=False,
                                      ssl_version=self.ssl_config.ssl_version,
                                      keyfile=self.ssl_config.keyfile,
                                      certfile=self.ssl_config.certfile,
                                      cert_reqs=self.ssl_config.cert_reqs,
                                      ca_certs=self.ssl_config.ca_certs)
        return self.sock.connect_ex(self.remote_peer)

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

    def send(self, data):
        """
        If data is ``None`` then ``self.write_buf`` is used.
        """
        if (data is not None) and not self.send_finished:

# 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

                                      ssl_version=self.ssl_config.ssl_version,
                                      keyfile=self.ssl_config.keyfile,
                                      certfile=self.ssl_config.certfile,
                                      cert_reqs=self.ssl_config.cert_reqs,
                                      ca_certs=self.ssl_config.ca_certs)
        newsock = LinkSocket(newsock, self.ssl_config)
        newsock.remote_peer = addr
        return newsock, addr

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

    def connect(self):
        self.is_connector = True
        if self.ssl_config is not None:
            self.sock = ssl.wrap_socket(self.sock, server_side=False,
                                      do_handshake_on_connect=False,
                                      ssl_version=self.ssl_config.ssl_version,
                                      keyfile=self.ssl_config.keyfile,
                                      certfile=self.ssl_config.certfile,
                                      cert_reqs=self.ssl_config.cert_reqs,
                                      ca_certs=self.ssl_config.ca_certs)
        return self.sock.connect_ex(self.remote_peer)

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

    def send(self, data):
        """
        If data is ``None`` then ``self.write_buf`` is used.
        """
        if (data is not None) and not self.send_finished:

            raise SendNotFinished(("previous send on %r is not finished, " +