# Path: mamba/web/websocket.py
# DATA, CLOSE, PING, PONG = range(4)                    # frame control
# HYBI00, HYBI07, HYBI10, RFC6455 = range(4)            # supported versions
# HANDSHAKE, NEGOTIATION, CHALLENGE, FRAMES = range(4)  # state machine.
# NORMAL_CLOSURE = 0x3e8
# class WebSocketError(Exception):
# class InvalidProtocol(WebSocketError):
# class NoWebSocketCodec(WebSocketError):
# class InvalidProtocolVersion(WebSocketError):
# class InvalidCharacterInHyBi00Frame(WebSocketError):
# class ReservedFlagsInFrame(WebSocketError):
# class UnknownFrameOpcode(WebSocketError):
# class HandshakePreamble(object):
# class HyBi00HandshakePreamble(HandshakePreamble):
# class HyBi07HandshakePreamble(HandshakePreamble):
# class InvalidProtocolVersionPreamble(HandshakePreamble):
# class HyBi00Frame(object):
# class HyBi07Frame(object):
# class WebSocketProtocol(ProtocolWrapper):
# class WebSocketFactory(WrappingFactory):
#     def __init__(self):
#     def write_to_transport(self, transport):
#     def __init__(self, protocol):
#     def write_to_transport(self, transport, response):
#     def __init__(self, protocol):
#     def generate_accept_opening(self, protocol):
#     def __init__(self):
#     def __init__(self, buf):
#     def is_valid(self):
#     def generate(self, opcode=0x00):
#     def parse(self):
#     def __init__(self, buf):
#     def generate(self, opcode=0x1):
#     def parse(self):
#     def mask(self, buf, key):
#     def __init__(self, *args, **kwargs):
#     def secure(self):
#     def codecs(self):
#     def is_hybi00(self):
#     def dataReceived(self, data):
#     def handle_handshake(self):
#     def handle_negotiation(self):
#     def handle_challenge(self):
#     def handle_frames(self):
#     def write(self, data):
#     def writeSequence(self, data):
#     def _send(self, binary=False):
#     def close(self, reason=''):
#     def complete_hybi00(self, challenge):
#     def parse_headers(self, headers):


import hashlib
from twisted.trial import unittest
from twisted.internet import address, task
from twisted.web.http import datetimeToString
from twisted.test import test_policies, proto_helpers
from mamba.web import websocket
        from string import digits
        from struct import pack
        from hashlib import md5

        fr, buf = websocket.HyBi07Frame('\x89\x0eLEMOOOOOOOOOON').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.PING, "LEMOOOOOOOOOON"))
        self.assertEqual(buf, '')

    def test_parse_pong(self):

        fr, buf = websocket.HyBi07Frame('\x8a\x0eLEMOOOOOOOOOON').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.PONG, "LEMOOOOOOOOOON"))
        self.assertEqual(buf, '')

    def test_parse_close_empty(self):

        fr, buf = websocket.HyBi07Frame('\x88\x00').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.CLOSE, (1000, 'No reason given')))
        self.assertEqual(buf, '')

    def test_parse_close_reason(self):

        frame = '\x88\x10\x03\xe8LEMOOOOOOOOOON'
        fr, buf = websocket.HyBi07Frame(frame).parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.CLOSE, (1000, 'LEMOOOOOOOOOON')))
        self.assertEqual(buf, '')

    def test_parse_partial_no_length(self):


# Path: mamba/web/websocket.py
# DATA, CLOSE, PING, PONG = range(4)                    # frame control
# HYBI00, HYBI07, HYBI10, RFC6455 = range(4)            # supported versions
# HANDSHAKE, NEGOTIATION, CHALLENGE, FRAMES = range(4)  # state machine.
# NORMAL_CLOSURE = 0x3e8
# class WebSocketError(Exception):
# class InvalidProtocol(WebSocketError):
# class NoWebSocketCodec(WebSocketError):
# class InvalidProtocolVersion(WebSocketError):
# class InvalidCharacterInHyBi00Frame(WebSocketError):
# class ReservedFlagsInFrame(WebSocketError):
# class UnknownFrameOpcode(WebSocketError):
# class HandshakePreamble(object):
# class HyBi00HandshakePreamble(HandshakePreamble):
# class HyBi07HandshakePreamble(HandshakePreamble):
# class InvalidProtocolVersionPreamble(HandshakePreamble):
# class HyBi00Frame(object):
# class HyBi07Frame(object):
# class WebSocketProtocol(ProtocolWrapper):
# class WebSocketFactory(WrappingFactory):
#     def __init__(self):
#     def write_to_transport(self, transport):
#     def __init__(self, protocol):
#     def write_to_transport(self, transport, response):
#     def __init__(self, protocol):
#     def generate_accept_opening(self, protocol):
#     def __init__(self):
#     def __init__(self, buf):
#     def is_valid(self):
#     def generate(self, opcode=0x00):
#     def parse(self):
#     def __init__(self, buf):
#     def generate(self, opcode=0x1):
#     def parse(self):
#     def mask(self, buf, key):
#     def __init__(self, *args, **kwargs):
#     def secure(self):
#     def codecs(self):
#     def is_hybi00(self):
#     def dataReceived(self, data):
#     def handle_handshake(self):
#     def handle_negotiation(self):
#     def handle_challenge(self):
#     def handle_frames(self):
#     def write(self, data):
#     def writeSequence(self, data):
#     def _send(self, binary=False):
#     def close(self, reason=''):
#     def complete_hybi00(self, challenge):
#     def parse_headers(self, headers):


# Path: mamba/test/test_websocket.py
import hashlib
from twisted.trial import unittest
from twisted.internet import address, task
from twisted.web.http import datetimeToString
from twisted.test import test_policies, proto_helpers
from mamba.web import websocket
        from string import digits
        from struct import pack
        from hashlib import md5


        fr, buf = websocket.HyBi07Frame('\x89\x0eLEMOOOOOOOOOON').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.PING, "LEMOOOOOOOOOON"))
        self.assertEqual(buf, '')

    def test_parse_pong(self):

        fr, buf = websocket.HyBi07Frame('\x8a\x0eLEMOOOOOOOOOON').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.PONG, "LEMOOOOOOOOOON"))
        self.assertEqual(buf, '')

    def test_parse_close_empty(self):

        fr, buf = websocket.HyBi07Frame('\x88\x00').parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.CLOSE, (1000, 'No reason given')))
        self.assertEqual(buf, '')

    def test_parse_close_reason(self):

        frame = '\x88\x10\x03\xe8LEMOOOOOOOOOON'
        fr, buf = websocket.HyBi07Frame(frame).parse()
        self.assertEqual(len(fr), 1)
        self.assertEqual(fr[0], (websocket.CLOSE, (1000, 'LEMOOOOOOOOOON')))
        self.assertEqual(buf, '')

    def test_parse_partial_no_length(self):


        fr, buf = websocket.HyBi07Frame('\x81').parse()