# Path: tornado/ioloop.py
# class IOLoop(Configurable):
# class PollIOLoop(IOLoop):
# class _Timeout(object):
# class PeriodicCallback(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
#         _FUTURE_TYPES = (futures.Future, DummyFuture)
#         _FUTURE_TYPES = DummyFuture
#     def instance():
#     def initialized():
#     def install(self):
#     def current():
#     def make_current(self):
#     def clear_current(self):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(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 time(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback, *args, **kwargs):
#     def add_callback_from_signal(self, callback, *args, **kwargs):
#     def add_future(self, future, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def initialize(self, impl, time_func=None):
#     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 start(self):
#     def stop(self):
#     def time(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback, *args, **kwargs):
#     def add_callback_from_signal(self, callback, *args, **kwargs):
#     def __init__(self, deadline, callback, io_loop):
#     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):
# 
# Path: tornado/log.py
# def _stderr_supports_color():
#     def __init__(self, color=True, *args, **kwargs):
#     def format(self, record):
# def enable_pretty_logging(options=None):
# def define_logging_options(options=None):
# class LogFormatter(logging.Formatter):
# 
# 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, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(*args, **kwargs):
# def _nested(*managers):
# 
# Path: tornado/util.py
# class ObjectDict(dict):
# class GzipDecompressor(object):
# class Configurable(object):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __init__(self):
#     def decompress(self, value):
#     def flush(self):
# def import_object(name):
#     def b(s):
#     def b(s):
# def raise_exc_info(exc_info):
#     def __new__(cls, **kwargs):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(self):
#     def configure(cls, impl, **kwargs):
#     def configured_class(cls):
#     def _save_configuration(cls):
#     def _restore_configuration(cls, saved):
# def doctests():


import collections
import errno
import os
import socket
import sys
import re
    import ssl  # Python 2.6+
    import doctest
from tornado import ioloop
from tornado.log import gen_log, app_log
from tornado import stack_context
from tornado.util import b, bytes_type
    from tornado.platform.posix import _set_nonblocking
                if num_bytes == 0:
                    # With OpenSSL, if we couldn't write the entire buffer,
                    # the very same string object must be used on the
                    # next call to send.  Therefore we suppress
                    # merging the write buffer after an incomplete send.
                    # A cleaner solution would be to set
                    # SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER, but this is
                    # not yet accessible from python
                    # (http://bugs.python.org/issue8240)
                    self._write_buffer_frozen = True
                    break
                self._write_buffer_frozen = False
                _merge_prefix(self._write_buffer, num_bytes)
                self._write_buffer.popleft()
            except socket.error, e:
                if e.args[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
                    self._write_buffer_frozen = True
                    break
                else:
                    gen_log.warning("Write error on %d: %s",
                                    self.fileno(), e)
                    self.close()
                    return
        if not self._write_buffer and self._write_callback:
            callback = self._write_callback
            self._write_callback = None
            self._run_callback(callback)

    def _consume(self, loc):
        if loc == 0:

# Path: tornado/ioloop.py
# class IOLoop(Configurable):
# class PollIOLoop(IOLoop):
# class _Timeout(object):
# class PeriodicCallback(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
#         _FUTURE_TYPES = (futures.Future, DummyFuture)
#         _FUTURE_TYPES = DummyFuture
#     def instance():
#     def initialized():
#     def install(self):
#     def current():
#     def make_current(self):
#     def clear_current(self):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(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 time(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback, *args, **kwargs):
#     def add_callback_from_signal(self, callback, *args, **kwargs):
#     def add_future(self, future, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def initialize(self, impl, time_func=None):
#     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 start(self):
#     def stop(self):
#     def time(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback, *args, **kwargs):
#     def add_callback_from_signal(self, callback, *args, **kwargs):
#     def __init__(self, deadline, callback, io_loop):
#     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):
# 
# Path: tornado/log.py
# def _stderr_supports_color():
#     def __init__(self, color=True, *args, **kwargs):
#     def format(self, record):
# def enable_pretty_logging(options=None):
# def define_logging_options(options=None):
# class LogFormatter(logging.Formatter):
# 
# 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, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(*args, **kwargs):
# def _nested(*managers):
# 
# Path: tornado/util.py
# class ObjectDict(dict):
# class GzipDecompressor(object):
# class Configurable(object):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __init__(self):
#     def decompress(self, value):
#     def flush(self):
# def import_object(name):
#     def b(s):
#     def b(s):
# def raise_exc_info(exc_info):
#     def __new__(cls, **kwargs):
#     def configurable_base(cls):
#     def configurable_default(cls):
#     def initialize(self):
#     def configure(cls, impl, **kwargs):
#     def configured_class(cls):
#     def _save_configuration(cls):
#     def _restore_configuration(cls, saved):
# def doctests():


# Path: tornado/iostream.py
import collections
import errno
import os
import socket
import sys
import re
    import ssl  # Python 2.6+
    import doctest
from tornado import ioloop
from tornado.log import gen_log, app_log
from tornado import stack_context
from tornado.util import b, bytes_type
    from tornado.platform.posix import _set_nonblocking

                if num_bytes == 0:
                    # With OpenSSL, if we couldn't write the entire buffer,
                    # the very same string object must be used on the
                    # next call to send.  Therefore we suppress
                    # merging the write buffer after an incomplete send.
                    # A cleaner solution would be to set
                    # SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER, but this is
                    # not yet accessible from python
                    # (http://bugs.python.org/issue8240)
                    self._write_buffer_frozen = True
                    break
                self._write_buffer_frozen = False
                _merge_prefix(self._write_buffer, num_bytes)
                self._write_buffer.popleft()
            except socket.error, e:
                if e.args[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
                    self._write_buffer_frozen = True
                    break
                else:
                    gen_log.warning("Write error on %d: %s",
                                    self.fileno(), e)
                    self.close()
                    return
        if not self._write_buffer and self._write_callback:
            callback = self._write_callback
            self._write_callback = None
            self._run_callback(callback)

    def _consume(self, loc):
        if loc == 0:

            return b("")