# 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/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 array
import functools
import hashlib
import struct
import time
import base64
import tornado.escape
import tornado.web
from tornado.log import gen_log, app_log
from tornado.util import bytes_type, b
    def _handle_challenge(self, challenge):
        try:
            challenge_response = self.challenge_response(challenge)
        except ValueError:
            gen_log.debug("Malformed key data in WebSocket request")
            self._abort()
            return
        self._write_response(challenge_response)

    def _write_response(self, challenge):
        self.stream.write(challenge)
        self.async_callback(self.handler.open)(*self.handler.open_args, **self.handler.open_kwargs)
        self._receive_message()

    def _handle_websocket_headers(self):
        """Verifies all invariant- and required headers

        If a header is missing or have an incorrect value ValueError will be
        raised
        """
        fields = ("Origin", "Host", "Sec-Websocket-Key1",
                  "Sec-Websocket-Key2")
        if not all(map(lambda f: self.request.headers.get(f), fields)):
            raise ValueError("Missing/Invalid WebSocket headers")

    def _calculate_part(self, key):
        """Processes the key headers and calculates their key value.

        Raises ValueError when feed invalid key."""
        number = int(''.join(c for c in key if c.isdigit()))

# 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/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/websocket.py
import array
import functools
import hashlib
import struct
import time
import base64
import tornado.escape
import tornado.web
from tornado.log import gen_log, app_log
from tornado.util import bytes_type, b

    def _handle_challenge(self, challenge):
        try:
            challenge_response = self.challenge_response(challenge)
        except ValueError:
            gen_log.debug("Malformed key data in WebSocket request")
            self._abort()
            return
        self._write_response(challenge_response)

    def _write_response(self, challenge):
        self.stream.write(challenge)
        self.async_callback(self.handler.open)(*self.handler.open_args, **self.handler.open_kwargs)
        self._receive_message()

    def _handle_websocket_headers(self):
        """Verifies all invariant- and required headers

        If a header is missing or have an incorrect value ValueError will be
        raised
        """
        fields = ("Origin", "Host", "Sec-Websocket-Key1",
                  "Sec-Websocket-Key2")
        if not all(map(lambda f: self.request.headers.get(f), fields)):
            raise ValueError("Missing/Invalid WebSocket headers")

    def _calculate_part(self, key):
        """Processes the key headers and calculates their key value.

        Raises ValueError when feed invalid key."""
        number = int(''.join(c for c in key if c.isdigit()))

        spaces = len([c for c in key if c.isspace()])