# Path: jega/ext/jsocket.py
#     EBADF = 9
# SOCKETMETHODS = ('setblocking', 'bind', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt')
#     _GLOBAL_DEFAULT_TIMEOUT = __socket__._GLOBAL_DEFAULT_TIMEOUT
#     _GLOBAL_DEFAULT_TIMEOUT = object()
#     class _realsocket(_socket.socket):
#     class _fileobject:
# class _closedsocket(object):
#     class socket(object):
#     class socket(object):
#         def __init__(self, sock, mode='rwb', bufsize=-1, close=False):
#         def closed(self):
#         def __del__(self):
#         def close(self):
#     def inet_ntop(address_family, packed_ip):
# def wait_read(fileno, timeout=None, timeout_exc=timeout):
# def wait_write(fileno, timeout=None, timeout_exc=timeout):
# def wait_readwrite(fileno, timeout=None, timeout_exc=timeout):
#     def _get_memory(string, offset):
#     def _dummy(*args):
# def internal_accept(s):
# def internal_close(s):
# def internal_connect(s, address):
# def internal_connect_ex(s, address):
# def internal_recv(s, *args):
# def internal_recvfrom(s, *args):
# def internal_recvfrom_into(s, *args):
# def internal_recv_into(s, *args):
# def internal_send(s, *args):
#     def internal_sendall(s, data, flags=0):
#     def internal_sendall(s, data, flags=0):
# def internal_sendto(s, *args):
# def internal_settimeout(s, howlong):
# def internal_gettimeout(s):
# def internal_shutdown(s, how):
#         def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
#         def __enter__(self):
#         def __exit__(self, *args):
#         def dup(self):
#         def _decref_socketios(self):
#         def _real_close(self, _ss=_socket.socket):
#         def close(self):
#         def detach(self):
#         def accept_block(self):
#         def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
#         def __repr__(self):
#         def __str__(self):
#         def _formatinfo(self):
#         def __enter__(self):
#         def __exit__(self, *args):
#         def dup(self):
#         def makefile(self, mode='r', bufsize=-1):
#         def accept_block(self):
#     def socketpair(*args):
#     def fromfd(fd, family, type, proto=0):
#         def fromfd(*args):
# def getfqdn(name=''):
# def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None):
#     def ssl(sock, certificate=None, private_key=None):
# 
# Path: jega/loop.py
# _MAX_WORKERS = 5
# def _raise_stop_error(*args):
#     def __init__(self):
#     def reset(self):
#     def add_signal_handler(self, sig, callback, *args):
#     def _handle_signal(self, sig, arg):
#     def remove_signal_handler(self, sig):
#     def _check_signal(self, sig):
#     def _socketpair(self):
#     def _close_self_pipe(self):
#     def _make_self_pipe(self):
#     def _read_from_self(self):
#     def _write_to_self(self):
#     def destroy(self):
#     def wrap_future(self, future):
#     def run(self):
#     def run_once(self):
#     def run_forever(self):
#     def run_until_complete(self, future, timeout=None):
#     def stop(self):
#     def call_soon_threadsafe(self, callback, *args):
#     def run_in_executor(self, executor, callback, *args):
#     def set_default_executor(self, executor):
#     def getaddrinfo(self, host, port, family=0, type=0, proto=0, flags=0):
#     def getnameinfo(self, sockaddr, flags=0):
#     def _add_callback_signalsafe(self, handle):
#     def set_socket_acceptor(self, sock, acceptor):
# def internal_acceptor(accept, acceptor):
# def get_event_loop():
# def spawn(cb, *args):
# class JegaEventLoop(jega.AbstractEventLoop):


from pytest import *
from jega.ext import jsocket
from jega import loop
from util import *
import socket
import jega

HOST = "bitbucket.org"
PORT = 80
HOST_IPS = ["131.103.20.167", "131.103.20.168"]
LISTEN_PORT = 8080

# @check_stop
def test_accept_timeout():
    print_name()
    with raises(jsocket.timeout):
        s = jsocket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.setsockopt(jsocket.SOL_SOCKET, jsocket.SO_REUSEADDR, 1)
        s.bind(("", LISTEN_PORT))
        s.listen(1)
        s.settimeout(2)
        result = s.accept()

# @check_stop
def test_accept():
    print_name()
    

