HTTP_STATUS_CODES = {
    100:    'Continue',
    101:    'Switching Protocols',
    102:    'Processing',
    200:    'OK',
    201:    'Created',
    202:    'Accepted',
    203:    'Non Authoritative Information',
    204:    'No Content',
    205:    'Reset Content',
    206:    'Partial Content',
    207:    'Multi Status',
    226:    'IM Used',              # see RFC 3229
    300:    'Multiple Choices',
    301:    'Moved Permanently',
    302:    'Found',
    303:    'See Other',
    304:    'Not Modified',
    305:    'Use Proxy',
    307:    'Temporary Redirect',
    400:    'Bad Request',
    401:    'Unauthorized',
    402:    'Payment Required',     # unused
    403:    'Forbidden',
    404:    'Not Found',
    405:    'Method Not Allowed',
    406:    'Not Acceptable',
    407:    'Proxy Authentication Required',
    408:    'Request Timeout',
    409:    'Conflict',
    410:    'Gone',
    411:    'Length Required',
    412:    'Precondition Failed',
    413:    'Request Entity Too Large',
    414:    'Request URI Too Long',
    415:    'Unsupported Media Type',
    416:    'Requested Range Not Satisfiable',
    417:    'Expectation Failed',
    418:    'I\'m a teapot',        # see RFC 2324
    422:    'Unprocessable Entity',
    423:    'Locked',
    424:    'Failed Dependency',
    426:    'Upgrade Required',
    428:    'Precondition Required', # see RFC 6585
    429:    'Too Many Requests',
    431:    'Request Header Fields Too Large',
    449:    'Retry With',           # proprietary MS extension
    500:    'Internal Server Error',
    501:    'Not Implemented',
    502:    'Bad Gateway',
    503:    'Service Unavailable',
    504:    'Gateway Timeout',
    505:    'HTTP Version Not Supported',
    507:    'Insufficient Storage',
    510:    'Not Extended'
} def http_date(value):
    if isinstance(value, (date, datetime)):
        value = value.utctimetuple()
    elif isinstance(value, (int, float)):
        value = time.gmtime(value)
    if not isinstance(value, string_types):
        value = time.strftime("%a, %d %b %Y %H:%M:%S GMT", value)
    return value def html_escape(string):
    """ Escape HTML special characters ``&<>`` and quotes ``'"``. """
    return string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')\
                 .replace('"', '&quot;').replace("'", '&#039;') def parse_date(ims):
    """ Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch. """
    try:
        ts = email.utils.parsedate_tz(ims)
        return time.mktime(ts[:8] + (0, )) - (ts[9] or 0) - time.timezone
    except (TypeError, ValueError, IndexError, OverflowError):
        return None def urldecode(qs):
    def __contains__(self, k):
    def __getattr__(self, k):
    def __setattr__(self, k, v):
    def __delattr__(self, k):
    def __init__(self, func):
    def __get__(self, obj, cls=None):
class ConfigDict(dict):
class cached_property(object): PY2 = sys.version_info[0] == 2
    def reraise(tp, value, tb=None):
