# Path: pyxmpp2/mainloop/interfaces.py
# class IOHandler:
#     """Wrapper for a socket or a file descriptor to be used in event loop
#     or for I/O threads."""
#     # pylint: disable-msg=W0232,R0921
#     __metaclass__ = ABCMeta
# 
#     @abstractmethod
#     def fileno(self):
#         """Return file descriptor to poll or select."""
#         return None
# 
#     @abstractmethod
#     def is_readable(self):
#         """
#         :Return: `True` when the I/O channel can be read
#         """
#         return False
# 
#     @abstractmethod
#     def wait_for_readability(self):
#         """
#         Stop current thread until the channel is readable.
# 
#         :Return: `False` if it won't be readable (e.g. is closed)
#         """
#         return False
# 
#     @abstractmethod
#     def is_writable(self):
#         """
#         :Return: `True` when the I/O channel can be written to
#         """
#         return False
# 
#     @abstractmethod
#     def prepare(self):
#         """
#         Prepare the I/O handler for the event loop or an event loop
#         iteration.
# 
#         :Return: `HandlerReady()` if there is no need to call `prepare` again
#             or `PrepareAgain()` otherwise.
#         :Returntype: `IOHandlerPrepareResult`
#         """
#         return HandlerReady()
# 
#     @abstractmethod
#     def wait_for_writability(self):
#         """
#         Stop current thread until the channel is writable.
# 
#         :Return: `False` if it won't be readable (e.g. is closed)
#         """
#         return False
# 
#     @abstractmethod
#     def handle_write(self):
#         """
#         Handle the 'channel writable' state. E.g. send buffered data via a
#         socket.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_read(self):
#         """
#         Handle the 'channel readable' state. E.g. read from a socket.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_hup(self):
#         """
#         Handle the 'channel hungup' state. The handler should not be writable
#         after this.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_err(self):
#         """
#         Handle an error reported.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_nval(self):
#         """
#         Handle an 'invalid file descriptor' event.
#         """
#         pass
# 
#     @abstractmethod
#     def close(self):
#         """Close the channell immediately, so it won't expect more events."""
#         pass
# 
# class HandlerReady(IOHandlerPrepareResult):
#     """Returned by the `IOHandler.prepare` method
#     when the object is ready to handle I/O events and doesn't need further
#     calls to the `IOHandler.prepare` method.
#     """
#     # pylint: disable-msg=R0903
#     def __repr__(self):
#         return "HandlerReady()"
# 
# Path: pyxmpp2/exceptions.py
# class PyXMPPIOError(Error):
#     """Exception raised on I/O error."""
#     pass
# 
# Path: pyxmpp2/transport.py
# BLOCKING_ERRORS = set()


import threading
import socket
import logging
    from socket import SOMAXCONN
from ..mainloop.interfaces import IOHandler, HandlerReady
from ..exceptions import PyXMPPIOError
from ..transport import BLOCKING_ERRORS
        return

    def handle_read(self):
        """
        Accept any incoming connections.
        """
        with self._lock:
            logger.debug("handle_read()")
            if self._socket is None:
                return
            while True:
                try:
                    sock, address = self._socket.accept()
                except socket.error, err:
                    if err.args[0] in BLOCKING_ERRORS:
                        break
                    else:
                        raise
                logger.debug("Accepted connection from: {0!r}".format(address))
                self._target(sock, address)

    def handle_hup(self):
        self.close()

    def handle_err(self):
        self.close()
        raise PyXMPPIOError("Unhandled error on socket")

    def handle_nval(self):
        self.close()

# Path: pyxmpp2/mainloop/interfaces.py
# class IOHandler:
#     """Wrapper for a socket or a file descriptor to be used in event loop
#     or for I/O threads."""
#     # pylint: disable-msg=W0232,R0921
#     __metaclass__ = ABCMeta
# 
#     @abstractmethod
#     def fileno(self):
#         """Return file descriptor to poll or select."""
#         return None
# 
#     @abstractmethod
#     def is_readable(self):
#         """
#         :Return: `True` when the I/O channel can be read
#         """
#         return False
# 
#     @abstractmethod
#     def wait_for_readability(self):
#         """
#         Stop current thread until the channel is readable.
# 
#         :Return: `False` if it won't be readable (e.g. is closed)
#         """
#         return False
# 
#     @abstractmethod
#     def is_writable(self):
#         """
#         :Return: `True` when the I/O channel can be written to
#         """
#         return False
# 
#     @abstractmethod
#     def prepare(self):
#         """
#         Prepare the I/O handler for the event loop or an event loop
#         iteration.
# 
#         :Return: `HandlerReady()` if there is no need to call `prepare` again
#             or `PrepareAgain()` otherwise.
#         :Returntype: `IOHandlerPrepareResult`
#         """
#         return HandlerReady()
# 
#     @abstractmethod
#     def wait_for_writability(self):
#         """
#         Stop current thread until the channel is writable.
# 
#         :Return: `False` if it won't be readable (e.g. is closed)
#         """
#         return False
# 
#     @abstractmethod
#     def handle_write(self):
#         """
#         Handle the 'channel writable' state. E.g. send buffered data via a
#         socket.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_read(self):
#         """
#         Handle the 'channel readable' state. E.g. read from a socket.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_hup(self):
#         """
#         Handle the 'channel hungup' state. The handler should not be writable
#         after this.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_err(self):
#         """
#         Handle an error reported.
#         """
#         pass
# 
#     @abstractmethod
#     def handle_nval(self):
#         """
#         Handle an 'invalid file descriptor' event.
#         """
#         pass
# 
#     @abstractmethod
#     def close(self):
#         """Close the channell immediately, so it won't expect more events."""
#         pass
# 
# class HandlerReady(IOHandlerPrepareResult):
#     """Returned by the `IOHandler.prepare` method
#     when the object is ready to handle I/O events and doesn't need further
#     calls to the `IOHandler.prepare` method.
#     """
#     # pylint: disable-msg=R0903
#     def __repr__(self):
#         return "HandlerReady()"
# 
# Path: pyxmpp2/exceptions.py
# class PyXMPPIOError(Error):
#     """Exception raised on I/O error."""
#     pass
# 
# Path: pyxmpp2/transport.py
# BLOCKING_ERRORS = set()


# Path: pyxmpp2/server/listener.py
import threading
import socket
import logging
    from socket import SOMAXCONN
from ..mainloop.interfaces import IOHandler, HandlerReady
from ..exceptions import PyXMPPIOError
from ..transport import BLOCKING_ERRORS

        return

    def handle_read(self):
        """
        Accept any incoming connections.
        """
        with self._lock:
            logger.debug("handle_read()")
            if self._socket is None:
                return
            while True:
                try:
                    sock, address = self._socket.accept()
                except socket.error, err:
                    if err.args[0] in BLOCKING_ERRORS:
                        break
                    else:
                        raise
                logger.debug("Accepted connection from: {0!r}".format(address))
                self._target(sock, address)

    def handle_hup(self):
        self.close()

    def handle_err(self):
        self.close()
        raise PyXMPPIOError("Unhandled error on socket")

    def handle_nval(self):
        self.close()

        raise PyXMPPIOError("Invalid file descriptor used in main event loop")