# Path: jega/ext/jsocket.py
#     EBADF = 9
# SOCKETMETHODS = ('setblocking', 'bind', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt')
#     _GLOBAL_DEFAULT_TIMEOUT = __socket__._GLOBAL_DEFAULT_TIMEOUT
#     _GLOBAL_DEFAULT_TIMEOUT = object()
#     class _realsocket(_socket.socket):
#     class _fileobject:
# class _closedsocket(object):
#     class socket(object):
#     class socket(object):
#         def __init__(self, sock, mode='rwb', bufsize=-1, close=False):
#         def closed(self):
#         def __del__(self):
#         def close(self):
#     def inet_ntop(address_family, packed_ip):
# def wait_read(fileno, timeout=None, timeout_exc=timeout):
# def wait_write(fileno, timeout=None, timeout_exc=timeout):
# def wait_readwrite(fileno, timeout=None, timeout_exc=timeout):
#     def _get_memory(string, offset):
#     def _dummy(*args):
# def internal_accept(s):
# def internal_close(s):
# def internal_connect(s, address):
# def internal_connect_ex(s, address):
# def internal_recv(s, *args):
# def internal_recvfrom(s, *args):
# def internal_recvfrom_into(s, *args):
# def internal_recv_into(s, *args):
# def internal_send(s, *args):
#     def internal_sendall(s, data, flags=0):
#     def internal_sendall(s, data, flags=0):
# def internal_sendto(s, *args):
# def internal_settimeout(s, howlong):
# def internal_gettimeout(s):
# def internal_shutdown(s, how):
#         def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
#         def __enter__(self):
#         def __exit__(self, *args):
#         def dup(self):
#         def _decref_socketios(self):
#         def _real_close(self, _ss=_socket.socket):
#         def close(self):
#         def detach(self):
#         def accept_block(self):
#         def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
#         def __repr__(self):
#         def __str__(self):
#         def _formatinfo(self):
#         def __enter__(self):
#         def __exit__(self, *args):
#         def dup(self):
#         def makefile(self, mode='r', bufsize=-1):
#         def accept_block(self):
#     def socketpair(*args):
#     def fromfd(fd, family, type, proto=0):
#         def fromfd(*args):
# def getfqdn(name=''):
# def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None):
#     def ssl(sock, certificate=None, private_key=None):
# 
# Path: jega/loop.py
# _MAX_WORKERS = 5
# def _raise_stop_error(*args):
#     def __init__(self):
#     def reset(self):
#     def add_signal_handler(self, sig, callback, *args):
#     def _handle_signal(self, sig, arg):
#     def remove_signal_handler(self, sig):
#     def _check_signal(self, sig):
#     def _socketpair(self):
#     def _close_self_pipe(self):
#     def _make_self_pipe(self):
#     def _read_from_self(self):
#     def _write_to_self(self):
#     def destroy(self):
#     def wrap_future(self, future):
#     def run(self):
#     def run_once(self):
#     def run_forever(self):
#     def run_until_complete(self, future, timeout=None):
#     def stop(self):
#     def call_soon_threadsafe(self, callback, *args):
#     def run_in_executor(self, executor, callback, *args):
#     def set_default_executor(self, executor):
#     def getaddrinfo(self, host, port, family=0, type=0, proto=0, flags=0):
#     def getnameinfo(self, sockaddr, flags=0):
#     def _add_callback_signalsafe(self, handle):
#     def set_socket_acceptor(self, sock, acceptor):
# def internal_acceptor(accept, acceptor):
# def get_event_loop():
# def spawn(cb, *args):
# class JegaEventLoop(jega.AbstractEventLoop):


# Path: tests/test_socket.py
from pytest import *
from jega.ext import jsocket
from jega import loop
from util import *
import socket
import jega


HOST = "bitbucket.org"
PORT = 80
HOST_IPS = ["131.103.20.167", "131.103.20.168"]
LISTEN_PORT = 8080

# @check_stop
def test_accept_timeout():
    print_name()
    with raises(jsocket.timeout):
        s = jsocket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.setsockopt(jsocket.SOL_SOCKET, jsocket.SO_REUSEADDR, 1)
        s.bind(("", LISTEN_PORT))
        s.listen(1)
        s.settimeout(2)
        result = s.accept()

# @check_stop
def test_accept():
    print_name()
    

    event_loop = loop.get_event_loop()