# 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 functools
import hashlib
import logging
import struct
import time
import base64
import tornado.escape
import tornado.web
from tornado.util import bytes_type, b
        self._frame_length = struct.unpack("!H", data)[0];
        self.stream.read_bytes(4, self._on_masking_key);
        
    def _on_frame_length_64(self, data):
        self._frame_length = struct.unpack("!Q", data)[0];
        self.stream.read_bytes(4, self._on_masking_key);

    def _on_masking_key(self, data):
        self._frame_mask = bytearray(data)
        self.stream.read_bytes(self._frame_length, self._on_frame_data)

    def _on_frame_data(self, data):
        unmasked = bytearray(data)
        for i in xrange(len(data)):
            unmasked[i] = unmasked[i] ^ self._frame_mask[i % 4]

        if not self._final_frame:
            if self._fragmented_message_buffer:
                self._fragmented_message_buffer += unmasked
            else:
                self._fragmented_message_opcode = self._frame_opcode
                self._fragmented_message_buffer = unmasked
        else:
            if self._frame_opcode == 0:
                unmasked = self._fragmented_message_buffer + unmasked
                opcode = self._fragmented_message_opcode
                self._fragmented_message_buffer = None
            else:
                opcode = self._frame_opcode


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

        self._frame_length = struct.unpack("!H", data)[0];
        self.stream.read_bytes(4, self._on_masking_key);
        
    def _on_frame_length_64(self, data):
        self._frame_length = struct.unpack("!Q", data)[0];
        self.stream.read_bytes(4, self._on_masking_key);

    def _on_masking_key(self, data):
        self._frame_mask = bytearray(data)
        self.stream.read_bytes(self._frame_length, self._on_frame_data)

    def _on_frame_data(self, data):
        unmasked = bytearray(data)
        for i in xrange(len(data)):
            unmasked[i] = unmasked[i] ^ self._frame_mask[i % 4]

        if not self._final_frame:
            if self._fragmented_message_buffer:
                self._fragmented_message_buffer += unmasked
            else:
                self._fragmented_message_opcode = self._frame_opcode
                self._fragmented_message_buffer = unmasked
        else:
            if self._frame_opcode == 0:
                unmasked = self._fragmented_message_buffer + unmasked
                opcode = self._fragmented_message_opcode
                self._fragmented_message_buffer = None
            else:
                opcode = self._frame_opcode


            self._handle_message(opcode, bytes_type(unmasked))