# Path: stator/lib.py

# 
# Path: stator/util.py
# def convert_ip(host):
#     match = IP_ADDRESS_RE.match(host)
#     if not match:
#         raise ValueError(
#             "Ip address string required, got {!r}".format(host))
#     parts = list(map(int, match.groups()))
#     if any(p > 255 for p in parts):
#         raise ValueError(
#             "Ip address string required, got {!r}".format(host))
#     return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]
# 
# Path: stator/loop.py
# class Socket(object):
# 
#     def __init__(self, id):
#         assert isinstance(id, INT_TYPES), (type(id), id)
#         self.id = id
#         TABLE.add(self)
# 
#     def close(self):
#         TABLE.remove(self.id)
# 
#     def parse_message(self, input):
#         raise RuntimeError("abstract method")
# 
#     def __repr__(self):
#         return '<{} {}>'.format(self.__class__.__name__,
#             repr(self.__dict__)[1:-1])


import sys
import cbor
from  ctypes import c_uint64, c_uint32, c_uint16, c_ssize_t, c_char_p
from  ctypes import c_size_t, c_uint64, c_int64, c_double, c_void_p
from .lib import dll
from .util import convert_ip
from .loop import Socket
dll.stator_http_reply.argtypes = [c_uint64, c_void_p, c_size_t]
dll.stator_http_reply.restype = None


if sys.version_info < (3, 0):
    UNICODE_TYPE = unicode
else:
    UNICODE_TYPE = str


class CantBindAddress(Exception):
    pass


class HttpRequest(Socket):

    def __init__(self, id, dic):
        super(HttpRequest, self).__init__(id)
        self.__dict__.update(dic)

    def reply(self, status, headers, body):
        assert 200 <= status[0] <= 599, status
        assert isinstance(status[1], UNICODE_TYPE), status
        assert isinstance(headers, dict), headers
        assert isinstance(body, bytes), body
        data = cbor.dumps([status, headers, body])
        dll.stator_http_reply(self.id, data, len(data))
        self.close()



# Path: stator/lib.py

# 
# Path: stator/util.py
# def convert_ip(host):
#     match = IP_ADDRESS_RE.match(host)
#     if not match:
#         raise ValueError(
#             "Ip address string required, got {!r}".format(host))
#     parts = list(map(int, match.groups()))
#     if any(p > 255 for p in parts):
#         raise ValueError(
#             "Ip address string required, got {!r}".format(host))
#     return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]
# 
# Path: stator/loop.py
# class Socket(object):
# 
#     def __init__(self, id):
#         assert isinstance(id, INT_TYPES), (type(id), id)
#         self.id = id
#         TABLE.add(self)
# 
#     def close(self):
#         TABLE.remove(self.id)
# 
#     def parse_message(self, input):
#         raise RuntimeError("abstract method")
# 
#     def __repr__(self):
#         return '<{} {}>'.format(self.__class__.__name__,
#             repr(self.__dict__)[1:-1])


# Path: stator/http.py
import sys
import cbor
from  ctypes import c_uint64, c_uint32, c_uint16, c_ssize_t, c_char_p
from  ctypes import c_size_t, c_uint64, c_int64, c_double, c_void_p
from .lib import dll
from .util import convert_ip
from .loop import Socket

dll.stator_http_reply.argtypes = [c_uint64, c_void_p, c_size_t]
dll.stator_http_reply.restype = None


if sys.version_info < (3, 0):
    UNICODE_TYPE = unicode
else:
    UNICODE_TYPE = str


class CantBindAddress(Exception):
    pass


class HttpRequest(Socket):

    def __init__(self, id, dic):
        super(HttpRequest, self).__init__(id)
        self.__dict__.update(dic)

    def reply(self, status, headers, body):
        assert 200 <= status[0] <= 599, status
        assert isinstance(status[1], UNICODE_TYPE), status
        assert isinstance(headers, dict), headers
        assert isinstance(body, bytes), body
        data = cbor.dumps([status, headers, body])
        dll.stator_http_reply(self.id, data, len(data))
        self.close()



class Http(Socket):