# Path: server/websockets/compatibility.py

# 
# Path: server/websockets/exceptions.py
# class ConnectionClosed(InvalidState):
#     """
#     Exception raised when trying to read or write on a closed connection.
# 
#     Provides the connection close code and reason in its ``code`` and
#     ``reason`` attributes respectively.
# 
#     """
#     def __init__(self, code, reason):
#         self.code = code
#         self.reason = reason
#         message = 'WebSocket connection is closed: '
#         message += 'code = {}, '.format(code) if code else 'no code, '
#         message += 'reason = {}.'.format(reason) if reason else 'no reason.'
#         super().__init__(message)
# 
# class InvalidState(Exception):
#     """
#     Exception raised when an operation is forbidden in the current state.
# 
#     """
# 
# Path: server/websockets/protocol.py
# CONNECTING, OPEN, CLOSING, CLOSED = range(4)
# class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
#     def __init__(self, *,
#                  host=None, port=None, secure=None,
#                  timeout=10, max_size=2 ** 20, max_queue=2 ** 5,
#                  loop=None, legacy_recv=False):
#     def local_address(self):
#     def remote_address(self):
#     def open(self):
#     def state_name(self):
#     def close(self, code=1000, reason=''):
#     def recv(self):
#     def send(self, data):
#     def ping(self, data=None):
#     def pong(self, data=b''):
#     def encode_data(self, data):
#     def ensure_open(self):
#     def run(self):
#     def read_message(self):
#                 def append(frame):
#                 def append(frame):
#                 def append(frame):
#                 def append(frame):
#     def read_data_frame(self, max_size):
#     def read_frame(self, max_size):
#     def write_frame(self, opcode, data=b''):
#     def close_connection(self, force=False):
#     def fail_connection(self, code=1011, reason=''):
#     def client_connected(self, reader, writer):
#     def eof_received(self):
#     def connection_lost(self, exc):


import asyncio
import contextlib
import functools
import os
import time
import unittest
import unittest.mock
from .compatibility import asyncio_ensure_future
from .exceptions import ConnectionClosed, InvalidState
from .framing import *
from .protocol import CLOSED, CONNECTING, WebSocketCommonProtocol



# Unit for timeouts. May be increased on slow machines by setting the
# WEBSOCKETS_TESTS_TIMEOUT_FACTOR environment variable.
MS = 0.001 * int(os.environ.get('WEBSOCKETS_TESTS_TIMEOUT_FACTOR', 1))

# asyncio's debug mode has a 10x performance penalty for this test suite.
if os.environ.get('PYTHONASYNCIODEBUG'):                    # pragma: no cover
    MS *= 10

# Ensure that timeouts are larger than the clock's resolution (for Windows).
MS = max(MS, 2.5 * time.get_clock_info('monotonic').resolution)



# Path: server/websockets/compatibility.py

# 
# Path: server/websockets/exceptions.py
# class ConnectionClosed(InvalidState):
#     """
#     Exception raised when trying to read or write on a closed connection.
# 
#     Provides the connection close code and reason in its ``code`` and
#     ``reason`` attributes respectively.
# 
#     """
#     def __init__(self, code, reason):
#         self.code = code
#         self.reason = reason
#         message = 'WebSocket connection is closed: '
#         message += 'code = {}, '.format(code) if code else 'no code, '
#         message += 'reason = {}.'.format(reason) if reason else 'no reason.'
#         super().__init__(message)
# 
# class InvalidState(Exception):
#     """
#     Exception raised when an operation is forbidden in the current state.
# 
#     """
# 
# Path: server/websockets/protocol.py
# CONNECTING, OPEN, CLOSING, CLOSED = range(4)
# class WebSocketCommonProtocol(asyncio.StreamReaderProtocol):
#     def __init__(self, *,
#                  host=None, port=None, secure=None,
#                  timeout=10, max_size=2 ** 20, max_queue=2 ** 5,
#                  loop=None, legacy_recv=False):
#     def local_address(self):
#     def remote_address(self):
#     def open(self):
#     def state_name(self):
#     def close(self, code=1000, reason=''):
#     def recv(self):
#     def send(self, data):
#     def ping(self, data=None):
#     def pong(self, data=b''):
#     def encode_data(self, data):
#     def ensure_open(self):
#     def run(self):
#     def read_message(self):
#                 def append(frame):
#                 def append(frame):
#                 def append(frame):
#                 def append(frame):
#     def read_data_frame(self, max_size):
#     def read_frame(self, max_size):
#     def write_frame(self, opcode, data=b''):
#     def close_connection(self, force=False):
#     def fail_connection(self, code=1011, reason=''):
#     def client_connected(self, reader, writer):
#     def eof_received(self):
#     def connection_lost(self, exc):


# Path: server/websockets/test_protocol.py
import asyncio
import contextlib
import functools
import os
import time
import unittest
import unittest.mock
from .compatibility import asyncio_ensure_future
from .exceptions import ConnectionClosed, InvalidState
from .framing import *
from .protocol import CLOSED, CONNECTING, WebSocketCommonProtocol




# Unit for timeouts. May be increased on slow machines by setting the
# WEBSOCKETS_TESTS_TIMEOUT_FACTOR environment variable.
MS = 0.001 * int(os.environ.get('WEBSOCKETS_TESTS_TIMEOUT_FACTOR', 1))

# asyncio's debug mode has a 10x performance penalty for this test suite.
if os.environ.get('PYTHONASYNCIODEBUG'):                    # pragma: no cover
    MS *= 10

# Ensure that timeouts are larger than the clock's resolution (for Windows).
MS = max(MS, 2.5 * time.get_clock_info('monotonic').resolution)



class TransportMock(unittest.mock.Mock):