# 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
                break
        self._add_io_state(self.io_loop.READ)

    def read_until_close(self, callback, streaming_callback=None):
        """Reads all data from the socket until it is closed.

        If a ``streaming_callback`` is given, it will be called with chunks
        of data as they become available, and the argument to the final
        ``callback`` will be empty.

        Subject to ``max_buffer_size`` limit from `IOStream` constructor if
        a ``streaming_callback`` is not used.
        """
        assert not self._read_callback, "Already reading"
        if self.closed():
            self._run_callback(callback, self._consume(self._read_buffer_size))
            return
        self._read_until_close = True
        self._read_callback = stack_context.wrap(callback)
        self._streaming_callback = stack_context.wrap(streaming_callback)
        self._add_io_state(self.io_loop.READ)

    def write(self, data, callback=None):
        """Write the given data to this stream.

        If callback is given, we call it when all of the buffered write
        data has been successfully written to the stream. If there was
        previously buffered write data and an old write callback, that
        callback is simply overwritten with this new callback.
        """

# 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

                break
        self._add_io_state(self.io_loop.READ)

    def read_until_close(self, callback, streaming_callback=None):
        """Reads all data from the socket until it is closed.

        If a ``streaming_callback`` is given, it will be called with chunks
        of data as they become available, and the argument to the final
        ``callback`` will be empty.

        Subject to ``max_buffer_size`` limit from `IOStream` constructor if
        a ``streaming_callback`` is not used.
        """
        assert not self._read_callback, "Already reading"
        if self.closed():
            self._run_callback(callback, self._consume(self._read_buffer_size))
            return
        self._read_until_close = True
        self._read_callback = stack_context.wrap(callback)
        self._streaming_callback = stack_context.wrap(streaming_callback)
        self._add_io_state(self.io_loop.READ)

    def write(self, data, callback=None):
        """Write the given data to this stream.

        If callback is given, we call it when all of the buffered write
        data has been successfully written to the stream. If there was
        previously buffered write data and an old write callback, that
        callback is simply overwritten with this new callback.
        """

        assert isinstance(data, bytes_type)