# Path: tests/moto_server.py
# _PYCHARM_HOSTED = os.environ.get('PYCHARM_HOSTED') == '1'
# _CONNECT_TIMEOUT = 90 if _PYCHARM_HOSTED else 10
# def get_free_tcp_port(release_socket: bool = False):
#     def __init__(self, service_name: str, port: int = None):
#     def endpoint_url(self):
#     def __call__(self, func):
#         async def wrapper(*args, **kwargs):
#     async def __aenter__(self):
#     async def __aexit__(self, exc_type, exc_val, exc_tb):
#     def _server_entry(self):
#     async def _start(self):
#     async def _stop(self):
# class MotoService:


import asyncio
import multiprocessing
import aiohttp
import aiohttp.web
import pytest
from aiohttp.web import StreamResponse
from tests.moto_server import host, MotoService, get_free_tcp_port

_proxy_bypass = {
  "http": None,
  "https": None,
}


# This runs in a subprocess for a variety of reasons
# 1) early versions of python 3.5 did not correctly set one thread per run loop
# 2) aiohttp uses get_event_loop instead of using the passed in run loop
# 3) aiohttp shutdown can be hairy
class AIOServer(multiprocessing.Process):
    """
    This is a mock AWS service which will 5 seconds before returning
    a response to test socket timeouts.
    """
    def __init__(self):
        super().__init__(target=self._run)
        self._loop = None
        self._port = get_free_tcp_port(True)
        self.endpoint_url = f'http://{host}:{self._port}'
        self.daemon = True  # die when parent dies

    def _run(self):
        asyncio.set_event_loop(asyncio.new_event_loop())
        app = aiohttp.web.Application()
        app.router.add_route('*', '/ok', self.ok)
        app.router.add_route('*', '/{anything:.*}', self.stream_handler)

        try:

# Path: tests/moto_server.py
# _PYCHARM_HOSTED = os.environ.get('PYCHARM_HOSTED') == '1'
# _CONNECT_TIMEOUT = 90 if _PYCHARM_HOSTED else 10
# def get_free_tcp_port(release_socket: bool = False):
#     def __init__(self, service_name: str, port: int = None):
#     def endpoint_url(self):
#     def __call__(self, func):
#         async def wrapper(*args, **kwargs):
#     async def __aenter__(self):
#     async def __aexit__(self, exc_type, exc_val, exc_tb):
#     def _server_entry(self):
#     async def _start(self):
#     async def _stop(self):
# class MotoService:


# Path: tests/mock_server.py
import asyncio
import multiprocessing
import aiohttp
import aiohttp.web
import pytest
from aiohttp.web import StreamResponse
from tests.moto_server import host, MotoService, get_free_tcp_port


_proxy_bypass = {
  "http": None,
  "https": None,
}


# This runs in a subprocess for a variety of reasons
# 1) early versions of python 3.5 did not correctly set one thread per run loop
# 2) aiohttp uses get_event_loop instead of using the passed in run loop
# 3) aiohttp shutdown can be hairy
class AIOServer(multiprocessing.Process):
    """
    This is a mock AWS service which will 5 seconds before returning
    a response to test socket timeouts.
    """
    def __init__(self):
        super().__init__(target=self._run)
        self._loop = None
        self._port = get_free_tcp_port(True)
        self.endpoint_url = f'http://{host}:{self._port}'
        self.daemon = True  # die when parent dies

    def _run(self):
        asyncio.set_event_loop(asyncio.new_event_loop())
        app = aiohttp.web.Application()
        app.router.add_route('*', '/ok', self.ok)
        app.router.add_route('*', '/{anything:.*}', self.stream_handler)

        try:

            aiohttp.web.run_app(app, host=host, port=self._port,