# Path: tornado/ioloop.py
# class IOLoop(object):
# class _Timeout(object):
# class PeriodicCallback(object):
# class _EPoll(object):
# class _KQueue(object):
# class _Select(object):
#     _EPOLLIN = 0x001
#     _EPOLLPRI = 0x002
#     _EPOLLOUT = 0x004
#     _EPOLLERR = 0x008
#     _EPOLLHUP = 0x010
#     _EPOLLRDHUP = 0x2000
#     _EPOLLONESHOT = (1 << 30)
#     _EPOLLET = (1 << 31)
#     NONE = 0
#     READ = _EPOLLIN
#     WRITE = _EPOLLOUT
#     ERROR = _EPOLLERR | _EPOLLHUP | _EPOLLRDHUP
#     _EPOLL_CTL_ADD = 1
#     _EPOLL_CTL_DEL = 2
#     _EPOLL_CTL_MOD = 3
#     def __init__(self, impl=None):
#     def instance():
#     def initialized():
#     def install(self):
#     def close(self, all_fds=False):
#     def add_handler(self, fd, handler, events):
#     def update_handler(self, fd, events):
#     def remove_handler(self, fd):
#     def set_blocking_signal_threshold(self, seconds, action):
#     def set_blocking_log_threshold(self, seconds):
#     def log_stack(self, signal, frame):
#     def start(self):
#     def stop(self):
#     def running(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def __init__(self, deadline, callback):
#     def timedelta_to_seconds(td):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __init__(self, callback, callback_time, io_loop=None):
#     def start(self):
#     def stop(self):
#     def _run(self):
#     def _schedule_next(self):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def _control(self, fd, events, flags):
#     def poll(self, timeout):
#     def __init__(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
# 
# Path: tornado/stack_context.py
# class _State(threading.local):
# class StackContext(object):
# class ExceptionStackContext(object):
# class NullContext(object):
# class _StackContextWrapper(functools.partial):
#     def __init__(self):
#     def __init__(self, context_factory):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(callback, contexts, *args, **kwargs):
# def _nested(*managers):
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


import collections
import errno
import logging
import socket
import sys
import re
    import ssl # Python 2.6+
    import doctest
from tornado import ioloop
from tornado import stack_context
from tornado.util import b, bytes_type
        self._streaming_callback = None
        self._write_callback = None
        self._close_callback = None
        self._connect_callback = None
        self._connecting = False
        self._state = None
        self._pending_callbacks = 0

    def connect(self, address, callback=None):
        """Connects the socket to a remote address without blocking.

        May only be called if the socket passed to the constructor was
        not previously connected.  The address parameter is in the
        same format as for socket.connect, i.e. a (host, port) tuple.
        If callback is specified, it will be called when the
        connection is completed.

        Note that it is safe to call IOStream.write while the
        connection is pending, in which case the data will be written
        as soon as the connection is ready.  Calling IOStream read
        methods before the socket is connected works on some platforms
        but is non-portable.
        """
        self._connecting = True
        try:
            self.socket.connect(address)
        except socket.error, e:
            # In non-blocking mode connect() always raises an exception
            if e.args[0] not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
                raise

# Path: tornado/ioloop.py
# class IOLoop(object):
# class _Timeout(object):
# class PeriodicCallback(object):
# class _EPoll(object):
# class _KQueue(object):
# class _Select(object):
#     _EPOLLIN = 0x001
#     _EPOLLPRI = 0x002
#     _EPOLLOUT = 0x004
#     _EPOLLERR = 0x008
#     _EPOLLHUP = 0x010
#     _EPOLLRDHUP = 0x2000
#     _EPOLLONESHOT = (1 << 30)
#     _EPOLLET = (1 << 31)
#     NONE = 0
#     READ = _EPOLLIN
#     WRITE = _EPOLLOUT
#     ERROR = _EPOLLERR | _EPOLLHUP | _EPOLLRDHUP
#     _EPOLL_CTL_ADD = 1
#     _EPOLL_CTL_DEL = 2
#     _EPOLL_CTL_MOD = 3
#     def __init__(self, impl=None):
#     def instance():
#     def initialized():
#     def install(self):
#     def close(self, all_fds=False):
#     def add_handler(self, fd, handler, events):
#     def update_handler(self, fd, events):
#     def remove_handler(self, fd):
#     def set_blocking_signal_threshold(self, seconds, action):
#     def set_blocking_log_threshold(self, seconds):
#     def log_stack(self, signal, frame):
#     def start(self):
#     def stop(self):
#     def running(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def __init__(self, deadline, callback):
#     def timedelta_to_seconds(td):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __init__(self, callback, callback_time, io_loop=None):
#     def start(self):
#     def stop(self):
#     def _run(self):
#     def _schedule_next(self):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def _control(self, fd, events, flags):
#     def poll(self, timeout):
#     def __init__(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
# 
# Path: tornado/stack_context.py
# class _State(threading.local):
# class StackContext(object):
# class ExceptionStackContext(object):
# class NullContext(object):
# class _StackContextWrapper(functools.partial):
#     def __init__(self):
#     def __init__(self, context_factory):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(callback, contexts, *args, **kwargs):
# def _nested(*managers):
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


# Path: tornado/iostream.py
import collections
import errno
import logging
import socket
import sys
import re
    import ssl # Python 2.6+
    import doctest
from tornado import ioloop
from tornado import stack_context
from tornado.util import b, bytes_type

        self._streaming_callback = None
        self._write_callback = None
        self._close_callback = None
        self._connect_callback = None
        self._connecting = False
        self._state = None
        self._pending_callbacks = 0

    def connect(self, address, callback=None):
        """Connects the socket to a remote address without blocking.

        May only be called if the socket passed to the constructor was
        not previously connected.  The address parameter is in the
        same format as for socket.connect, i.e. a (host, port) tuple.
        If callback is specified, it will be called when the
        connection is completed.

        Note that it is safe to call IOStream.write while the
        connection is pending, in which case the data will be written
        as soon as the connection is ready.  Calling IOStream read
        methods before the socket is connected works on some platforms
        but is non-portable.
        """
        self._connecting = True
        try:
            self.socket.connect(address)
        except socket.error, e:
            # In non-blocking mode connect() always raises an exception
            if e.args[0] not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
                raise

        self._connect_callback = stack_context.wrap(callback)