def to_bytes(s, enc='utf8'):
def to_unicode(s, enc='utf8', err='strict'): class HeaderProperty(object):
    def __init__(self, name, reader=None, writer=str, default=''):
        self.name, self.default = name, default
        self.reader, self.writer = reader, writer
        self.__doc__ = 'Current value of the %r header.' % name.title()

    def __get__(self, obj, _):
        if obj is None: return self
        value = obj.headers.get(self.name, self.default)
        return self.reader(value) if self.reader else value

    def __set__(self, obj, value):
        obj.headers[self.name] = self.writer(value)

    def __delete__(self, obj):
        del obj.headers[self.name] class HeaderDict(MultiDict):
    """ A case-insensitive version of `MultiDict` that defaults to
        replace the old value instead of appending it. """

    def __init__(self, *a, **ka):
        self.dict = {}
        if a or ka: self.update(*a, **ka)

    def __contains__(self, key):
        return _hkey(key) in self.dict

    def __delitem__(self, key):
        del self.dict[_hkey(key)]

    def __getitem__(self, key):
        return self.dict[_hkey(key)][0]

    def __setitem__(self, key, value):
        self.dict[_hkey(key)] = [value if isinstance(value, text_type) else
                                 str(value)]

    def append(self, key, value):
        self.dict.setdefault(_hkey(key), []).append(
            value if isinstance(value, text_type) else str(value))

    def replace(self, key, value):
        self.dict[_hkey(key)] = [value if isinstance(value, text_type) else
                                 str(value)]

    def getall(self, key):
        return self.dict.get(_hkey(key)) or []

    def get(self, key, default=None, index=0):
        return MultiDict.get(self, _hkey(key), default, index) class HTTPException(Exception):
    """
    Baseclass for all HTTP exceptions.  This exception can be called as WSGI
    application to render a default error page or you can catch the subclasses
    of it independently and render nicer error messages.
    """

    code = 555
    description = 'Unknown http exception'

    def __init__(self, description=None):
        Exception.__init__(self)
        if description is not None:
            self.description = description

    @property
    def name(self):
        """The status name."""
        return HTTP_STATUS_CODES.get(self.code, 'Unknown Error')

    def get_description(self):
        """Get the description."""
        return u'%s' % self.description

    def get_body(self):
        """Get the HTML body."""
        return text_type((u'%(description)s') % {
            'description':  self.get_description()
        })

    def get_headers(self):
        """Get a list of headers."""
        return [('Content-Type', 'text/plain')]


    def __str__(self):
        return '%d: %s' % (self.code, self.name)

    def __repr__(self):
        return '<%s \'%s\'>' % (self.__class__.__name__, self) class RequestRedirect(HTTPException):

    """Raise if the map requests a redirect. This is for example the case if
    `strict_slashes` are activated and an url that requires a trailing slash.
    The attribute `new_url` contains the absolute destination url.
    """
    code = 301

    def __init__(self, new_url):
        self.new_url = new_url

    def get_headers(self):
        return [('Location', self.new_url), ('Content-Type', 'text/html')]

    def get_body(self):
        display_location = html_escape(self.new_url)
        body = text_type((
            '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
            '<title>Redirecting...</title>\n'
            '<h1>Redirecting...</h1>\n'
            '<p>You should be redirected automatically to target URL: '
            '<a href="%s">%s</a>.  If not click the link.') % (html_escape(self.new_url), display_location))
        return body
from functools import update_wrapper
from datetime import datetime, timedelta, date
from .http import HTTP_STATUS_CODES, http_date, html_escape, parse_date
from .utils import json
from ._compat import PY2, to_bytes, string_types, text_type, \
     integer_types, to_unicode, to_native, BytesIO, to_bytes
from .datastructures import HeaderProperty, HeaderDict
from .exceptions import HTTPException, RequestRedirect
    from Cookie import SimpleCookie
    from http.cookies import SimpleCookie
import time
        import cocopot
# -*- coding: utf-8 -*-

if PY2:
else:


def make_response(*args):
    rv, status_or_headers, headers = args + (None,) * (3 - len(args))

    if rv is None:
        raise ValueError('View function did not return a response')

    if isinstance(status_or_headers, (dict, list)):
        headers, status_or_headers = status_or_headers, None

    if isinstance(rv, (text_type, bytes, bytearray)):
        rv = Response(rv, headers=headers,
                                 status=status_or_headers)
    elif isinstance(rv, HTTPException):
        rv = Response(to_bytes(rv.get_body()), headers=rv.get_headers(),
                                 status=rv.code)
    else:
        if not isinstance(rv, Response):
            raise ValueError('View function returns must be Response or text, not %s'%(rv))

        if status_or_headers is not None:

            if isinstance(status_or_headers, string_types):